Skip to content

Commit e8b39a9

Browse files
authored
Merge pull request #123 from gboeing/fix
code clean up
2 parents f2799dc + 02e7ece commit e8b39a9

8 files changed

Lines changed: 16 additions & 14 deletions

notebooks/00-osmnx-features-demo.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"outputs": [],
9191
"source": [
9292
"# get a fully bidirection network (as a MultiDiGraph)\n",
93-
"ox.settings.bidirectional_network_types += \"drive\"\n",
93+
"ox.settings.bidirectional_network_types.append(\"drive\")\n",
9494
"G = ox.graph.graph_from_place(\"Piedmont, California, USA\", network_type=\"drive\")\n",
9595
"\n",
9696
"# convert your MultiDiGraph to an undirected MultiGraph\n",
@@ -229,7 +229,7 @@
229229
"metadata": {},
230230
"outputs": [],
231231
"source": [
232-
"# impute missing edge speeds and calculate edge travel times with the speed module\n",
232+
"# impute missing edge speeds and calculate edge travel times with the routing module\n",
233233
"G = ox.routing.add_edge_speeds(G)\n",
234234
"G = ox.routing.add_edge_travel_times(G)"
235235
]

notebooks/01-overview-osmnx.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
"source": [
330330
"## Part 3: simplifying street network topology\n",
331331
"\n",
332-
"Simplification is normally done by OSMnx automatically under the hood, but we can break it out to see how it works. OpenStreetMap nodes are weird. They include intersections, but they also include all the points along a single block where the street curves. The latter are not nodes in the graph theory sense, so we remove them algorithmically and consolidate the set of edges between \"true\" network nodes into a single edge. There are two simplification modes, strict and non-strict. The main difference is that unlike strict mode, non-strict mode allows simplification to an \"expansion graph\" (ie, if the graph were undirected, nodes with degree 2 as long as the incident edges have different OSM IDs). For a more in-depth demonstration of topological simplification with OSMnx, see [this notebook](04-simplify-graph-consolidate-nodes.ipynb)."
332+
"Simplification is normally done by OSMnx automatically under the hood, but we can break it out to see how it works. OpenStreetMap nodes are weird. They include intersections, but they also include all the points along a single block where the street curves. The latter are not nodes in the graph theory sense, so we remove them algorithmically and consolidate the set of edges between \"true\" network nodes into a single edge. You can additionally retain nodes with specified attributes or where incident edges have different values for specified attributes by using the `node_attrs_include` and `edge_attrs_differ` parameters. For a more in-depth demonstration of topological simplification with OSMnx, see [this notebook](04-simplify-graph-consolidate-nodes.ipynb)."
333333
]
334334
},
335335
{
@@ -354,7 +354,7 @@
354354
"metadata": {},
355355
"outputs": [],
356356
"source": [
357-
"# turn off strict mode and see what nodes we'd remove, in yellow\n",
357+
"# identify endpoint nodes in red and nodes we'd remove in yellow\n",
358358
"nc = [\"r\" if ox.simplification._is_endpoint(G, node, None, None) else \"y\" for node in G.nodes()]\n",
359359
"fig, ax = ox.plot.plot_graph(G, node_color=nc)"
360360
]

notebooks/03-graph-place-queries.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
" - `drive_service` - get drivable streets, including service roads\n",
4848
" - `walk` - get all streets and paths that pedestrians can use (this network type ignores one-way directionality)\n",
4949
" - `bike` - get all streets and paths that cyclists can use\n",
50-
" - `all` - download all non-private OSM streets and paths\n",
51-
" - `all_private` - download all OSM streets and paths, including private-access ones\n",
50+
" - `all` - download all OSM streets and paths, including private-access ones\n",
51+
" - `all_public` - download all non-private OSM streets and paths\n",
5252
"\n",
5353
"Or you can define your own fine-tuned network type using OSMnx's `custom_filter` parameter (to get just highways, or railways, canals, etc).\n",
5454
"\n",

notebooks/04-simplify-graph-consolidate-nodes.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,12 @@
193193
"metadata": {},
194194
"outputs": [],
195195
"source": [
196-
"# turn off strict mode and see what nodes we'd remove\n",
196+
"# identify endpoint nodes in red and nodes we'd remove in yellow\n",
197197
"nc = [\n",
198-
" \"r\" if ox.simplification._is_endpoint(G, node, [\"osmid\"], None) else \"y\" for node in G.nodes()\n",
198+
" \"r\"\n",
199+
" if ox.simplification._is_endpoint(G, node, node_attrs_include=None, edge_attrs_differ=[\"osmid\"])\n",
200+
" else \"y\"\n",
201+
" for node in G.nodes()\n",
199202
"]\n",
200203
"fig, ax = ox.plot.plot_graph(G, node_color=nc)"
201204
]
@@ -206,7 +209,7 @@
206209
"metadata": {},
207210
"outputs": [],
208211
"source": [
209-
"# simplify network with strict mode turned off\n",
212+
"# simplify network while retaining nodes whose incident edges have different `osmid` values\n",
210213
"G3 = ox.simplification.simplify_graph(G.copy(), edge_attrs_differ=[\"osmid\"])\n",
211214
"fig, ax = ox.plot.plot_graph(G3, node_color=\"r\")"
212215
]

notebooks/08-custom-filters-infrastructure.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@
145145
"\n",
146146
"# union: get all ways with either a 'cycleway:right' or 'cycleway:left' tag\n",
147147
"cf = [cf1, cf2]\n",
148-
"ox.settings.useful_tags_way.extend([cf1, cf2])\n",
149148
"G = ox.graph.graph_from_place(place, custom_filter=cf, retain_all=True)\n",
150149
"print(len(G))"
151150
]

