winstonyym / urbanity

A network-based python package to understand and model urban complexity
https://urbanity.readthedocs.io/en/latest/
MIT License
134 stars 12 forks source link

enhancement: a more straightforward method to get boundary by using geocode #9

Closed Ultios closed 8 months ago

Ultios commented 8 months ago

As there is no GeoJson of Tanjong Pagar and it takes too long to simulate it for singapore, I think it is more straightforward to get boundary box from osmnx function, geocode_to_gdf.

I adapt the code from add_polygon_boundary function.

for example, m2 is the basemap of singapore.

from osmnx import geocoder
from ipyleaflet import GeoData

#Querying a boundary from geocode
gdf = geocoder.geocode_to_gdf("Tanglin, Singapore")

#Assigning boundary to the basemap
m2.polygon_bounds = gdf
polygon_style = {'style': {'color': 'black', 'fillColor': '#3366cc', 'opacity':0.05, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},
                                         'hover_style': {'fillColor': 'red' , 'fillOpacity': 0.2}}
layer_name = 'Site'
geo_data = GeoData(geo_dataframe = gdf,
                style=polygon_style['style'],
                hover_style=polygon_style['hover_style'],
                name = layer_name)
m2.add_layer(geo_data)

Notes: I use tanglin as opposed to Tanjong Pagar because in OpenStreetMap there are no boundary that represents it, it is mixed with central district and it takes too long to run central district boundary. I used tanglin because Tanglin suburb boundary is defined in the OSM.

It worked fine while using it in basic-functionality notebook.

winstonyym commented 8 months ago

Thank you for exploring. That looks like a nice way to combine functionality with OSMnx. Alternatively, for future reference, you can use this sample boundary that I prepared and hosted on Figshare: https://figshare.com/ndownloader/files/42515773.

winstonyym commented 8 months ago

7 referencing issue and closing this issue since they are similar.