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%20Custom%20Network%20Simplification%0A%0A%20%20%20%20Manually%20configure%20network%20simplification%20steps%20and%20parameters.%0A%0A%20%20%20%20Network%20simplification%20helps%20to%20prevent%20distortions%20in%20centrality%20measures%20and%20can%20also%20be%20preferable%20for%20visualisation.%0A%0A%20%20%20%20While%20cleaning%20and%20simplifying%20the%20network%2C%20%60cityseer%60%20keeps%20track%20of%20intersection%20coordinates%20and%20street%20geometries%20and%20updates%20these%20in%20place%2C%20checking%20that%20the%20street%20alignments%20remain%20as%20accurate%20as%20possible.%20This%20is%20a%20complex%20undertaking%20that%20involves%20finding%20an%20approach%20intended%20to%20work%20for%20most%20situations.%20Manual%20inspection%20and%20cleaning%20is%20recommended%20as%20a%20final%20step%20for%20best%20results.%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%20graphs%2C%20io%2C%20plot%0A%0A%20%20%20%20return%20graphs%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%20The%20test%20area%20is%20taken%20from%20London%20Soho.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(io)%3A%0A%20%20%20%20lng%2C%20lat%20%3D%20-0.13396079424572427%2C%2051.51371088849723%0A%20%20%20%20buffer%20%3D%201200%0A%20%20%20%20poly_wgs%2C%20epsg_code%20%3D%20io.buffered_point_poly(lng%2C%20lat%2C%20buffer)%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%20%23%23%23%20Option%201%20-%20Automatic%20simplification%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%20Simplification%20is%20automatic%20when%20using%20the%20%5B%60osm_graph_from_poly%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Ftools%2Fio%23osm-graph-from-poly)%20function.%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_auto%20%3D%20io.osm_graph_from_poly(%0A%20%20%20%20%20%20%20%20poly_wgs%2C%0A%20%20%20%20%20%20%20%20simplify%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20print(G_auto)%0A%20%20%20%20plot.plot_nx(%0A%20%20%20%20%20%20%20%20G_auto%2C%0A%20%20%20%20%20%20%20%20plot_geoms%3DTrue%2C%0A%20%20%20%20%20%20%20%20figsize%3D(10%2C%2010)%2C%0A%20%20%20%20%20%20%20%20x_lim%3D(698173%2C%20699570)%2C%0A%20%20%20%20%20%20%20%20y_lim%3D(5710085%2C%205711440)%2C%0A%20%20%20%20)%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%23%20Option%202%20-%20Automatic%20simplification%20with%20custom%20parameters%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%20%5B%60osm_graph_from_poly%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Ftools%2Fio%23osm-graph-from-poly)%20accepts%20parameters%20which%20offer%20a%20certain%20amount%20of%20control%20over%20the%20simplification%20process.%20Altering%20the%20distances%20used%20for%20%60final_clean_distances%60%20will%20affect%20how%20aggressive%20the%20final%20round%20of%20network%20simplification%20is.%20The%20default%20is%20%60(4%2C%208)%60.%20So%2C%20for%20example%2C%20adding%20%6025%60%20will%20make%20the%20simplification%20more%20aggressive.%0A%0A%20%20%20%20Footways%20and%20service%20roads%20intersecting%20green%20spaces%20are%20removed%20by%20default.%20This%20can%20be%20changed%20by%20setting%20%60green_footways%60%20and%20%60green_service_roads%60%20to%20%60True%60.%0A%0A%20%20%20%20%60cycleways%60%20is%20set%20to%20%60True%60%20by%20default%20because%20they%20sometimes%20provide%20important%20links%20within%20networks.%0A%0A%20%20%20%20The%20below%20example%20uses%20more%20aggressive%20cleaning%20while%20not%20discarding%20green%20footways.%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_params%20%3D%20io.osm_graph_from_poly(%0A%20%20%20%20%20%20%20%20poly_wgs%2C%0A%20%20%20%20%20%20%20%20simplify%3DTrue%2C%0A%20%20%20%20%20%20%20%20final_clean_distances%3D(4%2C%208%2C%2025)%2C%20%20%23%20adds%2025%20to%20the%20default%20(4%2C%208)%0A%20%20%20%20%20%20%20%20remove_disconnected%3D100%2C%0A%20%20%20%20%20%20%20%20cycleways%3DTrue%2C%0A%20%20%20%20%20%20%20%20busways%3DFalse%2C%0A%20%20%20%20%20%20%20%20green_footways%3DTrue%2C%20%20%23%20keeps%0A%20%20%20%20%20%20%20%20green_service_roads%3DFalse%2C%0A%20%20%20%20)%0A%20%20%20%20print(G_params)%0A%20%20%20%20plot.plot_nx(%0A%20%20%20%20%20%20%20%20G_params%2C%0A%20%20%20%20%20%20%20%20plot_geoms%3DTrue%2C%0A%20%20%20%20%20%20%20%20figsize%3D(10%2C%2010)%2C%0A%20%20%20%20%20%20%20%20x_lim%3D(698173%2C%20699570)%2C%0A%20%20%20%20%20%20%20%20y_lim%3D(5710085%2C%205711440)%2C%0A%20%20%20%20)%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%23%20Option%203%20-%20Custom%20OSM%20requests%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%20You%20may%20want%20more%20control%20over%20the%20data%20request%20that%20is%20sent%20internally%20to%20the%20OSM%20Overpass%20API.%20This%20is%20possible%20by%20providing%20the%20%60custom_request%60%20argument.%20The%20%5BOverpass%20API%5D(https%3A%2F%2Fwiki.openstreetmap.org%2Fwiki%2FOverpass_API%2FOverpass_QL)%20is%20useful%20for%20figuring%20out%20which%20tags%20you%20may%20want%20to%20include%20or%20exclude%20in%20your%20request.%0A%0A%20%20%20%20Note%20that%20the%20custom%20request%20must%20include%20a%20%60%7Bgeom_osm%7D%60%20placeholder%2C%20which%20will%20be%20replaced%20internally%20with%20the%20geometry%20of%20the%20area%20you%20are%20requesting%20data%20for.%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%20req%20%3D%20%22%22%22%0A%20%20%20%20%20%20%20%20%5Bout%3Ajson%5D%3B%0A%20%20%20%20%20%20%20%20(way%5B%22highway%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22highway%22!~%22bus_guideway%7Cbusway%7Cescape%7Craceway%7Cproposed%7Cplanned%7Cabandoned%7Cplatform%7C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20emergency_bay%7Crest_area%7Cdisused%7Ccorridor%7Cladder%7Cbus_stop%7Celevator%7Cservices%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22area%22!%3D%22yes%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22footway%22!%3D%22sidewalk%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22amenity%22!~%22charging_station%7Cparking%7Cfuel%7Cmotorcycle_parking%7Cparking_entrance%7Cparking_space%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22indoor%22!%3D%22yes%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22level%22!%3D%22-2%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22level%22!%3D%22-3%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22level%22!%3D%22-4%22%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%22level%22!%3D%22-5%22%5D(poly%3A%22%7Bgeom_osm%7D%22)%3B%0A%20%20%20%20%20%20%20%20)%3B%0A%20%20%20%20%20%20%20%20out%20body%3B%0A%20%20%20%20%20%20%20%20%3E%3B%0A%20%20%20%20%20%20%20%20out%20qt%3B%0A%20%20%20%20%22%22%22%0A%20%20%20%20G_req%20%3D%20io.osm_graph_from_poly(poly_wgs%2C%20simplify%3DTrue%2C%20custom_request%3Dreq)%0A%20%20%20%20print(G_req)%0A%20%20%20%20plot.plot_nx(%0A%20%20%20%20%20%20%20%20G_req%2C%0A%20%20%20%20%20%20%20%20plot_geoms%3DTrue%2C%0A%20%20%20%20%20%20%20%20figsize%3D(10%2C%2010)%2C%0A%20%20%20%20%20%20%20%20x_lim%3D(698173%2C%20699570)%2C%0A%20%20%20%20%20%20%20%20y_lim%3D(5710085%2C%205711440)%2C%0A%20%20%20%20)%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%23%20Option%204%20-%20Manual%20simplification%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%20If%20you%20need%20full%20control%20over%20the%20simplification%20process%2C%20you%20can%20use%20the%20following%20as%20a%20template%20for%20further%20configuring%20your%20cleaning%20recipe.%20This%20offers%20a%20large%20degree%20of%20control%2C%20but%20the%20precise%20combination%20of%20tags%20and%20distances%20involves%20a%20degree%20of%20experimentation%20and%20some%20inevitable%20trade-offs%20for%20a%20given%20area%20of%20interest.%0A%0A%20%20%20%20For%20this%20approach%2C%20start%20with%20an%20unsimplified%20network%2C%20which%20will%20perform%20only%20rudimentary%20preparation.%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(%0A%20%20%20%20%20%20%20%20G_raw%2C%0A%20%20%20%20%20%20%20%20plot_geoms%3DTrue%2C%0A%20%20%20%20%20%20%20%20figsize%3D(10%2C%2010)%2C%0A%20%20%20%20%20%20%20%20x_lim%3D(698173%2C%20699570)%2C%0A%20%20%20%20%20%20%20%20y_lim%3D(5710085%2C%205711440)%2C%0A%20%20%20%20)%0A%20%20%20%20return%20(G_raw%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%20Then%20manipulate%20the%20network%20depending%20on%20your%20needs.%20See%20the%20%5B%60graphs%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Ftools%2Fgraphs)%20module%20for%20further%20information%20what%20the%20various%20functions%20do.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(G_raw%2C%20graphs)%3A%0A%20%20%20%20%23%20remove%20disconnected%20components%0A%20%20%20%20G%20%3D%20graphs.nx_remove_dangling_nodes(G_raw%2C%20despine%3D0%2C%20remove_disconnected%3D100)%0A%20%20%20%20%23%20initialize%20tag%20cache%20for%20performance%0A%20%20%20%20tag_cache%3A%20dict%20%3D%20%7B%7D%0A%20%20%20%20%23%20clean%20by%20highway%20types%20-%20leave%20motorways%20alone%0A%20%20%20%20%23%20split%20only%20for%20a%20given%20type%20at%20a%20time%0A%20%20%20%20for%20dist%2C%20tags%2C%20max_angle%20in%20(%0A%20%20%20%20%20%20%20%20(40%2C%20%5B%22trunk%22%5D%2C%2030)%2C%0A%20%20%20%20%20%20%20%20(32%2C%20%5B%22primary%22%5D%2C%2035)%2C%0A%20%20%20%20%20%20%20%20(28%2C%20%5B%22secondary%22%5D%2C%2040)%2C%0A%20%20%20%20%20%20%20%20(24%2C%20%5B%22tertiary%22%5D%2C%2045)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20G%20%3D%20graphs.nx_split_opposing_geoms(%0A%20%20%20%20%20%20%20%20%20%20%20%20G%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20buffer_dist%3Ddist%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20squash_nodes%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20centroid_by_itx%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20osm_hwy_target_tags%3Dtags%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20osm_matched_tags_only%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20prioritise_by_hwy_tag%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20simplify_by_max_angle%3Dmax_angle%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20tag_cache%3Dtag_cache%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%23%20consolidate%0A%20%20%20%20for%20dist%2C%20tags%2C%20max_angle%20in%20(%0A%20%20%20%20%20%20%20%20(32%2C%20%5B%22trunk%22%5D%2C%2045)%2C%0A%20%20%20%20%20%20%20%20(28%2C%20%5B%22primary%22%5D%2C%2050)%2C%0A%20%20%20%20%20%20%20%20(24%2C%20%5B%22secondary%22%5D%2C%2055)%2C%0A%20%20%20%20%20%20%20%20(20%2C%20%5B%22tertiary%22%5D%2C%2060)%2C%0A%20%20%20%20)%3A%0A%20%20%20%20%20%20%20%20G%20%3D%20graphs.nx_consolidate_nodes(%0A%20%20%20%20%20%20%20%20%20%20%20%20G%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20buffer_dist%3Ddist%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20crawl%3DFalse%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20centroid_by_itx%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20osm_hwy_target_tags%3Dtags%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20osm_matched_tags_only%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20prioritise_by_hwy_tag%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20simplify_by_max_angle%3Dmax_angle%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20tag_cache%3Dtag_cache%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20G%20%3D%20graphs.nx_remove_filler_nodes(G)%0A%20%20%20%20%23%20snap%20gapped%20endings%20-%20don't%20clean%20danglers%20before%20this%0A%20%20%20%20G%20%3D%20graphs.nx_snap_gapped_endings(%0A%20%20%20%20%20%20%20%20G%2C%0A%20%20%20%20%20%20%20%20osm_hwy_target_tags%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22residential%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22living_street%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22service%22%2C%20%23%20intentionally%20omitted%20-%20e.g.%20parking%20lots%0A%20%20%20%20%20%20%20%20%20%20%20%20%22cycleway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22bridleway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22pedestrian%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22steps%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22footway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22footway_green%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22footway_pedestrian%22%2C%20%20%23%20plazas%0A%20%20%20%20%20%20%20%20%20%20%20%20%22path%22%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20buffer_dist%3D20%2C%0A%20%20%20%20%20%20%20%20tag_cache%3Dtag_cache%2C%0A%20%20%20%20)%0A%20%20%20%20%23%20snap%20gapped%20endings%20to%20roads%20-%20don't%20clean%20danglers%20before%20this%0A%20%20%20%20%23%20look%20for%20degree%201%20dead-ends%20and%20link%20to%20nearby%20edges%0A%20%20%20%20G%20%3D%20graphs.nx_split_opposing_geoms(%0A%20%20%20%20%20%20%20%20G%2C%0A%20%20%20%20%20%20%20%20buffer_dist%3D20%2C%0A%20%20%20%20%20%20%20%20osm_hwy_target_tags%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22trunk%22%2C%20%20%23%20intentionally%20omitted%0A%20%20%20%20%20%20%20%20%20%20%20%20%22primary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22primary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22secondary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22secondary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22tertiary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22tertiary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22residential%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22living_street%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22service%22%2C%20%23%20intentionally%20omitted%20-%20e.g.%20parking%20lots%0A%20%20%20%20%20%20%20%20%20%20%20%20%22cycleway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22bridleway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22pedestrian%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22steps%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22footway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22footway_green%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22footway_pedestrian%22%2C%20%20%23%20plazas%0A%20%20%20%20%20%20%20%20%20%20%20%20%22path%22%2C%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20min_node_degree%3D1%2C%0A%20%20%20%20%20%20%20%20max_node_degree%3D1%2C%0A%20%20%20%20%20%20%20%20squash_nodes%3DFalse%2C%0A%20%20%20%20%20%20%20%20tag_cache%3Dtag_cache%2C%0A%20%20%20%20)%0A%20%20%20%20%23%20remove%20danglers%0A%20%20%20%20G%20%3D%20graphs.nx_remove_dangling_nodes(G%2C%20despine%3D40)%0A%20%20%20%20%23%20do%20smaller%20scale%20cleaning%0A%20%20%20%20max_angle%20%3D%20120%20%20%23%20rue%20de%20nevers%20in%20Paris%0A%20%20%20%20for%20dist%20in%20(4%2C%208)%3A%0A%20%20%20%20%20%20%20%20G%20%3D%20graphs.nx_split_opposing_geoms(%0A%20%20%20%20%20%20%20%20%20%20%20%20G%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20buffer_dist%3Ddist%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20squash_nodes%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20centroid_by_itx%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20osm_hwy_target_tags%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22trunk%22%2C%20%20%23%20intentionally%20omitted%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22primary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22primary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22secondary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22secondary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22tertiary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22tertiary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22residential%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22living_street%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22service%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cycleway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22bridleway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pedestrian%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22steps%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22footway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22footway_pedestrian%22%2C%20%20%23%20plazas%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22path%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22unclassified%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20prioritise_by_hwy_tag%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20simplify_by_max_angle%3Dmax_angle%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20tag_cache%3Dtag_cache%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20G%20%3D%20graphs.nx_consolidate_nodes(%0A%20%20%20%20%20%20%20%20%20%20%20%20G%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20buffer_dist%3Ddist%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20crawl%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20centroid_by_itx%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20osm_hwy_target_tags%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22trunk%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22trunk_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22primary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22primary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22secondary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22secondary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22tertiary%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22tertiary_link%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20%22residential%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22living_street%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22service%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22cycleway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22bridleway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22pedestrian%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22steps%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22footway%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22footway_pedestrian%22%2C%20%20%23%20plazas%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22path%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22unclassified%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20prioritise_by_hwy_tag%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20simplify_by_max_angle%3Dmax_angle%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20tag_cache%3Dtag_cache%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20G%20%3D%20graphs.nx_remove_filler_nodes(G)%0A%20%20%20%20G%20%3D%20graphs.nx_merge_parallel_edges(G%2C%20merge_edges_by_midline%3DTrue%2C%20contains_buffer_dist%3D50)%0A%20%20%20%20G%20%3D%20graphs.nx_iron_edges(G%2C%20min_self_loop_length%3D100%2C%20max_foot_tunnel_length%3D100)%0A%20%20%20%20%23%20do%20this%20last%20to%20clean%20up%20any%20orphaned%20sub%20components%0A%20%20%20%20G%20%3D%20graphs.nx_remove_dangling_nodes(G%2C%20despine%3D25)%0A%20%20%20%20return%20(G%2C)%0A%0A%0A%40app.cell%0Adef%20_(G%2C%20plot)%3A%0A%20%20%20%20plot.plot_nx(%0A%20%20%20%20%20%20%20%20G%2C%0A%20%20%20%20%20%20%20%20plot_geoms%3DTrue%2C%0A%20%20%20%20%20%20%20%20figsize%3D(10%2C%2010)%2C%0A%20%20%20%20%20%20%20%20x_lim%3D(698173%2C%20699570)%2C%0A%20%20%20%20%20%20%20%20y_lim%3D(5710085%2C%205711440)%2C%0A%20%20%20%20)%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%0A%20%20%20%20This%20notebook%20demonstrated%20several%20approaches%20to%20network%20simplification%2C%20ranging%20from%20automatic%20simplification%20via%20%60osm_graph_from_poly%60%20with%20default%20or%20custom%20parameters%2C%20to%20fully%20manual%20control%20using%20individual%20functions%20from%20the%20%60graphs%60%20module.%20Simplification%20helps%20prevent%20distortions%20in%20centrality%20measures%20by%20consolidating%20complex%20intersections%2C%20removing%20danglers%2C%20and%20merging%20parallel%20edges%20while%20preserving%20accurate%20street%20geometries.%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**%20Once%20simplified%2C%20proceed%20to%20compute%20%5BNetwork%20Centrality%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fexamples%2Fcentrality)%20or%20other%20metrics.%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
f231354a9f1131862b2b821a6ca223e1