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%20Visibility%20from%20GeoPandas%20Data%0A%0A%20%20%20%20Generate%20a%20visibility%20analysis%20from%20GeoPandas%20data%20(or%20a%20file%20opened%20with%20GeoPandas).%0A%0A%20%20%20%20The%20bundled%20datasets%20and%20their%20source%20attributions%20are%20documented%20on%20the%20%5Bdatasets%20page%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fexamples%2Fdatasets).%0A%0A%20%20%20%20Visibility%20analysis%20is%20provided%20by%20the%20standalone%20%60visibility%60%20module%3B%20it%20is%20not%20wrapped%20by%20the%20higher-level%20%60CityNetwork%60%20class.%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%20import%20geopandas%20as%20gpd%0A%20%20%20%20from%20cityseer.metrics%20import%20visibility%0A%0A%20%20%20%20return%20gpd%2C%20visibility%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%20Open%20a%20GeoPandas%20dataset.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(gpd)%3A%0A%20%20%20%20bldgs_gdf%20%3D%20gpd.read_file(%22..%2F..%2Fdata%2Fmadrid_buildings%2Fmadrid_bldgs.gpkg%22)%0A%20%20%20%20bldgs_gdf.head()%0A%20%20%20%20return%20(bldgs_gdf%2C)%0A%0A%0A%40app.cell%0Adef%20_(bldgs_gdf)%3A%0A%20%20%20%20bldgs_gdf.crs%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%20Use%20the%20%5B%60visibility.visibility_from_gpd%60%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fmetrics%2Fvisibility%23visibility_from_gpd)%20method%20to%20run%20a%20visibility%20analysis%20over%20the%20provided%20building%20polygons.%0A%0A%20%20%20%20Pay%20particular%20attention%20to%3A%0A%0A%20%20%20%20-%20The%20%60bounds%60%20parameter%2C%20which%20defines%20the%20geographical%20area%20in%20the%20same%20CRS%20as%20your%20dataset.%20The%20order%20is%20left%2C%20bottom%2C%20right%2C%20top.%0A%20%20%20%20-%20The%20%60out_path%60%20parameter%2C%20which%20specifies%20where%20to%20save%20the%20output%20files.%20The%20directory%20must%20exist.%20Outputs%20are%20written%20in%20GeoTIFF%20format%20(%60.tif%60)%2C%20which%20can%20be%20opened%20in%20QGIS.%0A%20%20%20%20-%20The%20%60from_crs_code%60%20parameter%2C%20which%20specifies%20the%20coordinate%20reference%20system%20(CRS)%20of%20the%20input%20data.%20This%20should%20match%20the%20CRS%20of%20your%20GeoPandas%20dataset%3B%20check%20it%20with%20%60.crs%60%20if%20unsure.%0A%20%20%20%20-%20The%20%60to_crs_code%60%20parameter%2C%20which%20specifies%20the%20CRS%20of%20the%20output.%20The%20default%20is%20the%20local%20UTM%20zone%2C%20but%20any%20valid%20CRS%20code%20can%20be%20used.%0A%20%20%20%20-%20The%20%60view_distance%60%20and%20%60resolution%60%20parameters%2C%20which%20control%20the%20analysis%20granularity.%0A%0A%20%20%20%20There%20is%20a%20performance%20trade-off%20between%20the%20bounds%2C%20view%20distance%2C%20and%20resolution%3A%20a%20larger%20view%20distance%20or%20finer%20resolution%20gives%20more%20detailed%20output%20but%20takes%20longer%20to%20compute%20and%20requires%20more%20memory.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(bldgs_gdf%2C%20visibility)%3A%0A%20%20%20%20visibility.visibility_from_gpd(%0A%20%20%20%20%20%20%20%20bldgs_gdf%2C%0A%20%20%20%20%20%20%20%20bounds%3D(439658%2C%204473632%2C%20440914%2C%204474972)%2C%0A%20%20%20%20%20%20%20%20out_path%3D%22images%2Fmadrid_vis%22%2C%0A%20%20%20%20%20%20%20%20from_crs_code%3D25830%2C%20%20%23%20set%20geopandas%20CRS%0A%20%20%20%20%20%20%20%20to_crs_code%3D25830%2C%20%20%23%20set%20output%20CRS%0A%20%20%20%20%20%20%20%20view_distance%3D150%2C%20%20%23%20can%20use%20a%20larger%20view%20distance%20-%20but%20slower%0A%20%20%20%20%20%20%20%20resolution%3D2%2C%20%20%23%20can%20use%20a%20higher%20resolution%20-%20but%20slower%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%20The%20analysis%20writes%20three%20files%3A%0A%0A%20%20%20%20-%20A%20%60density%60%20measure%3A%20the%20number%20of%20visible%20pixels.%0A%20%20%20%20-%20A%20%60farness%60%20measure%3A%20the%20summed%20distance%20to%20visible%20pixels%2C%20which%20favours%20farther%20views%20(up%20to%20%60view_distance%60).%0A%20%20%20%20-%20A%20%60harmonic%60%20closeness%20measure%3A%20the%20summed%20inverse%20distance%20to%20visible%20pixels%2C%20which%20favours%20close%20adjacency%20to%20open%20spaces.%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%20The%20output%20below%20shows%20%60farness%60%2C%20with%20values%20clipped%20to%20de-accentuate%20rooftops%20while%20recovering%20detail%20at%20ground%20level.%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%3Cimg%20src%3D%22images%2Fmadrid_farness_150_1.png%22%20style%3D%22width%3A100%25%3B%22%3E%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%23%23%20Conclusion%0A%0A%20%20%20%20This%20notebook%20generated%20a%20visibility%20analysis%20from%20a%20GeoPandas%20GeoDataFrame%20of%20building%20footprints%20using%20%60visibility_from_gpd%60.%20Given%20bounds%2C%20CRS%2C%20view%20distance%2C%20and%20resolution%2C%20the%20method%20produces%20density%2C%20farness%2C%20and%20harmonic%20closeness%20rasters%20that%20capture%20the%20spatial%20pattern%20of%20visual%20openness%20and%20enclosure%20across%20the%20study%20area.%0A%0A%20%20%20%20**Next%20steps%3A**%20To%20incorporate%20terrain%20elevation%20data%2C%20see%20%5BVisibility%20from%20Raster%5D(https%3A%2F%2Fcityseer.benchmarkurbanism.com%2Fexamples%2Fvisibility%2Fvis-raster).%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
3f942c4a35ecb452f9fa9cc1a7c88f9f