Urban Layer¶
This notebook will guide you through creating urban layers—like streets
, intersections
, and cities features
as well as regions
— for urban analysis.
Let’s dive in! 🚀
To get started, we need to import the urban_mapper
module and create an instance of the UrbanMapper
class. This instance, called mapper
, will be our tool for building urban layers throughout the notebook.
import urban_mapper as um
# Fire up UrbanMapper
mapper = um.UrbanMapper()
Mapping Streets and Roads¶
Time to create our first urban layer! We’ll map the streets and roads of Downtown Brooklyn using the urban_layer
module. This layer type, streets_roads
, pulls data from Open Street Map (OSM) via OSMnx, and we’ll specify a driving network. Further could be explored via https://osmnx.readthedocs.io/en/stable/user-reference.html#osmnx.graph.graph_from_place as we wrap that.
Next steps:
- Set the layer type to
streets_roads
. - Define the location as Downtown Brooklyn.
- Render the layer visually with
static_render()
.
Here we go! 🛣️
# Create streets layer
layer = (
mapper
.urban_layer # From the urban_layer module
.with_type("streets_roads") # With the type streets_roads
.from_place("Downtown Brooklyn, New York City, USA", network_type="drive") # From a place
# Note that after the place name we can specify what's called kwargs in Python.
# Which are extra arguments / parameters that could be passed to the just chosen urban layer's type.
# Here we chose the streets roads which are leveraged thanks to OSMNX, hence, network_type is one of their parameters.
# See further in the documentation for the others.
.build()
)
# Render layer
layer.preview()
layer.static_render()
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/osmnx/convert.py:542: FutureWarning: <class 'geopandas.array.GeometryArray'>._reduce will require a `keepdims` parameter in the future dupes = edges[mask].dropna(subset=["geometry"])
Plotting Street Intersections¶
Next up, let’s map the intersections in Downtown Brooklyn. Using the streets_intersections
type, we’ll see where the roads meet—perfect for traffic or urban planning studies!
What’s next:
- Switch the layer type to
streets_intersections
. - Use the same location and network type.
- Render the intersections visually.
Let’s check it out! 🚦
# Create streets layer
layer = (
mapper
.urban_layer # From the urban_layer module
.with_type("streets_intersections") # With the type streets_intersections
.from_place("Downtown Brooklyn, New York City, USA", network_type="drive") # From a place
# Note that after the place name we can specify what's called kwargs in Python.
# Which are extra arguments / parameters that could be passed to the just chosen urban layer's type.
# Here we chose the streets roads which are leveraged thanks to OSMNX, hence, network_type is one of their parameters.
# See further in the documentation for the others.
.build()
)
# Render layer
layer.static_render()
Adding Sidewalks from Tile2Net¶
Now, let’s bring in sidewalks! The streets_sidewalks
type uses a shapefile (from Tile2Net, in this case) instead of a place name. You’ll need to replace the placeholder path with your actual file location.
Follow their readme to have an inference of sidewalks given a location of interest: https://github.com/VIDA-NYU/tile2net
If you believe this to be bothering your workflow, come shout out this issue: https://github.com/VIDA-NYU/UrbanMapper/issues/17
Next up:
- Set the layer type to
streets_sidewalks
. - Load data from a shapefile.
- Render the sidewalks.
Ready to walk the walk? 🚶♂️
# Create streets layer
layer = (
mapper
.urban_layer # From the urban_layer module
.with_type("streets_sidewalks") # With the type streets_sidewalks
.from_file("<path_towards_a_tile_2_net_shp_inference.shp") # Here you need to infer from Tile2Net to get the shapefile path to put here.
.build()
)
# Render layer
layer.static_render()
--------------------------------------------------------------------------- DataSourceError Traceback (most recent call last) Cell In[4], line 7 1 # Create streets layer 2 layer = ( 3 mapper 4 .urban_layer # From the urban_layer module 5 .with_type("streets_sidewalks") # With the type streets_sidewalks 6 .from_file("<path_towards_a_tile_2_net_shp_inference.shp") # Here you need to infer from Tile2Net to get the shapefile path to put here. ----> 7 .build() 8 ) 9 # Render layer 10 layer.static_render() File <@beartype(urban_mapper.modules.urban_layer.urban_layer_factory.UrbanLayerFactory.build) at 0x7dab09647250>:12, in build(__beartype_object_95637653152528, __beartype_get_violation, __beartype_conf, __beartype_check_meta, __beartype_func, *args, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/utils/helpers/require_attributes_not_none.py:35, in require_attributes_not_none.<locals>.decorator.<locals>.wrapper(self, *args, **kwargs) 31 else: 32 raise ValueError( 33 f"Attribute '{name}' is None on {self.__class__.__name__}" 34 ) ---> 35 return func(self, *args, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/utils/helpers/require_attributes_not_none.py:35, in require_attributes_not_none.<locals>.decorator.<locals>.wrapper(self, *args, **kwargs) 31 else: 32 raise ValueError( 33 f"Attribute '{name}' is None on {self.__class__.__name__}" 34 ) ---> 35 return func(self, *args, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layer_factory.py:252, in UrbanLayerFactory.build(self) 248 raise ValueError( 249 f"'{self.loading_method}' is not available for {self.layer_class.__name__}" 250 ) 251 loading_func = getattr(layer, self.loading_method) --> 252 loading_func(*self.loading_args, **self.loading_kwargs) 253 layer.mappings = self.mappings 254 self._instance = layer File <@beartype(urban_mapper.modules.urban_layer.urban_layers.tile2net_sidewalks.Tile2NetSidewalks.from_file) at 0x7dab096440d0>:37, in from_file(__beartype_object_138173813406016, __beartype_get_violation, __beartype_conf, __beartype_args_name_keywordable, __beartype_object_138174842465472, __beartype_check_meta, __beartype_func, *args, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py:69, in Tile2NetSidewalks.from_file(self, file_path, **kwargs) 43 def from_file(self, file_path: str | Path, **kwargs) -> None: 44 """Load sidewalk data from a file produced by `Tile2Net`. 45 46 This method reads a spatial data file containing `Tile2Net` output, filters for `sidewalk (...) 67 >>> sidewalks = Tile2NetSidewalks().from_file("path/to/tile2net_output.geojson") 68 """ ---> 69 self.layer = gpd.read_file(file_path) 70 self.layer = self.layer[self.layer["f_type"] == "sidewalk"] 71 self.layer = self.layer.to_crs(self.coordinate_reference_system) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/geopandas/io/file.py:294, in _read_file(filename, bbox, mask, columns, rows, engine, **kwargs) 291 from_bytes = True 293 if engine == "pyogrio": --> 294 return _read_file_pyogrio( 295 filename, bbox=bbox, mask=mask, columns=columns, rows=rows, **kwargs 296 ) 298 elif engine == "fiona": 299 if pd.api.types.is_file_like(filename): File ~/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/geopandas/io/file.py:547, in _read_file_pyogrio(path_or_bytes, bbox, mask, rows, **kwargs) 538 warnings.warn( 539 "The 'include_fields' and 'ignore_fields' keywords are deprecated, and " 540 "will be removed in a future release. You can use the 'columns' keyword " (...) 543 stacklevel=3, 544 ) 545 kwargs["columns"] = kwargs.pop("include_fields") --> 547 return pyogrio.read_dataframe(path_or_bytes, bbox=bbox, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/pyogrio/geopandas.py:265, in read_dataframe(path_or_buffer, layer, encoding, columns, read_geometry, force_2d, skip_features, max_features, where, bbox, mask, fids, sql, sql_dialect, fid_as_index, use_arrow, on_invalid, arrow_to_pandas_kwargs, **kwargs) 260 if not use_arrow: 261 # For arrow, datetimes are read as is. 262 # For numpy IO, datetimes are read as string values to preserve timezone info 263 # as numpy does not directly support timezones. 264 kwargs["datetime_as_string"] = True --> 265 result = read_func( 266 path_or_buffer, 267 layer=layer, 268 encoding=encoding, 269 columns=columns, 270 read_geometry=read_geometry, 271 force_2d=gdal_force_2d, 272 skip_features=skip_features, 273 max_features=max_features, 274 where=where, 275 bbox=bbox, 276 mask=mask, 277 fids=fids, 278 sql=sql, 279 sql_dialect=sql_dialect, 280 return_fids=fid_as_index, 281 **kwargs, 282 ) 284 if use_arrow: 285 meta, table = result File ~/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/pyogrio/raw.py:198, in read(path_or_buffer, layer, encoding, columns, read_geometry, force_2d, skip_features, max_features, where, bbox, mask, fids, sql, sql_dialect, return_fids, datetime_as_string, **kwargs) 59 """Read OGR data source into numpy arrays. 60 61 IMPORTANT: non-linear geometry types (e.g., MultiSurface) are converted (...) 194 195 """ 196 dataset_kwargs = _preprocess_options_key_value(kwargs) if kwargs else {} --> 198 return ogr_read( 199 get_vsi_path_or_buffer(path_or_buffer), 200 layer=layer, 201 encoding=encoding, 202 columns=columns, 203 read_geometry=read_geometry, 204 force_2d=force_2d, 205 skip_features=skip_features, 206 max_features=max_features or 0, 207 where=where, 208 bbox=bbox, 209 mask=_mask_to_wkb(mask), 210 fids=fids, 211 sql=sql, 212 sql_dialect=sql_dialect, 213 return_fids=return_fids, 214 dataset_kwargs=dataset_kwargs, 215 datetime_as_string=datetime_as_string, 216 ) File pyogrio/_io.pyx:1240, in pyogrio._io.ogr_read() File pyogrio/_io.pyx:220, in pyogrio._io.ogr_open() DataSourceError: <path_towards_a_tile_2_net_shp_inference.shp: No such file or directory
Mapping Crosswalks from Tile2Net¶
Crosswalks are up next! Similar to sidewalks, the streets_crosswalks
type uses a shapefile. Update the path to point to your Tile2Net output, and we’ll visualise pedestrian crossings.
Follow their readme to have an inference of sidewalks given a location of interest: https://github.com/VIDA-NYU/tile2net
What’s happening:
- Use
streets_crosswalks
as the layer type. - Load the shapefile data.
- Display the crosswalks.
Let’s cross over! 🚸
# Create streets layer
layer = (
mapper
.urban_layer # From the urban_layer module
.with_type("streets_crosswalks") # With the type streets_crosswalks
.from_file("<path_towards_a_tile_2_net_shp_inference.shp") # Here you need to infer from Tile2Net to get the shapefile path to put here.
.build()
)
# Render layer
layer.static_render()
--------------------------------------------------------------------------- DataSourceError Traceback (most recent call last) Cell In[5], line 7 1 # Create streets layer 2 layer = ( 3 mapper 4 .urban_layer # From the urban_layer module 5 .with_type("streets_crosswalks") # With the type streets_crosswalks 6 .from_file("<path_towards_a_tile_2_net_shp_inference.shp") # Here you need to infer from Tile2Net to get the shapefile path to put here. ----> 7 .build() 8 ) 9 # Render layer 10 layer.static_render() File <@beartype(urban_mapper.modules.urban_layer.urban_layer_factory.UrbanLayerFactory.build) at 0x7dab09647250>:12, in build(__beartype_object_95637653152528, __beartype_get_violation, __beartype_conf, __beartype_check_meta, __beartype_func, *args, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/utils/helpers/require_attributes_not_none.py:35, in require_attributes_not_none.<locals>.decorator.<locals>.wrapper(self, *args, **kwargs) 31 else: 32 raise ValueError( 33 f"Attribute '{name}' is None on {self.__class__.__name__}" 34 ) ---> 35 return func(self, *args, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/utils/helpers/require_attributes_not_none.py:35, in require_attributes_not_none.<locals>.decorator.<locals>.wrapper(self, *args, **kwargs) 31 else: 32 raise ValueError( 33 f"Attribute '{name}' is None on {self.__class__.__name__}" 34 ) ---> 35 return func(self, *args, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layer_factory.py:252, in UrbanLayerFactory.build(self) 248 raise ValueError( 249 f"'{self.loading_method}' is not available for {self.layer_class.__name__}" 250 ) 251 loading_func = getattr(layer, self.loading_method) --> 252 loading_func(*self.loading_args, **self.loading_kwargs) 253 layer.mappings = self.mappings 254 self._instance = layer File <@beartype(urban_mapper.modules.urban_layer.urban_layers.tile2net_crosswalks.Tile2NetCrosswalks.from_file) at 0x7dab09644dc0>:37, in from_file(__beartype_object_138173813406016, __beartype_get_violation, __beartype_conf, __beartype_args_name_keywordable, __beartype_object_138174842465472, __beartype_check_meta, __beartype_func, *args, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py:70, in Tile2NetCrosswalks.from_file(self, file_path, **kwargs) 44 def from_file(self, file_path: str | Path, **kwargs) -> None: 45 """Load crosswalk data from a file produced by `Tile2Net`. 46 47 This method reads a spatial data file containing `Tile2Net` output, filters for `crosswalk (...) 68 >>> crosswalks = Tile2NetCrosswalks().from_file("path/to/tile2net_output.geojson") 69 """ ---> 70 self.layer = gpd.read_file(file_path) 71 self.layer = self.layer[self.layer["f_type"] == "crosswalk"] 72 self.layer = self.layer.to_crs(self.coordinate_reference_system) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/geopandas/io/file.py:294, in _read_file(filename, bbox, mask, columns, rows, engine, **kwargs) 291 from_bytes = True 293 if engine == "pyogrio": --> 294 return _read_file_pyogrio( 295 filename, bbox=bbox, mask=mask, columns=columns, rows=rows, **kwargs 296 ) 298 elif engine == "fiona": 299 if pd.api.types.is_file_like(filename): File ~/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/geopandas/io/file.py:547, in _read_file_pyogrio(path_or_bytes, bbox, mask, rows, **kwargs) 538 warnings.warn( 539 "The 'include_fields' and 'ignore_fields' keywords are deprecated, and " 540 "will be removed in a future release. You can use the 'columns' keyword " (...) 543 stacklevel=3, 544 ) 545 kwargs["columns"] = kwargs.pop("include_fields") --> 547 return pyogrio.read_dataframe(path_or_bytes, bbox=bbox, **kwargs) File ~/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/pyogrio/geopandas.py:265, in read_dataframe(path_or_buffer, layer, encoding, columns, read_geometry, force_2d, skip_features, max_features, where, bbox, mask, fids, sql, sql_dialect, fid_as_index, use_arrow, on_invalid, arrow_to_pandas_kwargs, **kwargs) 260 if not use_arrow: 261 # For arrow, datetimes are read as is. 262 # For numpy IO, datetimes are read as string values to preserve timezone info 263 # as numpy does not directly support timezones. 264 kwargs["datetime_as_string"] = True --> 265 result = read_func( 266 path_or_buffer, 267 layer=layer, 268 encoding=encoding, 269 columns=columns, 270 read_geometry=read_geometry, 271 force_2d=gdal_force_2d, 272 skip_features=skip_features, 273 max_features=max_features, 274 where=where, 275 bbox=bbox, 276 mask=mask, 277 fids=fids, 278 sql=sql, 279 sql_dialect=sql_dialect, 280 return_fids=fid_as_index, 281 **kwargs, 282 ) 284 if use_arrow: 285 meta, table = result File ~/checkouts/readthedocs.org/user_builds/urbanmapper/envs/80/lib/python3.10/site-packages/pyogrio/raw.py:198, in read(path_or_buffer, layer, encoding, columns, read_geometry, force_2d, skip_features, max_features, where, bbox, mask, fids, sql, sql_dialect, return_fids, datetime_as_string, **kwargs) 59 """Read OGR data source into numpy arrays. 60 61 IMPORTANT: non-linear geometry types (e.g., MultiSurface) are converted (...) 194 195 """ 196 dataset_kwargs = _preprocess_options_key_value(kwargs) if kwargs else {} --> 198 return ogr_read( 199 get_vsi_path_or_buffer(path_or_buffer), 200 layer=layer, 201 encoding=encoding, 202 columns=columns, 203 read_geometry=read_geometry, 204 force_2d=force_2d, 205 skip_features=skip_features, 206 max_features=max_features or 0, 207 where=where, 208 bbox=bbox, 209 mask=_mask_to_wkb(mask), 210 fids=fids, 211 sql=sql, 212 sql_dialect=sql_dialect, 213 return_fids=return_fids, 214 dataset_kwargs=dataset_kwargs, 215 datetime_as_string=datetime_as_string, 216 ) File pyogrio/_io.pyx:1240, in pyogrio._io.ogr_read() File pyogrio/_io.pyx:220, in pyogrio._io.ogr_open() DataSourceError: <path_towards_a_tile_2_net_shp_inference.shp: No such file or directory
Exploring Parks in Brooklyn¶
Let’s switch gears and map some urban features! Using streets_features
, we’ll find all the parks in Brooklyn by setting a leisure
tag. See how tags works here https://osmnx.readthedocs.io/en/stable/user-reference.html#osmnx.features.features_from_place and here for more precision over the tags https://wiki.openstreetmap.org/wiki/Map_features
Next steps:
- Set the layer type to
streets_features
. - Filter for parks in Brooklyn.
- Render the result.
Time to analyse around the park! 🌳
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags={"leisure": "park"} # get the parks.
)
# Note that after the place name we can specify what's called kwargs in Python.
# Which are extra arguments / parameters that could be passed to the just chosen urban layer's type.
# Here we chose the streets roads which are leveraged thanks to OSMNX, hence, network_type is one of their parameters.
# See further in the documentation for the others.
.build()
)
layer.static_render()
Finding Restaurants in Brooklyn¶
Hungry? Let’s map restaurants in Brooklyn with the amenity
tag set to restaurant
. This shows how flexible streets_features
is for urban exploration.
What’s next:
- Keep using
streets_features
. - Filter for restaurants.
- Visualise the dining spots.
Bon appétit! 🍽️
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags={"amenity": "restaurant"} # get the restaurants.
)
.build()
)
layer.static_render()
Locating Schools in Brooklyn¶
Now, let’s find schools! Using the amenity
tag again, we’ll map educational institutions across Brooklyn.
Next up:
- Target schools with
streets_features
. - Render the school locations.
Class is in session! 📚
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags={"amenity": "school"} # get the schools.
)
.build()
)
layer.static_render()
Mapping Hospitals in Brooklyn¶
Health matters! Let’s map hospitals in Brooklyn using the amenity
tag set to hospital
.
What’s happening:
- Use
streets_features
to find hospitals. - Display the results.
Stay healthy! 🏥
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags={"amenity": "hospital"} # get the hospitals.
)
.build()
)
layer.static_render()
Charting Cycleways in Brooklyn¶
For the cyclists out there, let’s map cycleways using the highway
tag. This highlights bike-friendly paths in Brooklyn.
Next steps:
- Set the tag to
cycleway
. - Render the bike lanes.
Pedal on! 🚲
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags={"highway": "cycleway"} # get the cycleways.
)
.build()
)
layer.static_render()
Pinpointing Public Transport Stops¶
Let’s map public transport stops in Brooklyn with the public_transport
tag. Great for transit planning!
What’s next:
- Filter for
stop_position
. - Visualise the stops.
All aboard! 🚌
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags={"public_transport": "stop_position"} # get the public transport stops.
)
.build()
)
layer.static_render()
Highlighting Water Bodies¶
Nature time! Let’s map water bodies in Brooklyn using the natural
tag set to water
.
Next up:
- Target water features.
- Render the map.
Splash! 💧
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags={"natural": "water"} # get the water bodies.
)
.build()
)
layer.static_render()
Combining Parks and Playgrounds¶
Why choose one when you can have both? Let’s map parks and playgrounds in Brooklyn by using a list in the leisure
tag.
What’s happening:
- Use a list to filter multiple features.
- Display the combined result.
Fun for all! 🎠
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags = {"leisure": ["park", "playground"]} # get the parks and playgrounds.
)
.build()
)
layer.static_render()
Savoring French Cuisine¶
Craving something specific? Let’s find French restaurants in Brooklyn with the cuisine
tag.
Next steps:
- Filter for French cuisine.
- Render the tasty spots.
Ooh la la! 🇫🇷
# Create streets layer
layer = (
mapper.urban_layer.with_type("streets_features") # From with the urban_layer module and with the type streets_features
.from_place(
"Brooklyn, New York City, USA",
tags={ "cuisine": "french" } # get the french restaurants.
)
.build()
)
layer.static_render()
___________________________________¶
Mapping Cities¶
We will be switching to what we call as regions
based urban layers from now on. Having a larger zoom at the world map layer.
First, let’s map the cities in Hérault, France. We’re using the region_cities
layer type to fetch city boundaries from OpenStreetMap. The from_place
method targets 'Hérault, France', and we’ll build and render the layer, adding an interactive map with city names in tooltips. Note that the tooltip is not necessary, but open street map returns a lot of noise attributes that are not needed for this very example, feel free to explore that yourself.
layer = (
mapper.urban_layer.with_type("region_cities") # From with the urban_layer module and with the type region_cities
.from_place("Hérault, France") # From a place
.build()
)
layer.static_render()
layer.get_layer().explore(tooltip=["name"])
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:103: UserWarning: Administrative levels vary across regions. The system will infer the most appropriate admin_level based on the data and division type, but you can (and is recommended to) override it with 'overwrite_admin_level'. warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:168: UserWarning: Inferred admin_level for city: 8. Other available levels: ['10', '11', '6', '7', '8', '9']. You can override this with 'overwrite_admin_level' if desired. warnings.warn(
Mapping States¶
In this section, we’re mapping states in Grenada. The region_states
layer type retrieves state or province boundaries. Using from_place
with 'Grenada', we’ll construct and visualise the layer interactively.
layer = (
mapper.urban_layer.with_type("region_states") # From with the urban_layer module and with the type region_states
.from_place("Grenada") # From a place
.build()
)
layer.static_render()
layer.get_layer().explore()
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:103: UserWarning: Administrative levels vary across regions. The system will infer the most appropriate admin_level based on the data and division type, but you can (and is recommended to) override it with 'overwrite_admin_level'. warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:168: UserWarning: Inferred admin_level for state: 6. Other available levels: ['2', '6']. You can override this with 'overwrite_admin_level' if desired. warnings.warn(
Mapping Neighbourhoods¶
Here, we’re mapping neighbourhoods in Paris, France. The region_neighbourhoods
layer type focuses on smaller administrative areas like districts. We’ll use from_place
with 'Paris, France' to build and display the layer, complete with neighbourhood names in an interactive map.
layer = (
mapper.urban_layer.with_type("region_neighborhoods") # From with the urban_layer module and with the type region_neighborhoods
.from_place("Paris, France") # From a place
.build()
)
layer.static_render()
layer.get_layer().explore(tooltip=["name"])
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:103: UserWarning: Administrative levels vary across regions. The system will infer the most appropriate admin_level based on the data and division type, but you can (and is recommended to) override it with 'overwrite_admin_level'. warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:168: UserWarning: Inferred admin_level for neighborhood: 10. Other available levels: ['10', '6', '7', '8', '9']. You can override this with 'overwrite_admin_level' if desired. warnings.warn(
Next, we’re applying the same approach to map neighbourhoods in Montpellier, France. This shows how region_neighbourhoods
can be used across different cities to visualise local administrative boundaries.
layer = (
mapper.urban_layer.with_type("region_neighborhoods") # From with the urban_layer module and with the type region_neighborhoods
.from_place("Montpellier, France") # From a place
.build()
)
layer.static_render()
layer.get_layer().explore(tooltip=["name"])
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:103: UserWarning: Administrative levels vary across regions. The system will infer the most appropriate admin_level based on the data and division type, but you can (and is recommended to) override it with 'overwrite_admin_level'. warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:168: UserWarning: Inferred admin_level for neighborhood: 11. Other available levels: ['10', '11', '8']. You can override this with 'overwrite_admin_level' if desired. warnings.warn(
Now, we’re mapping neighbourhoods in New York City, United States. Due to incomplete data in OpenStreetMap, we’re overriding the default admin level to '7' with overwrite_admin_level
to get accurate boundaries, then displaying them interactively.
layer = (
mapper.urban_layer.with_type("region_neighborhoods") # From with the urban_layer module and with the type region_neighborhoods
.from_place("New York City, United States", overwrite_admin_level="7") # Here we overwrite because the inference do not find a correct enough level due to the lack of information on OSM.
.build()
)
layer.get_layer().reset_index().explore(tooltip=["name"])
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:103: UserWarning: Administrative levels vary across regions. The system will infer the most appropriate admin_level based on the data and division type, but you can (and is recommended to) override it with 'overwrite_admin_level'. warnings.warn(
Let’s switch back to cities and map those in Corsica. Using region_cities
, we’ll retrieve and render city boundaries for this region, adding an interactive map with tooltips.
layer = (
mapper.urban_layer.with_type("region_cities") # From with the urban_layer module and with the type region_cities
.from_place("Corsica") # From a place
.build()
)
layer.static_render()
layer.get_layer().reset_index().explore(tooltip=["name"])
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:103: UserWarning: Administrative levels vary across regions. The system will infer the most appropriate admin_level based on the data and division type, but you can (and is recommended to) override it with 'overwrite_admin_level'. warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/urbanmapper/checkouts/80/src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py:168: UserWarning: Inferred admin_level for city: 8. Other available levels: ['4', '6', '7', '8']. You can override this with 'overwrite_admin_level' if desired. warnings.warn(