notebooks/14-osmnx-to-igraph.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
"outputs": [],
188188
"source": [
189189
"%%time\n",
190-
"closeness2 = nx.closeness_centrality(G_nx, distance=weight, wf_improved=True)\n",
190+
"closeness2 = nx.closeness_centrality(G_nx.to_undirected(), distance=weight, wf_improved=True)\n",
191191
"max_closeness2 = max(closeness2.items(), key=operator.itemgetter(1))[0]"
192192
]
193193
},

notebooks/16-download-osm-geospatial-features.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"cell_type": "markdown",
3737
"metadata": {},
3838
"source": [
39-
"Use the `geometries` module to download features, such as grocery stores, transit stops, points of interest, or building footprints, and turn them into a GeoDataFrame: [see docs](https://osmnx.readthedocs.io/en/stable/osmnx.html#module-osmnx.geometries).\n",
39+
"Use the `features` module to download features, such as grocery stores, transit stops, points of interest, or building footprints, and turn them into a GeoDataFrame: [see docs](https://osmnx.readthedocs.io/en/stable/osmnx.html#module-osmnx.features).\n",
4040
"\n",
4141
"To query, pass a `tags` dict where keys are OSM tags. The dict's values can be either:\n",
4242
" 1. `True` to retrieve all OSM objects with this tag, regardless of its value\n",
@@ -149,7 +149,7 @@
149149
"useful_tags = [\"access\", \"parking\", \"surface\", \"capacity\", \"fee\"]\n",
150150
"for node, feature in zip(nn, features[useful_tags].to_dict(orient=\"records\"), strict=False):\n",
151151
" feature = {k: v for k, v in feature.items() if pd.notna(v)}\n",
152-
" G.nodes[node].update({\"parking\": feature})"
152+
" G.nodes[node].setdefault(\"parking\", []).append(feature)"
153153
]
154154
},
155155
{

notebooks/17-street-network-orientations.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
" print(ox.utils.ts(), place)\n",
9999
"\n",
100100
" # get undirected graphs with edge bearing attributes\n",
101-
" G = ox.graph.graph_from_place(place, network_type=\"drive\")\n",
101+
" G = ox.graph.graph_from_place(places[place], network_type=\"drive\")\n",
102102
" Gu = ox.bearing.add_edge_bearings(ox.convert.to_undirected(G))\n",
103103
" fig, ax = ox.plot.plot_orientation(Gu, ax=ax, title=place, area=True)\n",
104104
"\n",

0 commit comments

Comments
 (0)