import%20marimo%0A%0A__generated_with%20%3D%20%220.23.13%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20OSM%20Network%20from%20a%20Bounding%20Box%0A%0A%20%20%20%20Use%20a%20bounding%20box%20to%20create%20a%20%60networkx%60%20graph%20from%20OpenStreetMap%20data.%0A%0A%20%20%20%20Network%20data%20%C2%A9%20%5BOpenStreetMap%5D(https%3A%2F%2Fwww.openstreetmap.org%2Fcopyright)%20contributors%2C%20available%20under%20the%20Open%20Database%20Licence.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20from%20cityseer.tools%20import%20io%2C%20plot%0A%20%20%20%20from%20shapely%20import%20geometry%0A%0A%20%20%20%20return%20geometry%2C%20io%2C%20plot%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Use%20a%20shapely%20Polygon%20in%20WGS84%20coordinates%20to%20define%20a%20boundary%20for%20the%20graph.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(geometry)%3A%0A%20%20%20%20poly_wgs%20%3D%20geometry.box(-0.14115725966109327%2C%2051.509220662095714%2C%20-0.12676440185383622%2C%2051.51820111033659)%0A%20%20%20%20poly_wgs%0A%20%20%20%20return%20(poly_wgs%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Use%20the%20%5Bosm_graph_from_poly%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Ftools%2Fio%23osm-graph-from-poly)%20function%20available%20from%20the%20%60cityseer%60%20package's%20%60io%60%20module.%0A%0A%20%20%20%20The%20function%20expects%20a%20%60shapely%60%20polygon%20and%20returns%20a%20%60networkx%60%20graph.%20%60cityseer%60%20will%20automatically%20extract%20the%20graph%20topology%20while%20also%20creating%20accurate%20street%20geometries%20represented%20as%20%60shapely%60%20LineString%20geometries%2C%20which%20are%20linked%20to%20the%20graph's%20edges%20through%20the%20%60geom%60%20edge%20attribute.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(io%2C%20poly_wgs)%3A%0A%20%20%20%20G%20%3D%20io.osm_graph_from_poly(poly_wgs)%0A%20%20%20%20print(G)%0A%20%20%20%20return%20(G%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20%5B%60plot_nx%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Ftools%2Fplot%23plot-nx)%20function%20can%20be%20used%20to%20visualize%20the%20graph.%20It%20accepts%20a%20%60cityseer%60%20prepared%20%60networkx%60%20graph%20and%20will%20plot%20street%20geometries%20when%20the%20%60plot_geoms%60%20parameter%20is%20set%20to%20%60True%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(G%2C%20plot)%3A%0A%20%20%20%20plot.plot_nx(G%2C%20plot_geoms%3DTrue)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20If%20using%20a%20different%20CRS%2C%20then%20specify%20this%20using%20the%20%60poly_crs_code%60%20parameter.%20For%20example%2C%20if%20you%20are%20using%20UTM%20zone%2030N%2C%20then%20set%20this%20to%20the%20corresponding%20EPSG%20code%2C%20in%20this%20case%20%5B32630%5D(https%3A%2F%2Fepsg.io%2F32630).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(geometry%2C%20io%2C%20plot)%3A%0A%20%20%20%20poly_utm%20%3D%20geometry.box(698361%2C%205710348%2C%20699361%2C%205711348)%0A%20%20%20%20G_utm%20%3D%20io.osm_graph_from_poly(poly_utm%2C%20poly_crs_code%3D32630)%0A%20%20%20%20print(G_utm)%0A%20%20%20%20plot.plot_nx(G_utm%2C%20plot_geoms%3DTrue)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%60cityseer%60%20will%20set%20node%20and%20edge%20geometry%20coordinates%20to%20the%20local%20projected%20UTM%20coordinate%20reference%20system.%20If%20you%20want%20to%20create%20the%20resulting%20graph%20in%20a%20specific%20CRS%2C%20then%20specify%20this%20using%20the%20%60to_crs_code%60%20parameter.%20For%20example%2C%20in%20the%20UK%20you%20might%20want%20to%20use%20the%20British%20National%20Grid%2C%20which%20has%20the%20EPSG%20code%20%5B27700%5D(https%3A%2F%2Fepsg.io%2F27700).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(io%2C%20plot%2C%20poly_wgs)%3A%0A%20%20%20%20G_bng%20%3D%20io.osm_graph_from_poly(poly_wgs%2C%20to_crs_code%3D27700)%0A%20%20%20%20print(G_bng)%0A%20%20%20%20plot.plot_nx(G_bng%2C%20plot_geoms%3DTrue)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%60cityseer%60%20will%20automatically%20attempt%20to%20clean-up%20the%20graph%20by%20removing%20unnecessary%20nodes%20and%20simplifying%20the%20graph.%20If%20you%20only%20want%20basic%20cleaning%20without%20simplification%2C%20then%20set%20the%20%60simplify%60%20parameter%20to%20%60False%60.%20Note%20that%20in%20this%20case%20the%20graph%20has%20significantly%20more%20nodes%20and%20edges%20because%20simplification%20has%20not%20been%20applied.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(io%2C%20plot%2C%20poly_wgs)%3A%0A%20%20%20%20G_raw%20%3D%20io.osm_graph_from_poly(poly_wgs%2C%20simplify%3DFalse)%0A%20%20%20%20print(G_raw)%0A%20%20%20%20plot.plot_nx(G_raw%2C%20plot_geoms%3DTrue)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Conclusion%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20This%20notebook%20demonstrated%20how%20to%20create%20a%20%60networkx%60%20street%20network%20graph%20from%20OpenStreetMap%20data%20using%20a%20bounding%20box%20defined%20as%20a%20%60shapely%60%20Polygon.%20It%20covered%20specifying%20custom%20CRS%20codes%20for%20both%20the%20input%20polygon%20and%20the%20output%20graph%2C%20as%20well%20as%20toggling%20automatic%20network%20simplification%20on%20or%20off.%0A%0A%20%20%20%20To%20continue%20into%20analysis%2C%20hand%20the%20prepared%20graph%20to%20the%20high-level%20API%20with%20%5B%60CityNetwork.from_nx%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fapi%2Fnetwork%23from_nx)%2C%20which%20builds%20the%20dual%20network%20and%20exposes%20the%20centrality%20and%20land-use%20methods.%0A%0A%20%20%20%20**Next%20steps%3A**%20To%20create%20a%20network%20from%20a%20buffered%20point%20instead%2C%20see%20%5BBuffered%20Point%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fexamples%2Fnetworks%2Fcreate-from-buffered-point).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
7413855891e47167618f10938506669a