diff --git a/modules/07-urban-networks-i/lecture.ipynb b/modules/07-urban-networks-i/lecture.ipynb index 8672e6b..8108786 100644 --- a/modules/07-urban-networks-i/lecture.ipynb +++ b/modules/07-urban-networks-i/lecture.ipynb @@ -229,8 +229,8 @@ "source": [ "# download/model a street network for some city then visualize it\n", "place = \"Piedmont, California, USA\"\n", - "G = ox.graph_from_place(place, network_type=\"drive\")\n", - "fig, ax = ox.plot_graph(G)" + "G = ox.graph.graph_from_place(place, network_type=\"drive\")\n", + "fig, ax = ox.plot.plot_graph(G)" ] }, { @@ -287,7 +287,7 @@ "outputs": [], "source": [ "# 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.utils_graph.graph_to_gdfs(G)\n", "gdf_nodes.head()" ] }, @@ -314,7 +314,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)\n", + "G2 = ox.utils_graph.graph_from_gdfs(gdf_nodes, gdf_edges, graph_attrs=G.graph)\n", "print(len(G2.nodes))\n", "print(len(G2.edges))" ] @@ -343,8 +343,8 @@ "outputs": [], "source": [ "# get our study site's geometry\n", - "gdf = ox.geocode_to_gdf(place)\n", - "gdf_proj = ox.project_gdf(gdf)\n", + "gdf = ox.geocoder.geocode_to_gdf(place)\n", + "gdf_proj = ox.projection.project_gdf(gdf)\n", "geom_proj = gdf_proj[\"geometry\"].iloc[0]\n", "geom_proj" ] @@ -367,7 +367,7 @@ "outputs": [], "source": [ "# project the graph (automatically) then check its new CRS\n", - "G_proj = ox.project_graph(G)\n", + "G_proj = ox.projection.project_graph(G)\n", "G_proj.graph[\"crs\"]" ] }, @@ -378,7 +378,7 @@ "outputs": [], "source": [ "# show some basic stats about the (projected) network\n", - "ox.basic_stats(G_proj, area=area_m, clean_int_tol=10)" + "ox.stats.basic_stats(G_proj, area=area_m, clean_int_tol=10)" ] }, { @@ -395,8 +395,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\")" ] }, { @@ -427,7 +427,7 @@ "source": [ "# color edges in original graph with 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)" ] }, { @@ -444,8 +444,8 @@ "outputs": [], "source": [ "# impute missing edge speeds then calculate edge (free-flow) travel times\n", - "G = ox.add_edge_speeds(G)\n", - "G = ox.add_edge_travel_times(G)" + "G = ox.speed.add_edge_speeds(G)\n", + "G = ox.speed.add_edge_travel_times(G)" ] }, { @@ -455,8 +455,8 @@ "outputs": [], "source": [ "# get the nearest network nodes to two lat/lng points\n", - "orig = ox.nearest_nodes(G, -122.245846, 37.828903)\n", - "dest = ox.nearest_nodes(G, -122.215006, 37.812303)" + "orig = ox.distance.nearest_nodes(G, -122.245846, 37.828903)\n", + "dest = ox.distance.nearest_nodes(G, -122.215006, 37.812303)" ] }, { @@ -466,8 +466,8 @@ "outputs": [], "source": [ "# find the shortest path between these 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)" ] }, { @@ -477,7 +477,7 @@ "outputs": [], "source": [ "# how long is our route in meters?\n", - "edge_lengths = ox.utils_graph.get_route_edge_attributes(G, route, \"length\")\n", + "edge_lengths = ox.utils_graph.route_to_gdf(G, route)[\"length\"]\n", "sum(edge_lengths)" ] }, @@ -488,7 +488,7 @@ "outputs": [], "source": [ "# how far is it between these two nodes as the crow flies (haversine)?\n", - "ox.distance.great_circle_vec(\n", + "ox.distance.great_circle(\n", " G.nodes[orig][\"y\"], G.nodes[orig][\"x\"], G.nodes[dest][\"y\"], G.nodes[dest][\"x\"]\n", ")" ] @@ -521,8 +521,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)" ] }, { @@ -532,8 +532,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)" ] }, { @@ -546,8 +546,15 @@ "# ...useful when OSM just doesn't already have a polygon for the place you want\n", "lewis_hall = (34.019267, -118.283566)\n", "one_mile = 1609 # meters\n", - "G = ox.graph_from_point(lewis_hall, dist=one_mile, network_type=\"drive\")\n", - "fig, ax = ox.plot_graph(G, node_size=0)" + "G = ox.graph.graph_from_point(lewis_hall, dist=one_mile, network_type=\"drive\")\n", + "fig, ax = ox.plot.plot_graph(G, node_size=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Consider study area boundaries and the artificial perimeter problem." ] }, { @@ -577,7 +584,7 @@ "outputs": [], "source": [ "# get NY subway rail network\n", - "G = ox.graph_from_place(\n", + "G = ox.graph.graph_from_place(\n", " \"New York City, New York, USA\",\n", " retain_all=False,\n", " truncate_by_edge=True,\n", @@ -585,7 +592,7 @@ " custom_filter='[\"railway\"~\"subway\"]',\n", ")\n", "\n", - "fig, ax = ox.plot_graph(G, node_size=0, edge_color=\"c\", edge_linewidth=0.2)" + "fig, ax = ox.plot.plot_graph(G, node_size=0, edge_color=\"c\", edge_linewidth=0.2)" ] }, { @@ -594,7 +601,7 @@ "source": [ "## Get any geospatial entities' geometries and attributes\n", "\n", - "Use the `geometries` module to download entities, such as local amenities, points of interest, or building footprints, and turn them into a GeoDataFrame." + "Use the `features` module to download entities, such as local amenities, points of interest, or building footprints, and turn them into a GeoDataFrame." ] }, { @@ -604,9 +611,9 @@ "outputs": [], "source": [ "# get all building footprints in some neighborhood\n", - "place = \"Civic Center, Los Angeles, California\"\n", + "place = \"Soho, New York, NY, USA\"\n", "tags = {\"building\": True}\n", - "gdf = ox.geometries_from_place(place, tags)\n", + "gdf = ox.features.features_from_place(place, tags)\n", "gdf.shape" ] }, @@ -616,7 +623,7 @@ "metadata": {}, "outputs": [], "source": [ - "fig, ax = ox.plot_footprints(gdf, figsize=(3, 3))" + "fig, ax = ox.plot.plot_footprints(gdf, figsize=(3, 3))" ] }, { @@ -627,7 +634,7 @@ "source": [ "# get all parks and bus stops in some neighborhood\n", "tags = {\"leisure\": \"park\", \"highway\": \"bus_stop\"}\n", - "gdf = ox.geometries_from_place(place, tags)\n", + "gdf = ox.features.features_from_place(place, tags)\n", "gdf.shape" ] }, @@ -640,7 +647,7 @@ "# restaurants near the empire state buildings\n", "address = \"350 5th Ave, New York, NY 10001\"\n", "tags = {\"amenity\": \"restaurant\"}\n", - "gdf = ox.geometries_from_address(address, tags=tags, dist=500)\n", + "gdf = ox.features.features_from_address(address, tags=tags, dist=500)\n", "gdf[[\"name\", \"cuisine\", \"geometry\"]].dropna().head()" ] }, @@ -662,7 +669,7 @@ "source": [ "## In-class workshop\n", "\n", - "Git clone the [OSMnx examples](https://github.com/gboeing/osmnx-examples) repo to your desktop, then work through the notebooks (skip notebook 00, which covers a similar overview as this lecture)." + "Git clone the OSMnx [Examples Gallery](https://github.com/gboeing/osmnx-examples) repository to your desktop, then work through the notebooks (skip notebook 00, which covers a similar overview as this lecture)." ] }, {