Skip to content

Commit

Permalink
Merge pull request #97 from gboeing/new
Browse files Browse the repository at this point in the history
Update examples and add new examples
  • Loading branch information
gboeing authored Dec 19, 2024
2 parents 3017217 + ece39a9 commit e6a8efa
Show file tree
Hide file tree
Showing 22 changed files with 676 additions and 273 deletions.
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ repos:
args: [--branch, main]
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
hooks:
- id: prettier
types_or: [markdown, yaml]

- repo: https://github.com/nbQA-dev/nbQA
rev: "1.9.1"
hooks:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-2024 Geoff Boeing https://geoffboeing.com/
Copyright (c) 2016-2025 Geoff Boeing https://geoffboeing.com/

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 0 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ channels:
dependencies:
- jupyterlab
- osmnx=2.0.*
- pillow
- pre-commit
- python=3.11.*
- python-igraph
62 changes: 35 additions & 27 deletions notebooks/00-osmnx-features-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"outputs": [],
"source": [
"# download/model a street network for some city then visualize it\n",
"G = ox.graph_from_place(\"Piedmont, California, USA\", network_type=\"drive\")\n",
"fig, ax = ox.plot_graph(G)"
"G = ox.graph.graph_from_place(\"Piedmont, California, USA\", network_type=\"drive\")\n",
"fig, ax = ox.plot.plot_graph(G)"
]
},
{
Expand All @@ -67,7 +67,9 @@
"OSMnx models all networks as NetworkX `MultiDiGraph` objects. You can convert to:\n",
" - undirected MultiGraphs\n",
" - DiGraphs without (possible) parallel edges\n",
" - GeoPandas node/edge GeoDataFrames"
" - GeoPandas node/edge GeoDataFrames\n",
"\n",
"Note that converting to an undirected MultiGraph is really only meant for use cases where a function or algorithm only accepts a MultiGraph argument. If you just want a fully bidirectional graph (such as for a walking network), just configure the `settings` module’s `bidirectional_network_types` before creating your graph."
]
},
{
Expand All @@ -76,6 +78,10 @@
"metadata": {},
"outputs": [],
"source": [
"# get a fully bidirection network (as a MultiDiGraph)\n",
"ox.settings.bidirectional_network_types += \"drive\"\n",
"G = ox.graph.graph_from_place(\"Piedmont, California, USA\", network_type=\"drive\")\n",
"\n",
"# convert your MultiDiGraph to an undirected MultiGraph\n",
"M = ox.convert.to_undirected(G)\n",
"\n",
Expand All @@ -90,7 +96,7 @@
"outputs": [],
"source": [
"# you can convert your graph to node and edge GeoPandas GeoDataFrames\n",
"gdf_nodes, gdf_edges = ox.graph_to_gdfs(G)\n",
"gdf_nodes, gdf_edges = ox.convert.graph_to_gdfs(G)\n",
"gdf_nodes.head()"
]
},
Expand All @@ -117,7 +123,7 @@
"outputs": [],
"source": [
"# convert node/edge GeoPandas GeoDataFrames to a NetworkX MultiDiGraph\n",
"G2 = ox.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)"
"G2 = ox.convert.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)"
]
},
{
Expand All @@ -134,9 +140,9 @@
"outputs": [],
"source": [
"# what sized area does our network cover in square meters?\n",
"G_proj = ox.project_graph(G)\n",
"nodes_proj = ox.graph_to_gdfs(G_proj, edges=False)\n",
"graph_area_m = nodes_proj.unary_union.convex_hull.area\n",
"G_proj = ox.projection.project_graph(G)\n",
"nodes_proj = ox.convert.graph_to_gdfs(G_proj, edges=False)\n",
"graph_area_m = nodes_proj.union_all().convex_hull.area\n",
"graph_area_m"
]
},
Expand All @@ -147,7 +153,7 @@
"outputs": [],
"source": [
"# show some basic stats about the network\n",
"ox.basic_stats(G_proj, area=graph_area_m, clean_int_tol=15)"
"ox.stats.basic_stats(G_proj, area=graph_area_m, clean_int_tol=15)"
]
},
{
Expand All @@ -164,8 +170,8 @@
"outputs": [],
"source": [
"# save graph to disk as geopackage (for GIS) or graphml file (for gephi etc)\n",
"ox.save_graph_geopackage(G, filepath=\"./data/mynetwork.gpkg\")\n",
"ox.save_graphml(G, filepath=\"./data/mynetwork.graphml\")"
"ox.io.save_graph_geopackage(G, filepath=\"./data/mynetwork.gpkg\")\n",
"ox.io.save_graphml(G, filepath=\"./data/mynetwork.graphml\")"
]
},
{
Expand Down Expand Up @@ -196,7 +202,7 @@
"source": [
"# color edges in original graph with closeness centralities from line graph\n",
"ec = ox.plot.get_edge_colors_by_attr(G, \"edge_centrality\", cmap=\"inferno\")\n",
"fig, ax = ox.plot_graph(G, edge_color=ec, edge_linewidth=2, node_size=0)"
"fig, ax = ox.plot.plot_graph(G, edge_color=ec, edge_linewidth=2, node_size=0)"
]
},
{
Expand Down Expand Up @@ -235,8 +241,8 @@
"outputs": [],
"source": [
"# find the shortest path between nodes, minimizing travel time, then plot it\n",
"route = ox.shortest_path(G, orig, dest, weight=\"travel_time\")\n",
"fig, ax = ox.plot_graph_route(G, route, node_size=0)"
"route = ox.routing.shortest_path(G, orig, dest, weight=\"travel_time\")\n",
"fig, ax = ox.plot.plot_graph_route(G, route, node_size=0)"
]
},
{
Expand Down Expand Up @@ -286,7 +292,9 @@
" G = ox.elevation.add_node_elevations_google(G, api_key=google_elevation_api_key)\n",
" G = ox.elevation.add_edge_grades(G)\n",
" nc = ox.plot.get_node_colors_by_attr(G, \"elevation\", cmap=\"plasma\")\n",
" fig, ax = ox.plot_graph(G, node_color=nc, node_size=20, edge_linewidth=2, edge_color=\"#333\")\n",
" fig, ax = ox.plot.plot_graph(\n",
" G, node_color=nc, node_size=20, edge_linewidth=2, edge_color=\"#333\"\n",
" )\n",
"except ImportError:\n",
" print(\"You need a google_elevation_api_key to run this cell.\")"
]
Expand Down Expand Up @@ -317,8 +325,8 @@
"source": [
"# you can make query an unambiguous dict to help the geocoder find it\n",
"place = {\"city\": \"San Francisco\", \"state\": \"California\", \"country\": \"USA\"}\n",
"G = ox.graph_from_place(place, network_type=\"drive\", truncate_by_edge=True)\n",
"fig, ax = ox.plot_graph(G, figsize=(10, 10), node_size=0, edge_color=\"y\", edge_linewidth=0.2)"
"G = ox.graph.graph_from_place(place, network_type=\"drive\", truncate_by_edge=True)\n",
"fig, ax = ox.plot.plot_graph(G, figsize=(10, 10), node_size=0, edge_color=\"y\", edge_linewidth=0.2)"
]
},
{
Expand All @@ -328,8 +336,8 @@
"outputs": [],
"source": [
"# you can get networks anywhere in the world\n",
"G = ox.graph_from_place(\"Sinalunga, Italy\", network_type=\"all\")\n",
"fig, ax = ox.plot_graph(G, node_size=0, edge_linewidth=0.5)"
"G = ox.graph.graph_from_place(\"Sinalunga, Italy\", network_type=\"all\")\n",
"fig, ax = ox.plot.plot_graph(G, node_size=0, edge_linewidth=0.5)"
]
},
{
Expand All @@ -342,8 +350,8 @@
"# ...useful when OSM just doesn't already have a polygon for the place you want\n",
"wurster_hall = (37.870605, -122.254830)\n",
"one_mile = 1609 # meters\n",
"G = ox.graph_from_point(wurster_hall, dist=one_mile, network_type=\"drive\")\n",
"fig, ax = ox.plot_graph(G, node_size=0)"
"G = ox.graph.graph_from_point(wurster_hall, dist=one_mile, network_type=\"drive\")\n",
"fig, ax = ox.plot.plot_graph(G, node_size=0)"
]
},
{
Expand All @@ -369,15 +377,15 @@
"outputs": [],
"source": [
"# get NY subway rail network\n",
"G = ox.graph_from_place(\n",
"G = ox.graph.graph_from_place(\n",
" \"New York, New York, USA\",\n",
" retain_all=False,\n",
" truncate_by_edge=True,\n",
" simplify=True,\n",
" custom_filter='[\"railway\"~\"subway\"]',\n",
")\n",
"\n",
"fig, ax = ox.plot_graph(G, node_size=0, edge_color=\"w\", edge_linewidth=0.2)"
"fig, ax = ox.plot.plot_graph(G, node_size=0, edge_color=\"w\", edge_linewidth=0.2)"
]
},
{
Expand All @@ -398,7 +406,7 @@
"# get all building footprints in some neighborhood\n",
"place = \"SoHo, New York, NY\"\n",
"tags = {\"building\": True}\n",
"gdf = ox.features_from_place(place, tags)\n",
"gdf = ox.features.features_from_place(place, tags)\n",
"gdf.shape"
]
},
Expand All @@ -408,7 +416,7 @@
"metadata": {},
"outputs": [],
"source": [
"fig, ax = ox.plot_footprints(gdf, figsize=(3, 3))"
"fig, ax = ox.plot.plot_footprints(gdf, figsize=(3, 3))"
]
},
{
Expand All @@ -426,7 +434,7 @@
"source": [
"# get all parks and bus stops in some neighborhood\n",
"tags = {\"leisure\": \"park\", \"highway\": \"bus_stop\"}\n",
"gdf = ox.features_from_place(place, tags)\n",
"gdf = ox.features.features_from_place(place, tags)\n",
"gdf.shape"
]
},
Expand Down Expand Up @@ -454,7 +462,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
"version": "3.12.8"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit e6a8efa

Please sign in to comment.