Urban Layer¶
What is the Urban Layer's module?
The urban_layer
module is responsible for the spatial canvases on which your datasets are displayed. These layers
provide structure for urban insights, such as mapping taxi trips to busy intersections
or analysing neighbourhood
demographics.
Meanwhile, we recommend to look through the Example
's Urban layer for a more hands-on introduction about
the Urban layer module and its usage.
Documentation Under Alpha Construction
This documentation is in its early stages and still being developed. The API may therefore change, and some parts might be incomplete or inaccurate.
Use at your own risk, and please report anything that seems incorrect
/ outdated
you find.
UrbanLayerBase
¶
Bases: ABC
Abstract base class for all urban layers
This abstract class defines the interface that all urban layer implementations
must follow. Urban layers represent spatial layers (dataset as GeoDataframe
) used for geographical
analysis and mapping within UrbanMapper
, such as streets
, regions
, or custom layers.
Attributes:
Name | Type | Description |
---|---|---|
layer |
GeoDataFrame | None
|
The |
mappings |
List[Dict[str, object]]
|
List of mapping configurations for relating this layer to datasets (bridging layer <-> dataset). |
coordinate_reference_system |
str
|
The coordinate reference system used by this layer. Default: EPSG:4326. |
has_mapped |
bool
|
Indicates whether this layer has been mapped to another dataset. |
Examples:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> streets = mapper.urban_layer.osmnx_streets().from_place("London, UK")
>>> # This is an abstract class; use concrete implementations like OSMNXStreets
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
from_place(place_name, **kwargs)
abstractmethod
¶
Load an urban layer from a place name
Creates and populates the layer attribute with spatial data from the specified place.
Method Not Implemented
This method must be implemented by subclasses. It should contain the logic for geocoding the place name and retrieving the corresponding spatial data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
place_name
|
str
|
Name of the place to load (e.g., "New York City", "Paris, France"). |
required |
**kwargs
|
Additional implementation-specific parameters. Common parameters include:
|
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If the place cannot be geocoded or data cannot be retrieved. |
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
from_file(file_path, **kwargs)
abstractmethod
¶
Load an urban layer from a local file.
Creates and populates the layer attribute with spatial data from the specified file.
What is the difference between from_file
and from_place
?
The from_file
method is used to load spatial data from a local file (e.g., shapefile, GeoJSON), if
the urban layer is not available through from_place
, it should be having a fallback to from_file
.
Method Not Implemented
This method must be implemented by subclasses. It should contain the logic for reading the file and loading the corresponding spatial data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the file containing the spatial data. |
required |
**kwargs
|
Additional implementation-specific parameters. |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If the file cannot be read or does not contain valid spatial data. |
FileNotFoundError
|
If the specified file does not exist. |
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
_map_nearest_layer(data, longitude_column, latitude_column, output_column='nearest_element', _reset_layer_index=True, **kwargs)
abstractmethod
¶
Map points to their nearest elements in this urban layer.
Performs spatial joining of points to their nearest elements using either provided column names or predefined mappings.
!!! "How does the mapping / spatial join works?"
The map nearest layer is based on the type of urban layer,
e.g streets roads
will be mapping to the nearest street
, while streets sidewalks
will be mapping to
the nearest sidewalk
. Or in a nutshell, for any new urban layer, the mapping will be based on
the type of urban layer.
Method Not Implemented
This method must be implemented by subclasses. It should contain the logic for performing the spatial join and mapping the points to their nearest elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
GeoDataFrame
|
|
required |
longitude_column
|
str | None
|
Column name for longitude values. |
required |
latitude_column
|
str | None
|
Column name for latitude values. |
required |
output_column
|
str | None
|
Column name for mapping results. |
'nearest_element'
|
threshold_distance
|
float | None
|
Maximum distance for mapping. I.e. if a record is N distance away from urban layer's component, that fits within the threshold distance, it will be mapped to the nearest component, otherwise will be skipped. |
required |
**kwargs
|
Additional parameters for the implementation. |
{}
|
Returns:
Type | Description |
---|---|
Tuple[GeoDataFrame, GeoDataFrame]
|
Tuple[gpd.GeoDataFrame, gpd.GeoDataFrame]: Updated urban layer and mapped data. |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer is not loaded, columns are missing, or mappings are invalid. |
Examples:
>>> mapper = UrbanMapper()
>>> streets = mapper.urban_layer.osmnx_streets().from_place("Edinburgh, UK")
>>> _, mapped = streets.map_nearest_layer(
... data=taxi_trips,
... longitude_column="pickup_lng",
... latitude_column="pickup_lat",
... output_column="nearest_street"
... )
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
map_nearest_layer(data, longitude_column=None, latitude_column=None, output_column=None, threshold_distance=None, **kwargs)
¶
Map points to their nearest elements in this urban layer.
This method is the public method calling internally the _map_nearest_layer
method.
This method performs spatial joining of points to their nearest elements in the urban layer.
It either uses provided column names or processes all mappings defined for this layer.
This means if with_mapping(.)
from the Urban Layer factory
is multiple time called, it'll process the
spatial join (_map_narest_layer(.)
) as many times as the mappings has objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Union[Dict[str, GeoDataFrame], GeoDataFrame]
|
one or more |
required |
longitude_column
|
str | None
|
Name of the column containing longitude values. If provided, overrides any predefined mappings. |
None
|
latitude_column
|
str | None
|
Name of the column containing latitude values. If provided, overrides any predefined mappings. |
None
|
output_column
|
str | None
|
Name of the column to store the mapping results. If provided, overrides any predefined mappings. |
None
|
threshold_distance
|
float | None
|
Maximum distance (in CRS units) to consider for nearest element. Points beyond this distance will not be mapped. |
None
|
**kwargs
|
Additional implementation-specific parameters passed to _map_nearest_layer. |
{}
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
A tuple containing: |
Union[Dict[str, GeoDataFrame], GeoDataFrame]
|
|
Tuple[GeoDataFrame, Union[Dict[str, GeoDataFrame], GeoDataFrame]]
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded, if required columns are missing, if the layer has already been mapped, or if no mappings are defined. |
Examples:
>>> streets = OSMNXStreets()
>>> streets.from_place("Manhattan, New York")
>>> # Using direct column mapping
>>> _, mapped_data = streets.map_nearest_layer(
... data=taxi_trips,
... longitude_column="pickup_longitude",
... latitude_column="pickup_latitude",
... output_column="nearest_street"
... )
>>> # πThis essentially adds a new column `nearest_street` to the datataset `taxi_trips` with the nearest street for each of the data-points it is filled-with.
>>> # Using predefined mappings
>>> streets = OSMNXStreets()
>>> streets.from_place("Manhattan, New York")
>>> streets.mappings = [
... {"longitude_column": "pickup_longitude",
... "latitude_column": "pickup_latitude",
... "output_column": "nearest_pickup_street"}
... ] # Much better with the `.with_mapping()` method from the `Urban Layer factory`.
>>> _, mapped_data = streets.map_nearest_layer(data=taxi_trips)
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
get_layer()
abstractmethod
¶
Get the GeoDataFrame
representing this urban layer.
Method Not Implemented
This method must be implemented by subclasses. It should contain the logic for returning the urban layer data.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
The |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
get_layer_bounding_box()
abstractmethod
¶
Get the bounding box coordinates of this urban layer.
Method Not Implemented
This method must be implemented by subclasses. It should contain the logic for calculating the bounding box.
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float]
|
A tuple containing ( |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
static_render(**plot_kwargs)
abstractmethod
¶
Create a static visualisation of this urban layer.
Method Not Implemented
This method must be implemented by subclasses. It should contain the logic for rendering the urban layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**plot_kwargs
|
Keyword arguments passed to the underlying plotting function. Common parameters include (obviously, this will depend on the implementation):
|
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
preview(format='ascii')
abstractmethod
¶
Generate a preview of this urban layer.
Creates a summary or visual representation of the urban layer for quick inspection.
Method Not Implemented
This method must be implemented by subclasses. It should contain the logic for generating the preview based on the requested format.
Supported Formats include:
- ascii: Text-based table format
- json: JSON-formatted data
- html: one may see the HTML representation if necessary in the long term. Open an Issue!
- dict: Python dictionary representation if necessary in the long term for re-use in the Python workflow. Open an Issue!
- other: Any other formats of interest? Open an Issue!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The output format for the preview. Options include:
|
'ascii'
|
Returns:
Type | Description |
---|---|
Any
|
A representation of the urban layer in the requested format. |
Any
|
Return type varies based on the format parameter. |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
ValueError
|
If an unsupported format is requested. |
Source code in src/urban_mapper/modules/urban_layer/abc_urban_layer.py
OSMNXStreets
¶
Bases: UrbanLayerBase
Urban layer implementation for OpenStreetMap
street networks
.
This class offers a straightforward interface for loading and manipulating
street networks
from OpenStreetMap
using OSMnx
. It adheres to the UrbanLayerBase
interface
, ensuring compatibility with UrbanMapper components such as filters
,
enrichers
, and pipelines
.
When to Use?
Employ this class when you need to integrate street network data into your urban analysis workflows. Itβs particularly handy for:
- Accidents on roads
- Traffic analysis
- Urban planning
- Road-Based Infrastructure development
Attributes:
Name | Type | Description |
---|---|---|
network |
StreetNetwork | None
|
The underlying |
layer |
GeoDataFrame | None
|
The |
Examples:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> # Load streets for a specific place
>>> streets = mapper.urban_layer.streets_roads().from_place("Edinburgh, Scotland")
>>> # Load streets within a bounding box
>>> bbox_streets = mapper.urban_layer.streets_roads().from_bbox(
... (-3.21, 55.94, -3.17, 55.96) # left, bottom, right, top
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
|
from_place(place_name, undirected=True, **kwargs)
¶
Load a street network for a named place.
Retrieves the street network for a specified place name from OpenStreetMap
,
supporting cities
, neighbourhoods
, and other recognised geographic entities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
place_name
|
str
|
Name of the place to load (e.g., "Bristol, England"). |
required |
undirected
|
bool
|
Whether to convert the network to an undirected graph (default: True). |
True
|
**kwargs
|
Additional parameters passed to OSMnx's graph_from_place. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, enabling method chaining. |
Examples:
>>> streets = mapper.urban_layer.streets_roads().from_place("Glasgow, Scotland")
>>> # Load only drivable streets
>>> streets = mapper.urban_layer.streets_roads().from_place(
... "Cardiff, Wales", network_type="drive"
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
from_address(address, undirected=True, **kwargs)
¶
Load a street network around a specified address.
Fetches the street network within a given distance of an address, requiring the distance to be specified in the keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address
|
str
|
The address to centre the network around (e.g., "10 Downing Street, London"). |
required |
undirected
|
bool
|
Whether to convert the network to an undirected graph (default: True). |
True
|
Boots argues that the method retrieves the street network within a certain distance of a specified address. **kwargs: Additional parameters passed to OSMnx's graph_from_address. Must include 'dist' specifying the distance in metres.
Returns:
Type | Description |
---|---|
None
|
Self, enabling method chaining. |
Examples:
>>> streets = mapper.urban_layer.streets_roads().from_address(
... "Buckingham Palace, London", dist=1000
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
from_bbox(bbox, undirected=True, **kwargs)
¶
Load a street network within a bounding box.
Retrieves the street network contained within the specified bounding box coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bbox
|
Tuple[float, float, float, float]
|
Tuple of ( |
required |
undirected
|
bool
|
Whether to convert the network to an undirected graph (default: True). |
True
|
**kwargs
|
Additional parameters passed to OSMnx's graph_from_bbox. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, enabling method chaining. |
Examples:
>>> streets = mapper.urban_layer.streets_roads().from_bbox(
... (-0.13, 51.50, -0.09, 51.52) # Central London
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
from_point(center_point, undirected=True, **kwargs)
¶
Load a street network around a specified point.
Fetches the street network within a certain distance of a geographic point, with the distance specified in the keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center_point
|
Tuple[float, float]
|
Tuple of ( |
required |
undirected
|
bool
|
Whether to convert the network to an undirected graph (default: True). |
True
|
**kwargs
|
Additional parameters passed to OSMnx's graph_from_point. Must include 'dist' specifying the distance in metres. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, enabling method chaining. |
Examples:
>>> streets = mapper.urban_layer.streets_roads().from_point(
... (51.5074, -0.1278), dist=500 # Near Trafalgar Square
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
from_polygon(polygon, undirected=True, **kwargs)
¶
Load a street network within a polygon boundary.
Retrieves the street network contained within the specified polygon boundary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Shapely Polygon or MultiPolygon defining the boundary. |
required |
undirected
|
bool
|
Whether to convert the network to an undirected graph (default: True). |
True
|
**kwargs
|
Additional parameters passed to OSMnx's graph_from_polygon. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, enabling method chaining. |
Examples:
>>> from shapely.geometry import Polygon
>>> boundary = Polygon([(-0.13, 51.50), (-0.09, 51.50), (-0.09, 51.52), (-0.13, 51.52)])
>>> streets = mapper.urban_layer.streets_roads().from_polygon(boundary)
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
from_xml(filepath, undirected=True, **kwargs)
¶
Load a street network from an OSM XML file.
Loads a street network from a local OpenStreetMap XML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str | Path
|
Path to the OSM XML file. |
required |
undirected
|
bool
|
Whether to convert the network to an undirected graph (default: True). |
True
|
**kwargs
|
Additional parameters passed to OSMnx's graph_from_xml. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, enabling method chaining. |
Examples:
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
from_file(file_path, **kwargs)
¶
Load a street network from a file.
Not Implemented
This method is not supported for OSMNXStreets. Use from_xml() for OSM XML files instead.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the file. |
required |
**kwargs
|
Additional parameters (not used). |
{}
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
Always raised, as this method is not supported. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
_map_nearest_layer(data, longitude_column, latitude_column, output_column='nearest_street', threshold_distance=None, _reset_layer_index=True, **kwargs)
¶
Map points to their nearest street edges.
This internal method identifies the nearest street edge for each point in the
input GeoDataFrame
, adding a reference to that edge as a new column. Itβs primarily
used by UrbanLayerBase.map_nearest_layer()
to perform spatial joins between point data and
the street network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
GeoDataFrame
|
|
required |
longitude_column
|
str
|
Name of the column with longitude values. |
required |
latitude_column
|
str
|
Name of the column with latitude values. |
required |
output_column
|
str
|
Name of the column to store nearest street indices (default: "nearest_street"). |
'nearest_street'
|
threshold_distance
|
float | None
|
Maximum distance for a match, in CRS units (default: None). |
None
|
_reset_layer_index
|
bool
|
Whether to reset the layer |
True
|
**kwargs
|
Additional parameters (not used). |
{}
|
Returns:
Type | Description |
---|---|
Tuple[GeoDataFrame, GeoDataFrame]
|
A tuple containing:
- The street network |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
get_layer()
¶
Get the street network as a GeoDataFrame.
Returns the street network edges as a GeoDataFrame for further analysis or visualisation.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
GeoDataFrame containing the street network edges. |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Examples:
>>> streets = mapper.urban_layer.streets_roads().from_place("Birmingham, UK")
>>> streets_gdf = streets.get_layer()
>>> streets_gdf.plot()
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
get_layer_bounding_box()
¶
Get the bounding box of the street network.
Returns the bounding box coordinates of the street network, useful for spatial queries or visualisation extents.
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float]
|
Tuple of ( |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Examples:
>>> streets = mapper.urban_layer.streets_roads().from_place("Leeds, UK")
>>> bbox = streets.get_layer_bounding_box()
>>> print(f"Extent: {bbox}")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
static_render(**plot_kwargs)
¶
Render the street network as a static plot.
Creates a static visualisation of the street network using OSMnx
βs plotting
capabilities, displayed immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**plot_kwargs
|
Additional keyword arguments passed to See further in |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If no network has been loaded yet. |
Examples:
>>> streets = mapper.urban_layer.streets_roads().from_place("Oxford, UK")
>>> streets.static_render(edge_color="grey", node_size=0)
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
preview(format='ascii')
¶
Generate a preview of this urban layer.
Produces a textual or structured representation of the OSMNXStreets
layer for
quick inspection, including metadata like the coordinate reference system and mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
Output format for the preview (default: "ascii").
|
'ascii'
|
Returns:
Type | Description |
---|---|
Any
|
A string (for "ascii") or dictionary (for "json") representing the street network layer. |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported format is requested. |
Examples:
>>> streets = mapper.urban_layer.streets_roads().from_place("Cambridge, UK")
>>> print(streets.preview())
>>> # JSON preview
>>> import json
>>> print(json.dumps(streets.preview(format="json"), indent=2))
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_streets.py
OSMNXIntersections
¶
Bases: UrbanLayerBase
Urban layer
implementation for OpenStreetMap
street intersections
.
This class provides methods for loading street intersection
data from OpenStreetMap
,
and accessing it as urban layers
. Intersections
are
represented as points (nodes in graph) where multiple street segments meet.
The class uses OSMnx
to retrieve street networks
and extract their nodes
, which
represent intersections. It implements the UrbanLayerBase interface
, making it
compatible with other UrbanMapper components
.
When to use?
Street intersections are useful for:
- Network analysis
- Accessibility studies
- Traffic modeling
- Pedestrian safety analysis
- Urban mobility research
Attributes:
Name | Type | Description |
---|---|---|
network |
StreetNetwork | None
|
The underlying |
layer |
GeoDataFrame | None
|
The |
Examples:
>>> from urban_mapper import UrbanMapper
>>>
>>> # Initialise UrbanMapper
>>> mapper = UrbanMapper()
>>>
>>> # Get intersections in Manhattan
>>> intersections = mapper.urban_layer.osmnx_intersections().from_place("Manhattan, New York")
>>>
>>> # Visualise the intersections
>>> intersections.static_render(node_size=5, node_color="red")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
from_place(place_name, undirected=True, **kwargs)
¶
Load street intersections
for a named place.
This method retrieves street network data for a specified place name and extracts the intersections (nodes) from that network. The place name is geocoded to determine the appropriate area to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
place_name
|
str
|
Name of the place to load intersections for (e.g., "Manhattan, New York", "Paris, France"). |
required |
undirected
|
bool
|
Whether to consider the street network as undirected (default: True). When True, one-way streets are treated as bidirectional for the purposes of identifying intersections. |
True
|
**kwargs
|
Additional parameters passed to OSMnx's network retrieval functions. Common parameters include:
More can be explored in OSMnx's documentation at https://osmnx.readthedocs.io/en/stable/. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Examples:
>>> # Get walkable intersections in Brooklyn
>>> intersections = OSMNXIntersections().from_place(
... "Brooklyn, New York",
... network_type="walk"
... )
>>>
>>> # Get all intersections, including isolated ones
>>> all_intersections = OSMNXIntersections().from_place(
... "Boston, MA",
... retain_all=True
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
from_address(address, undirected=True, **kwargs)
¶
Load street intersections
for a specific address.
This method retrieves street network data for a specified address and extracts the intersections (nodes) from that network. The address is geocoded to determine the appropriate area to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address
|
str
|
Address to load intersections for (e.g., "1600 Amphitheatre Parkway, Mountain View, CA"). |
required |
undirected
|
bool
|
Whether to consider the street network as undirected (default: True). When True, one-way streets are treated as bidirectional for the purposes of identifying intersections. |
True
|
**kwargs
|
Additional parameters passed to OSMnx's network retrieval functions. Common parameters include:
More can be explored in OSMnx's documentation at https://osmnx.readthedocs.io/en/stable/. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
from_bbox(bbox, undirected=True, **kwargs)
¶
Load street intersections
for a specified bounding box.
This method retrieves street network data for a specified bounding box and extracts the intersections (nodes) from that network. The bounding box is defined by its southwest and northeast corners.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bbox
|
Tuple[float, float, float, float]
|
Bounding box defined by southwest and northeast corners (e.g., (southwest_latitude, southwest_longitude, northeast_latitude, northeast_longitude)). |
required |
undirected
|
bool
|
Whether to consider the street network as undirected (default: True). When True, one-way streets are treated as bidirectional for the purposes of identifying intersections. |
True
|
**kwargs
|
Additional parameters passed to OSMnx's network retrieval functions. Common parameters include:
More can be explored in OSMnx's documentation at https://osmnx.readthedocs.io/en/stable/. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
from_point(center_point, undirected=True, **kwargs)
¶
Load street intersections
for a specified center point.
This method retrieves street network data for a specified center point and extracts the intersections (nodes) from that network. The center point is used to determine the area to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center_point
|
Tuple[float, float]
|
Center point defined by its latitude and longitude (e.g., (latitude, longitude)). |
required |
undirected
|
bool
|
Whether to consider the street network as undirected (default: True). When True, one-way streets are treated as bidirectional for the purposes of identifying intersections. |
True
|
**kwargs
|
Additional parameters passed to OSMnx's network retrieval functions. Common parameters include:
More can be explored in OSMnx's documentation at https://osmnx.readthedocs.io/en/stable/. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
from_polygon(polygon, undirected=True, **kwargs)
¶
Load street intersections
for a specified polygon.
This method retrieves street network data for a specified polygon and extracts the intersections (nodes) from that network. The polygon is used to determine the area to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Polygon or MultiPolygon defining the area of interest. |
required |
undirected
|
bool
|
Whether to consider the street network as undirected (default: True). When True, one-way streets are treated as bidirectional for the purposes of identifying intersections. |
True
|
**kwargs
|
Additional parameters passed to OSMnx's network retrieval functions. Common parameters include:
More can be explored in OSMnx's documentation at https://osmnx.readthedocs.io/en/stable/. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
from_xml(filepath, undirected=True, **kwargs)
¶
Load street intersections
from a specified XML file.
This method retrieves street network data from a specified XML file and extracts the intersections (nodes) from that network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str | Path
|
Path to the XML file containing street network data. |
required |
undirected
|
bool
|
Whether to consider the street network as undirected (default: True). When True, one-way streets are treated as bidirectional for the purposes of identifying intersections. |
True
|
**kwargs
|
Additional parameters passed to OSMnx's network retrieval functions. Common parameters include:
More can be explored in OSMnx's documentation at https://osmnx.readthedocs.io/en/stable/. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
from_file(file_path, **kwargs)
¶
Load street intersections
from a specified file.
Not implemented
This method is not implemented for OSMNXIntersections
. It raises a
NotImplementedError
if called.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
_map_nearest_layer(data, longitude_column, latitude_column, output_column='nearest_node_idx', threshold_distance=None, _reset_layer_index=True, **kwargs)
¶
Map points to their nearest street intersections
.
This internal method finds the nearest intersection (node) for each point in
the input GeoDataFrame
and adds a reference to that intersection as a new column.
It's primarily used by the UrbanLayerBase.map_nearest_layer()
method to
implement spatial joining between point data and street intersections.
The method uses OSMnx's nearest_nodes
function, which efficiently identifies
the closest node in the street network to each input point. If a threshold
distance is specified, points beyond that distance will not be matched.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
GeoDataFrame
|
|
required |
longitude_column
|
str
|
Name of the column containing longitude values. |
required |
latitude_column
|
str
|
Name of the column containing latitude values. |
required |
output_column
|
str
|
Name of the column to store the indices of nearest nodes. |
'nearest_node_idx'
|
threshold_distance
|
float | None
|
Maximum distance to consider a match, in the CRS units. |
None
|
_reset_layer_index
|
bool
|
Whether to reset the index of the layer |
True
|
**kwargs
|
Additional parameters (not used). |
{}
|
Returns:
Type | Description |
---|---|
Tuple[GeoDataFrame, GeoDataFrame]
|
A tuple containing:
- The intersections |
Notes
Unlike some other spatial joins which use GeoPandas' sjoin_nearest, this method uses OSMnx's optimised nearest_nodes function which is specifically designed for network analysis.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
get_layer()
¶
Get the GeoDataFrame
of the layer.
This method returns the GeoDataFrame
containing the loaded street intersections.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: The |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
get_layer_bounding_box()
¶
Get the bounding box of the layer.
This method returns the bounding box of the loaded street intersections layer.
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float]
|
Tuple[float, float, float, float]: The bounding box of the layer in the
format ( |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
static_render(**plot_kwargs)
¶
Render the street intersections
on a static map.
This method uses OSMnx
to plot the street intersections on a static map.
It can be used to visualise the intersections in the context of the
surrounding street network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**plot_kwargs
|
Additional parameters for the
More can be explored in OSMnx's documentation at https://osmnx.readthedocs.io/en/stable/. |
{}
|
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
preview(format='ascii')
¶
Preview the OSMNXIntersections
layer.
This method provides a summary of the OSMNXIntersections
layer,
including the coordinate reference system and mappings.
It can return the preview in either ASCII or JSON format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The format of the preview. Can be "ascii" or "json".
|
'ascii'
|
Returns:
Type | Description |
---|---|
Any
|
str | dict: The preview of the |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified format is not supported. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osmnx_intersections.py
OSMFeatures
¶
Bases: UrbanLayerBase
Urban layer
implementation for arbitrary OpenStreetMap features
.
This class provides methods for loading various types of OpenStreetMap features
into UrbanMapper
, based on user-specified tags
. It handles the details of
querying OSM data
using different spatial contexts (place names
, addresses
,
bounding boxes
, etc.) and converting the results to GeoDataFrames
.
The class is designed to be both usable directly and subclassed for more
specific feature types. It implements the UrbanLayerBase interface
, making
it compatible with other UrbanMapper
components.
When to use?
OSM Features are useful for:
- Looking to do analysis on specific features in
OpenStreetMap
. - Wanting to load features based on
tags
(e.g.,amenity
,building
, etc.).
Attributes:
Name | Type | Description |
---|---|---|
feature_network |
AdminFeatures | None
|
The underlying |
tags |
Dict[str, str] | None
|
Dictionary of OpenStreetMap |
layer |
GeoDataFrame | None
|
The |
Examples:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>>
>>> # Load all restaurants in Manhattan
>>> restaurants = mapper.urban_layer.osm_features().from_place(
... "Manhattan, New York",
... tags={"amenity": "restaurant"}
... )
>>>
>>> # Load parks within a bounding box
>>> parks = mapper.urban_layer.osm_features().from_bbox(
... (-74.01, 40.70, -73.97, 40.75), # NYC area
... tags={"leisure": "park"}
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
|
from_place(place_name, tags, **kwargs)
¶
Load OpenStreetMap features
for a named place.
This method retrieves OSM features matching the specified tags for a given place name. The place name is geocoded to determine the appropriate area to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
place_name
|
str
|
Name of the place to query (e.g., |
required |
tags
|
Dict[str, str | bool | dict | list]
|
Dictionary of OSM tags to filter features. Examples:
See more in the OSM documentation, here
as well as in the |
required |
**kwargs
|
Additional parameters passed to OSMnx's features_from_place. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Examples:
>>> # Load all hospitals in Chicago
>>> hospitals = OSMFeatures().from_place(
... "Chicago, Illinois",
... tags={"amenity": "hospital"}
... )
>>>
>>> # Load multiple amenity types with a list
>>> poi = OSMFeatures().from_place(
... "Paris, France",
... tags={"tourism": ["hotel", "museum", "attraction"]}
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
from_address(address, tags, dist, **kwargs)
¶
Load OpenStreetMap features
for a specific address.
This method retrieves OSM
features matching the specified tags for a
given address. The address is geocoded to determine the appropriate
area to query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address
|
str
|
Address to query (e.g., |
required |
tags
|
Dict[str, str | bool | dict | list]
|
Dictionary of OSM tags to filter features. Examples:
See more in the OSM documentation, here
as well as in the |
required |
dist
|
float
|
Distance in meters to search around the address. |
required |
**kwargs
|
Additional parameters passed to OSMnx's features_from_address. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Examples:
>>> # Load all restaurants within 500 meters of a specific address
>>> restaurants = OSMFeatures().from_address(
... "1600 Amphitheatre Parkway, Mountain View, CA",
... tags={"amenity": "restaurant"},
... dist=500
... )
>>>
# Load all parks within 1 km of a specific address
>>> parks = OSMFeatures().from_address(
... "Central Park, New York, NY",
... tags={"leisure": "park"},
... dist=1000
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
from_bbox(bbox, tags, **kwargs)
¶
Load OpenStreetMap features
for a specific bounding box.
This method retrieves OSM features matching the specified tags for a given bounding box. The bounding box is defined by its coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bbox
|
Tuple[float, float, float, float]
|
Bounding box coordinates in the format (min_lon, min_lat, max_lon, max_lat). |
required |
tags
|
Dict[str, str | bool | dict | list]
|
Dictionary of OSM tags to filter features. Examples:
See more in the OSM documentation, here
as well as in the |
required |
**kwargs
|
Additional parameters passed to OSMnx's features_from_bbox. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Examples:
>>> # Load all schools within a bounding box in San Francisco
>>> schools = OSMFeatures().from_bbox(
... (-122.45, 37.75, -122.40, 37.80),
... tags={"amenity": "school"}
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
from_point(center_point, tags, dist, **kwargs)
¶
Load OpenStreetMap features
for a specific point.
This method retrieves OSM features matching the specified tags for a given point. The point is defined by its coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
center_point
|
Tuple[float, float]
|
Coordinates of the point in the format (longitude, latitude). |
required |
tags
|
Dict[str, str | bool | dict | list]
|
Dictionary of OSM tags to filter features. Examples:
See more in the OSM documentation, here
as well as in the |
required |
dist
|
float
|
Distance in meters to search around the point. |
required |
**kwargs
|
Additional parameters passed to OSMnx's features_from_point. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Examples:
>>> # Load all restaurants within 500 meters of a specific point
>>> restaurants = OSMFeatures().from_point(
... (37.7749, -122.4194), # San Francisco coordinates
... tags={"amenity": "restaurant"},
... dist=500
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
from_polygon(polygon, tags, **kwargs)
¶
Load OpenStreetMap features
for a specific polygon.
This method retrieves OSM features matching the specified tags for a given polygon. The polygon is defined by its geometry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Shapely Polygon or MultiPolygon object defining the area. |
required |
tags
|
Dict[str, str | bool | dict | list]
|
Dictionary of OSM tags to filter features. Examples:
See more in the OSM documentation, here
as well as in the |
required |
**kwargs
|
Additional parameters passed to OSMnx's features_from_polygon. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Examples:
>>> # Load all parks within a specific polygon
>>> parks = OSMFeatures().from_polygon(
... Polygon([(37.7749, -122.4194), (37.7849, -122.4294), (37.7949, -122.4194)]),
... # πCan get polygon from geocoding an address/place via GeoPY.
... tags={"leisure": "park"}
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
from_file(file_path, **kwargs)
¶
Load OpenStreetMap features
from a file.
Not Implemented
This method is not implemented yet. It raises a NotImplementedError
.
You can use the other loading methods (e.g., from_place
, from_bbox
)
to load OSM features.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
_map_nearest_layer(data, longitude_column, latitude_column, output_column='nearest_feature', threshold_distance=None, _reset_layer_index=True, **kwargs)
¶
Map points to their nearest OSM features
.
This internal method finds the nearest OSM feature for each point in
the input GeoDataFrame
and adds a reference to that feature as a new column.
It's primarily used by the UrbanLayerBase.map_nearest_layer()
method to
implement spatial joining between your dataset point data and OSM features compoents.
The method handles both points with explicit geometry and points defined by longitude/latitude columns. It also automatically converts coordinate systems to ensure accurate distance calculations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
GeoDataFrame
|
|
required |
longitude_column
|
str
|
Name of the column containing longitude values. |
required |
latitude_column
|
str
|
Name of the column containing latitude values. |
required |
output_column
|
str
|
Name of the column to store the indices of nearest features. |
'nearest_feature'
|
threshold_distance
|
float | None
|
Maximum distance to consider a match, in the CRS units. |
None
|
_reset_layer_index
|
bool
|
Whether to reset the index of the layer GeoDataFrame. |
True
|
**kwargs
|
Additional parameters (not used). |
{}
|
Returns:
Type | Description |
---|---|
Tuple[GeoDataFrame, GeoDataFrame]
|
A tuple containing:
|
To Keep in Mind
- The method preferentially uses
OSM IDs
when available, otherwise falls back toDataFrame indices
. - The method converts to a projected
CRS
for accurate distance calculations.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
get_layer()
¶
Get the loaded OSM features
layer.
This method returns the GeoDataFrame
containing the loaded OSM features.
It's primarily used for accessing the layer after loading it using
methods like from_place
, from_bbox
, etc.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
The |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
get_layer_bounding_box()
¶
Get the bounding box of the loaded OSM features
layer.
This method returns the bounding box coordinates of the loaded OSM features
in the format (min_lon
, min_lat
, max_lon
, max_lat
). It's useful for
understanding the spatial extent of the layer.
Returns:
Type | Description |
---|---|
float
|
A tuple containing the bounding box coordinates in the format |
float
|
( |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
static_render(**plot_kwargs)
¶
Render the loaded OSM features
layer.
This method visualises the loaded OSM features using the specified
plotting parameters. It uses the plot()
method of the GeoDataFrame
to create a static plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**plot_kwargs
|
Additional parameters passed to the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
The method does not return anything. It directly displays the plot. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
preview(format='ascii')
¶
Preview the loaded OSM features
layer.
This method provides a summary of the loaded OSM features
, including
the tags
used for filtering, the coordinate reference system
(CRS),
and the mappings
between the input data and the OSM features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
Format of the preview output. Options are "ascii" or "json". - [x] "ascii" - Plain text summary. - [x] "json" - JSON representation of the summary. |
'ascii'
|
Returns:
Type | Description |
---|---|
Any
|
A string or dictionary containing the preview information. |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported format is specified. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/osm_features.py
Tile2NetSidewalks
¶
Bases: UrbanLayerBase
Urban layer implementation for sidewalks extracted with Tile2Net
.
This class provides access to sidewalk data extracted from aerial imagery using the
Tile2Net
deep learning framework. It implements the UrbanLayerBase
interface, ensuring
compatibility with other UrbanMapper
components such as filters, enrichers, and pipelines.
When to Use?
Sidewalk data is particularly useful for:
- Pedestrian accessibility studies
- Walkability analysis
- Urban planning and design
- Mobility assessment for people with disabilities
Attributes:
Name | Type | Description |
---|---|---|
layer |
GeoDataFrame
|
The GeoDataFrame containing sidewalk geometries (set after loading). |
Examples:
Load and visualise sidewalk data:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> sidewalks = mapper.urban_layer.tile2net_sidewalks().from_file("path/to/sidewalks.geojson")
>>> sidewalks.static_render(figsize=(10, 8), colour="blue")
Data Source
Sidewalk data must be pre-extracted using Tile2Net
and loaded from files. Direct
loading from place names or other spatial queries is not supported.
See further here: Tile2Net VIDA NYU && This Feature Request
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
from_file(file_path, **kwargs)
¶
Load sidewalk data from a file produced by Tile2Net
.
This method reads a spatial data file containing Tile2Net
output, filters for sidewalk
features
, and prepares them for use within the UrbanMapper's workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the file containing |
required |
**kwargs
|
Additional parameters passed to |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, enabling method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If the file contains a |
FileNotFoundError
|
If the specified file does not exist. |
Examples:
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py
from_place(place_name, **kwargs)
¶
Load sidewalk data for a specific place.
Not Implemented
This method is not yet implemented. Currently, sidewalk data can only be loaded
from files produced by Tile2Net
. Future versions may support loading from
geographic place names or other spatial queries.
See further in this feature request
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py
_map_nearest_layer(data, longitude_column, latitude_column, output_column='nearest_sidewalk', threshold_distance=None, _reset_layer_index=True, **kwargs)
¶
Map points to their nearest sidewalk segments.
This internal method identifies the nearest sidewalk segment for each point in the input
GeoDataFrame
and adds a reference to that segment as a new column. Itβs primarily
used by UrbanLayerBase.map_nearest_layer()
to perform spatial joins between point
data and sidewalks.
The method utilises GeoPandasβ spatial join with nearest match to find the closest sidewalk segment for each point. If a threshold distance is specified, points beyond that distance will not be matched.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
GeoDataFrame
|
GeoDataFrame containing point data to map. |
required |
longitude_column
|
str
|
Name of the column containing longitude values. |
required |
latitude_column
|
str
|
Name of the column containing latitude values. |
required |
output_column
|
str
|
Name of the column to store the indices of nearest sidewalks (default: "nearest_sidewalk"). |
'nearest_sidewalk'
|
threshold_distance
|
float | None
|
Maximum distance to consider a match, in CRS units (default: None). |
None
|
_reset_layer_index
|
bool
|
Whether to reset the index of the layer GeoDataFrame (default: True). |
True
|
**kwargs
|
Additional parameters (not used). |
{}
|
Returns:
Type | Description |
---|---|
Tuple[GeoDataFrame, GeoDataFrame]
|
Tuple[GeoDataFrame, GeoDataFrame]: A tuple containing: - The sidewalk network GeoDataFrame (possibly with reset index) - The input GeoDataFrame with the new output_column added (filtered if threshold_distance was specified) |
Coordinate Reference System
The method automatically converts the input data to a projected CRS if itβs not already projected, ensuring accurate distance calculations.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
get_layer()
¶
Get the sidewalk network as a GeoDataFrame.
Returns the sidewalk network as a GeoDataFrame for further analysis or visualisation.
Returns:
Name | Type | Description |
---|---|---|
GeoDataFrame |
GeoDataFrame
|
GeoDataFrame containing the sidewalk segments. |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Examples:
>>> sidewalks = Tile2NetSidewalks().from_file("path/to/sidewalks.geojson")
>>> sidewalks_gdf = sidewalks.get_layer()
>>> print(f"Loaded {len(sidewalks_gdf)} sidewalk segments")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py
get_layer_bounding_box()
¶
Get the bounding box of the sidewalk network.
Returns the bounding box coordinates of the sidewalk network, useful for spatial queries or visualisation extents.
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float]
|
Tuple[float, float, float, float]: Tuple of (left, bottom, right, top) coordinates defining the bounding box. |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Examples:
>>> sidewalks = Tile2NetSidewalks().from_file("path/to/sidewalks.geojson")
>>> bbox = sidewalks.get_layer_bounding_box()
>>> print(f"Sidewalks extent: {bbox}")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py
static_render(**plot_kwargs)
¶
Render the sidewalk network as a static plot.
Creates a static visualisation of the sidewalk network using GeoPandasβ plotting functionality, displayed immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**plot_kwargs
|
Additional keyword arguments passed to |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If no layer has been loaded yet. |
Examples:
>>> sidewalks = Tile2NetSidewalks().from_file("path/to/sidewalks.geojson")
>>> sidewalks.static_render(figsize=(10, 8), colour="green", linewidth=0.8)
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py
preview(format='ascii')
¶
Generate a preview of this urban layer.
Produces a textual or structured representation of the Tile2NetSidewalks
layer for
quick inspection, including metadata like the coordinate reference system and mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
Output format for the preview (default: "ascii").
|
'ascii'
|
Returns:
Type | Description |
---|---|
Any
|
str | dict: A string (for "ascii") or dictionary (for "json") representing the sidewalk network layer. |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported format is requested. |
Examples:
>>> sidewalks = Tile2NetSidewalks().from_file("path/to/sidewalks.geojson")
>>> print(sidewalks.preview())
>>> # JSON preview
>>> import json
>>> print(json.dumps(sidewalks.preview(format="json"), indent=2))
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_sidewalks.py
Tile2NetCrosswalks
¶
Bases: UrbanLayerBase
Urban layer implementation for crosswalks extracted with Tile2Net
.
This class provides access to crosswalk data extracted from aerial imagery using the
Tile2Net
deep learning framework. It implements the UrbanLayerBase
interface, ensuring
compatibility with other UrbanMapper
components such as filters, enrichers, and pipelines.
When to Use?
Crosswalk data is particularly useful for:
- Pedestrian safety analysis
- Intersection safety studies
- Accessibility assessment
- Walkability index calculations
- Complete streets planning
Attributes:
Name | Type | Description |
---|---|---|
layer |
GeoDataFrame
|
The GeoDataFrame containing crosswalk geometries (set after loading). |
Examples:
Load and visualise crosswalk data:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> crosswalks = mapper.urban_layer.tile2net_crosswalks().from_file("path/to/crosswalks.geojson")
>>> crosswalks.static_render(figsize=(10, 8), colour="red")
Data Source
Crosswalk data must be pre-extracted using Tile2Net
and loaded from files. Direct
loading from place names or other spatial queries is not supported.
See further here: Tile2Net VIDA NYU && This Feature Request
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
from_file(file_path, **kwargs)
¶
Load crosswalk data from a file produced by Tile2Net
.
This method reads a spatial data file containing Tile2Net
output, filters for crosswalk
features
, and prepares them for use within the UrbanMapper's workflow
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the file containing |
required |
**kwargs
|
Additional parameters passed to |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, enabling method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If the file contains a |
FileNotFoundError
|
If the specified file does not exist. |
Examples:
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py
from_place(place_name, **kwargs)
¶
Load crosswalk data for a specific place.
Not Implemented
This method is not yet implemented. Currently, crosswalk data can only be loaded
from files produced by Tile2Net
. Future versions may support loading from
geographic place names or other spatial queries.
See further in this feature request
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py
_map_nearest_layer(data, longitude_column, latitude_column, output_column='nearest_crosswalk', threshold_distance=None, _reset_layer_index=True, **kwargs)
¶
Map points to their nearest crosswalk features.
This internal method identifies the nearest crosswalk for each point in the input
GeoDataFrame
and adds a reference to that crosswalk as a new column. Itβs primarily
used by UrbanLayerBase.map_nearest_layer()
to perform spatial joins between point
data and crosswalks.
The method utilises GeoPandasβ spatial join with nearest match to find the closest crosswalk for each point. If a threshold distance is specified, points beyond that distance will not be matched.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
GeoDataFrame
|
GeoDataFrame containing point data to map. |
required |
longitude_column
|
str
|
Name of the column containing longitude values. |
required |
latitude_column
|
str
|
Name of the column containing latitude values. |
required |
output_column
|
str
|
Name of the column to store the indices of nearest crosswalks (default: "nearest_crosswalk"). |
'nearest_crosswalk'
|
threshold_distance
|
float | None
|
Maximum distance to consider a match, in CRS units (default: None). |
None
|
_reset_layer_index
|
bool
|
Whether to reset the index of the layer GeoDataFrame (default: True). |
True
|
**kwargs
|
Additional parameters (not used). |
{}
|
Returns:
Type | Description |
---|---|
Tuple[GeoDataFrame, GeoDataFrame]
|
Tuple[GeoDataFrame, GeoDataFrame]: A tuple containing: - The crosswalk network GeoDataFrame (possibly with reset index) - The input GeoDataFrame with the new output_column added (filtered if threshold_distance was specified) |
Coordinate Reference System
The method automatically converts the input data to a projected CRS if itβs not already projected, ensuring accurate distance calculations.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py
get_layer()
¶
Get the crosswalk network as a GeoDataFrame.
Returns the crosswalk network as a GeoDataFrame for further analysis or visualisation.
Returns:
Name | Type | Description |
---|---|---|
GeoDataFrame |
GeoDataFrame
|
GeoDataFrame containing the crosswalk segments. |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Examples:
>>> crosswalks = Tile2NetCrosswalks().from_file("path/to/crosswalks.geojson")
>>> crosswalks_gdf = crosswalks.get_layer()
>>> print(f"Loaded {len(crosswalks_gdf)} crosswalk segments")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py
get_layer_bounding_box()
¶
Get the bounding box of the crosswalk network.
Returns the bounding box coordinates of the crosswalk network, useful for spatial queries or visualisation extents.
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float]
|
Tuple[float, float, float, float]: Tuple of (left, bottom, right, top) coordinates defining the bounding box. |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Examples:
>>> crosswalks = Tile2NetCrosswalks().from_file("path/to/crosswalks.geojson")
>>> bbox = crosswalks.get_layer_bounding_box()
>>> print(f"Crosswalks extent: {bbox}")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py
static_render(**plot_kwargs)
¶
Render the crosswalk network as a static plot.
Creates a static visualisation of the crosswalk network using GeoPandasβ plotting functionality, displayed immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**plot_kwargs
|
Additional keyword arguments passed to |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If no layer has been loaded yet. |
Examples:
>>> crosswalks = Tile2NetCrosswalks().from_file("path/to/crosswalks.geojson")
>>> crosswalks.static_render(figsize=(10, 8), colour="yellow", linewidth=1.5)
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py
preview(format='ascii')
¶
Generate a preview of this urban layer.
Produces a textual or structured representation of the Tile2NetCrosswalks
layer for
quick inspection, including metadata like the coordinate reference system and mappings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
Output format for the preview (default: "ascii"). - "ascii": Text-based format for terminal display - "json": JSON-formatted data for programmatic use |
'ascii'
|
Returns:
Type | Description |
---|---|
Any
|
str | dict: A string (for "ascii") or dictionary (for "json") representing the crosswalk network layer. |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported format is requested. |
Examples:
>>> crosswalks = Tile2NetCrosswalks().from_file("path/to/crosswalks.geojson")
>>> print(crosswalks.preview())
>>> # JSON preview
>>> import json
>>> print(json.dumps(crosswalks.preview(format="json"), indent=2))
Source code in src/urban_mapper/modules/urban_layer/urban_layers/tile2net_crosswalks.py
RegionNeighborhoods
¶
Bases: AdminRegions
Urban layer implementation for neighbourhood-level administrative regions.
This class provides methods for loading neighbourhood boundaries from OpenStreetMap.
It extends the AdminRegions
base class, specifically targeting neighbourhood-level
administrative divisions. The class automatically attempts to identify the appropriate
administrative level for neighbourhoods in different regions, with an option for manual override.
Neighbourhoods are small, local administrative or cultural divisions typically found within
cities. They often correspond to OpenStreetMapβs admin_level
10, though this can vary by country.
The class employs heuristics to determine the correct level based on the size and number of divisions
within a specified area.
When to Use?
Use this class when you need neighbourhood-level administrative boundaries for tasks such as urban planning, local governance studies, or providing geographic context for neighbourhood-specific datasets.
Attributes:
Name | Type | Description |
---|---|---|
division_type |
str
|
Set to "neighborhood" to instruct the parent class to look for neighbourhood-level administrative boundaries. |
layer |
GeoDataFrame
|
The GeoDataFrame containing the neighbourhood boundaries (set after loading). |
Examples:
Load and visualise neighbourhood boundaries for a city:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> neighborhoods = mapper.urban_layer.region_neighborhoods().from_place("Brooklyn, NY")
>>> neighborhoods.static_render(
... figsize=(10, 8),
... edgecolor="black",
... alpha=0.7,
... column="name" # Colour by neighbourhood name if available
... )
Specify a custom administrative level:
>>> neighborhoods = mapper.urban_layer.region_neighborhoods().from_place(
... "Paris, France",
... overwrite_admin_level="9" # Use level 9 in Paris instead of the inferred level
... )
Administrative Level Inference
This class uses heuristics to infer the correct administrative level for neighbourhoods.
However, as administrative levels vary globally, accuracy is not guaranteed. Use the
overwrite_admin_level
parameter in loading methods to manually specify the level if necessary.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/region_neighborhoods.py
RegionCities
¶
Bases: AdminRegions
Urban layer implementation for city-level administrative regions.
This class facilitates the loading of city and municipal boundaries from OpenStreetMap,
extending the AdminRegions
base class to target city-level administrative divisions.
It employs heuristics to automatically determine the appropriate administrative level
for cities across different regions, with an option for manual override.
Cities and municipalities represent medium-sized administrative units, typically under
local government jurisdiction. While they often correspond to OpenStreetMapβs
admin_level
8, variations across countries are common. This class adapts to such
differences by analysing the size and number of divisions within a specified area.
When to Use?
Employ this class when you need city-level administrative boundaries for tasks like urban analysis, municipal planning, population studies, or providing geographic context for city-specific datasets.
Attributes:
Name | Type | Description |
---|---|---|
division_type |
str
|
Fixed to "city", directing the parent class to target city-level administrative boundaries. |
layer |
GeoDataFrame
|
Holds the city boundaries as a |
Examples:
Load and visualise city boundaries for a region:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> cities = mapper.urban_layer.region_cities().from_place("Greater Manchester, England")
>>> cities.static_render(
... figsize=(12, 10),
... edgecolor="black",
... alpha=0.5,
... column="name" # Colour by city name if available
... )
Specify a custom administrative level:
>>> cities = mapper.urban_layer.region_cities().from_place(
... "Bavaria, Germany",
... overwrite_admin_level="6" # Override inferred level with 6
... )
Administrative Level Inference
This class attempts to infer the correct administrative level for cities using
heuristics. However, as levels differ globally, accuracy isnβt guaranteed. Use the
overwrite_admin_level
parameter in loading methods to manually set the level if
needed.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/region_cities.py
RegionStates
¶
Bases: AdminRegions
Urban layer implementation for state and province-level administrative regions.
This class provides methods for loading state and province boundaries from OpenStreetMap.
It extends the AdminRegions
base class, specifically targeting state-level administrative
divisions. The class automatically attempts to identify the appropriate administrative
level for states or provinces in different regions, with an option for manual override.
States and provinces are mid-level administrative units, typically found within countries.
They often correspond to OpenStreetMapβs admin_level
4, though this can vary by country.
The class employs heuristics to determine the correct level based on the size and number
of divisions within a specified area.
When to Use?
Use this class when you need state or province-level administrative boundaries for tasks such as regional analysis, governance studies, or providing geographic context for state-specific datasets.
Attributes:
Name | Type | Description |
---|---|---|
division_type |
str
|
Set to "state" to instruct the parent class to look for state-level administrative boundaries. |
layer |
GeoDataFrame
|
The GeoDataFrame containing the state boundaries (set after loading). |
Examples:
Load and visualise state boundaries for a country:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> states = mapper.urban_layer.region_states().from_place("United States")
>>> states.static_render(
... figsize=(12, 8),
... edgecolor="black",
... alpha=0.5,
... column="name" # Colour by state name
... )
Specify a custom administrative level:
>>> states = mapper.urban_layer.region_states().from_place(
... "Canada",
... overwrite_admin_level="4" # Explicitly use level 4 for Canadian provinces
... )
Administrative Level Inference
This class uses heuristics to infer the correct administrative level for states.
However, as administrative levels vary globally, accuracy is not guaranteed. Use the
overwrite_admin_level
parameter in loading methods to manually specify the level
if necessary.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/region_states.py
RegionCountries
¶
Bases: AdminRegions
Urban layer implementation for country-level administrative regions.
This class provides methods for loading country boundaries from OpenStreetMap.
It extends the AdminRegions
base class, specifically targeting country-level
administrative divisions. The class automatically attempts to identify the appropriate
administrative level for countries in different contexts, with an option for manual override.
Countries represent the highest level of administrative divisions in most global datasets.
They typically correspond to OpenStreetMapβs admin_level
2, though variations exist in
some special cases. The class uses heuristics to determine the correct level based on the
size and connectivity of boundaries within a specified area.
When to Use?
Use this class when you need country-level administrative boundaries for tasks such as global analysis, international comparisons, or providing geographic context for country-specific datasets.
Attributes:
Name | Type | Description |
---|---|---|
division_type |
str
|
Set to "country" to instruct the parent class to look for country-level administrative boundaries. |
layer |
GeoDataFrame
|
The GeoDataFrame containing the country boundaries (set after loading). |
Examples:
Load and visualise country boundaries for a continent:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> countries = mapper.urban_layer.region_countries().from_place("Europe")
>>> countries.static_render(
... figsize=(15, 10),
... edgecolor="black",
... alpha=0.6,
... column="name" # Colour by country name
... )
Specify a custom administrative level:
>>> countries = mapper.urban_layer.region_countries().from_place(
... "World",
... overwrite_admin_level="2" # Explicitly use level 2 for countries
... )
Administrative Level Inference
This class uses heuristics to infer the correct administrative level for countries.
However, as administrative levels can vary, accuracy is not guaranteed. Use the
overwrite_admin_level
parameter in loading methods to manually specify the level
if necessary.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/region_countries.py
CustomUrbanLayer
¶
Bases: UrbanLayerBase
urban_layer
implementation for user-defined spatial layer.
This class allows users to create urban layers
from their own spatial information,
either by loading from files (shapefiles
, GeoJSON
) or by using existing
urban_layer
s from other libraries, if any. It implements the UrbanLayerBase interface
, making it compatible
with other UrbanMapper
components like filters
, enrichers
, and pipelines
.
Why use CustomUrbanLayer?
Custom urban_layer
s are useful for incorporating domain-specific spatial data
that may not be available through standard APIs
, such as:
- Local government datasets
- Research-specific spatial information
- Historical or projected data
- Specialised analysis results
- None of the other
urban_layer
s solved your need
Attributes:
Name | Type | Description |
---|---|---|
layer |
GeoDataFrame | None
|
The |
source |
str | None
|
String indicating how the layer was loaded ("file" or "urban_layer"). |
Examples:
>>> from urban_mapper import UrbanMapper
>>>
>>> # Initialise UrbanMapper
>>> mapper = UrbanMapper()
>>>
>>> # Load data from a GeoJSON file
>>> custom_data = mapper.urban_layer.custom_urban_layer().from_file("path/to/data.geojson")
>>>
>>> # Or create from an existing urban layer
>>> neighborhoods = mapper.urban_layer.region_neighborhoods().from_place("Brooklyn, NY")
>>> custom_layer = mapper.urban_layer.custom_urban_layer().from_urban_layer(neighborhoods)
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
from_file(file_path, **kwargs)
¶
Load custom spatial data from a file.
This method reads spatial data from a shapefile
(.shp) or GeoJSON
(.geojson) file
and prepares it for use as an urban_layer
. The data is automatically converted
to the default coordinate reference system
, i.e EPSG:4326
(WGS 84),
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the file containing spatial data. Must be a |
required |
**kwargs
|
Additional parameters passed to gpd.read_file(). |
{}
|
Returns:
Type | Description |
---|---|
CustomUrbanLayer
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If the file format is not supported or if the file doesn't contain a geometry column. |
FileNotFoundError
|
If the specified file does not exist. |
Examples:
>>> custom_layer = CustomUrbanLayer().from_file("path/to/districts.geojson")
>>> # Visualise the loaded data
>>> custom_layer.static_render(figsize=(10, 8), column="district_name")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
from_urban_layer(urban_layer, **kwargs)
¶
Create a custom urban layer
from an existing urban layer
.
This method creates a new custom urban layer
by copying data from an
existing urban_layer
.
Why use this method?
This is useful in two scenarios:
- You do one urban analysis / pipeline workflow. The second one needs to have the results of the previous one (enriched urban layer).
- For transforming or extending standard
urban_layer
s with custom functionality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urban_layer
|
UrbanLayerBase
|
An instance of |
required |
**kwargs
|
Additional parameters (not used). |
{}
|
Returns:
Type | Description |
---|---|
CustomUrbanLayer
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided object is not a valid |
Examples:
>>> # Get neighborhoods from standard layer
>>> neighborhoods = UrbanMapper().urban_layer.region_neighborhoods().from_place("Chicago")
>>> # Create custom layer from neighborhoods
>>> custom = CustomUrbanLayer().from_urban_layer(neighborhoods)
>>> # Now use custom layer with additional functionality / workflow
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
from_place(place_name, **kwargs)
¶
Load custom data for a specific place.
To Not Use β There For Consistency & Compatibility
This method is not currently implemented for CustomUrbanLayer
, as custom
layers require data to be loaded explicitly from files or other urban_layer
s
rather than from geocoded place names.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
_map_nearest_layer(data, longitude_column, latitude_column, output_column='nearest_feature', threshold_distance=None, _reset_layer_index=True, **kwargs)
¶
Map points to their nearest features
in the custom layer
.
This internal method finds the nearest feature
in the custom layer
for each point
in the input GeoDataFrame
and adds a reference to that feature as a new column.
It's primarily used by the UrbanLayerBase.map_nearest_layer()
method to
implement spatial joining between your dataset point data and custom urban layer's components.
The method uses GeoPandas
' spatial join with nearest match to find the
closest feature for each point. If a threshold distance is specified,
points beyond that distance will not be matched.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
GeoDataFrame
|
|
required |
longitude_column
|
str
|
Name of the column containing longitude values. |
required |
latitude_column
|
str
|
Name of the column containing latitude values. |
required |
output_column
|
str
|
Name of the column to store the indices of nearest features. |
'nearest_feature'
|
threshold_distance
|
float | None
|
Maximum distance to consider a match, in the CRS units. |
None
|
_reset_layer_index
|
bool
|
Whether to reset the index of the layer |
True
|
**kwargs
|
Additional parameters (not used). |
{}
|
Returns:
Type | Description |
---|---|
Tuple[GeoDataFrame, GeoDataFrame]
|
A tuple containing:
- The custom layer |
To Keep In Mind
- The method automatically converts the input data to a projected CRS if it's not already projected, which is necessary for accurate distance calculations.
- Any duplicate indices in the result are removed to ensure a clean result.
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
get_layer()
¶
Get the custom layer as a GeoDataFrame
.
This method returns the custom layer as a GeoDataFrame
, which can be
used for further analysis or visualisation purposes.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
|
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Examples:
>>> custom_layer = CustomUrbanLayer().from_file("path/to/data.geojson")
>>> custom_gdf = custom_layer.get_layer()
>>> # Analyse the data
>>> print(f"Layer has {len(custom_gdf)} features")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
get_layer_bounding_box()
¶
Get the bounding box
of the custom layer
.
This method returns the bounding box
coordinates of the custom layer
,
which can be used for spatial queries, visualisation extents, or other
geospatial operations.
Returns:
Type | Description |
---|---|
Tuple[float, float, float, float]
|
Tuple of ( |
Raises:
Type | Description |
---|---|
ValueError
|
If the layer has not been loaded yet. |
Examples:
>>> custom_layer = CustomUrbanLayer().from_file("path/to/data.geojson")
>>> bbox = custom_layer.get_layer_bounding_box()
>>> print(f"Layer covers area: {bbox}")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
static_render(**plot_kwargs)
¶
Render the custom layer
as a static plot
.
This method creates a static visualisation of the custom layer using
GeoPandas
' plotting functionality. The plot is displayed immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**plot_kwargs
|
Additional keyword arguments to pass to GeoDataFrame.plot(). Common options include:
|
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If no layer has been loaded yet. |
Examples:
>>> custom_layer = CustomUrbanLayer().from_file("path/to/districts.geojson")
>>> # Create a choropleth map by population
>>> custom_layer.static_render(
... figsize=(10, 8),
... column="population",
... cmap="viridis",
... legend=True
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
preview(format='ascii')
¶
Generate a preview of this urban_layer
.
This method creates a textual or structured representation of the CustomUrbanLayer
for quick inspection. It includes metadata about the layer such as its source
,
coordinate reference system
, and any mappings
that have been defined.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The output format for the preview (default: "ascii").
|
'ascii'
|
Returns:
Type | Description |
---|---|
Any
|
A string (for |
Any
|
the |
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported format is requested. |
Examples:
>>> custom_layer = CustomUrbanLayer().from_file("path/to/data.geojson")
>>> # ASCII preview
>>> print(custom_layer.preview())
>>> # JSON preview
>>> import json
>>> print(json.dumps(custom_layer.preview(format="json"), indent=2))
Source code in src/urban_mapper/modules/urban_layer/urban_layers/custom_urban_layer.py
UrbanLayerFactory
¶
Factory for creating urban layer
instances with a fluent chaining-method-based interface.
This factory class provides a chainable API
for creating and configuring
urban layer
instances. It supports setting the layer type
, loading method
,
mappings
, and preview
options before building
the final urban layer
instance.
The factory uses method chaining for a fluent, expressive API:
- [x] Set the layer type with `with_type()`
- [x] Set the loading method with `from_*()` methods
- [x] Add mappings with `with_mapping()`
- [x] Build the layer instance with `build()`
What are the various type available?
The available types are defined in the URBAN_LAYER_FACTORY
dictionary.
As follows:
-
streets_roads
: OSMNXStreets -
streets_intersections
: OSMNXIntersections -
streets_sidewalks
: Tile2NetSidewalks -
streets_crosswalks
: Tile2NetCrosswalks -
streets_features
: OSMFeatures -
region_cities
: RegionCities -
region_neighborhoods
: RegionNeighborhoods -
region_states
: RegionStates -
region_countries
: RegionCountries -
custom_urban_layer
: CustomUrbanLayer
Attributes:
Name | Type | Description |
---|---|---|
layer_class |
Type[UrbanLayerBase] | None
|
The class of the |
loading_method |
str | None
|
The method to call to load the |
loading_args |
Tuple[object, ...]
|
Positional arguments for the loading method. |
loading_kwargs |
Dict[str, object]
|
Keyword arguments for the loading method. |
mappings |
List[Dict[str, object]]
|
List of mapping configurations for this layer. |
Examples:
>>> from urban_mapper as um
>>> streets = um.UrbanMapper().urban_layer ... .with_type("streets_roads") ... .from_place("Manhattan, New York") ... .with_mapping(
... longitude_column="pickup_lng",
... latitude_column="pickup_lat",
... output_column="nearest_street"
... ) ... .with_preview("ascii") ... .build()
Source code in src/urban_mapper/modules/urban_layer/urban_layer_factory.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
with_type(primitive_type)
¶
Set the type of urban layer
to create.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
primitive_type
|
str
|
String identifier for the |
required |
Returns:
Type | Description |
---|---|
UrbanLayerFactory
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided type is not registered in |
Examples:
Source code in src/urban_mapper/modules/urban_layer/urban_layer_factory.py
with_mapping(longitude_column=None, latitude_column=None, output_column=None, **mapping_kwargs)
¶
Add a mapping configuration to the urban layer
.
Mappings define how the urban layer
should be joined or related to other data.
Each mapping specifies which columns contain the coordinates to map, and
what the output column should be named.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
longitude_column
|
str | None
|
Name of the column containing longitude values in the data
to be mapped to this |
None
|
latitude_column
|
str | None
|
Name of the column containing latitude values in the data
to be mapped to this |
None
|
output_column
|
str | None
|
Name of the column that will contain the mapping results. Must be unique across all mappings for this layer. |
None
|
**mapping_kwargs
|
Additional parameters specific to the mapping operation.
Common parameters include |
{}
|
Returns:
Type | Description |
---|---|
UrbanLayerFactory
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If the |
Examples:
>>> factory = um.UrbanMapper().urban_layer ... .with_type("streets_roads") ... .from_place("Manhattan, New York") ... .with_mapping(
... longitude_column="pickup_lng",
... latitude_column="pickup_lat",
... output_column="nearest_street",
... threshold_distance=100
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layer_factory.py
build()
¶
Build and return the configured urban layer
instance.
This method creates an instance of the specified urban layer
class,
calls the loading method with the specified arguments, and attaches
any mappings that were added.
Returns:
Type | Description |
---|---|
UrbanLayerBase
|
An initialised |
UrbanLayerBase
|
loaded with the specified data and configured with the specified mappings. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Examples:
>>> streets = um.UrbanMapper().urban_layer ... .with_type("osmnx_streets") ... .from_place("Manhattan, New York") ... .with_mapping(
... longitude_column="pickup_lng",
... latitude_column="pickup_lat",
... output_column="nearest_street"
... ) ... .build()
Source code in src/urban_mapper/modules/urban_layer/urban_layer_factory.py
preview(format='ascii')
¶
Display a preview of the built urban layer
.
This method generates and displays a preview of the urban layer
instance
that was created by the build()
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The output format for the preview ("ascii" or "json"). |
'ascii'
|
Raises:
Type | Description |
---|---|
ValueError
|
If an unsupported format is requested. |
Examples:
>>> streets = um.UrbanMapper().urban_layer ... .with_type("osmnx_streets") ... .from_place("Manhattan, New York") ... .build()
>>> streets.preview()
Source code in src/urban_mapper/modules/urban_layer/urban_layer_factory.py
with_preview(format='ascii')
¶
Enable automatic preview after building the urban layer
.
This method sets up the factory to automatically display a preview
of the urban layer
instance after it is built with build()
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The output format for the preview ("ascii" or "json"). |
'ascii'
|
Returns:
Type | Description |
---|---|
UrbanLayerFactory
|
Self, for method chaining. |
Examples:
>>> streets = UrbanLayerFactory() ... .with_type("osmnx_streets") ... .from_place("Manhattan, New York") ... .with_preview("json") ... .build()
Source code in src/urban_mapper/modules/urban_layer/urban_layer_factory.py
AdminFeatures
¶
Helper class for dealing with OpenStreetMap features
.
What to understand from this class?
In a nutshell? You barely will be using this out at all, unless you create a new
UrbanLayer
that needs to load OpenStreetMap
features. If not, you can skip reading.
This class provides methods for loading various types of features from OpenStreetMap
using different spatial queries. Features
can include amenities
(restaurants
, hospitals
),
buildings
, infrastructure
, natural features
, and more, specified through OSM tags
.
More can be found at: Map Features.
The class uses OSMnx
's features_from_*
methods to retrieve the data and store it in
a GeoDataFrame
. It supports loading features by place name
, address
, bounding box
,
point with radius, or custom polygon.
Attributes:
Name | Type | Description |
---|---|---|
_features |
GeoDataFrame | None
|
Internal GeoDataFrame containing the loaded OSM features. None until load() is called. |
Examples:
>>> admin_features = AdminFeatures()
>>> # Load all restaurants in Manhattan
>>> tags = {"amenity": "restaurant"}
>>> admin_features.load("place", tags, query="Manhattan, New York")
>>> restaurants = admin_features.features
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_features_.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
features
property
¶
Get the loaded OpenStreetMap
features as a GeoDataFrame
.
This property provides access to the OpenStreetMap
features that were
loaded using the load()
method. The returned GeoDataFrame
contains
geometries and attributes for all features that matched the specified tags.
Returns:
Type | Description |
---|---|
GeoDataFrame
|
GeoDataFrame containing the loaded OpenStreetMap features. |
Raises:
Type | Description |
---|---|
ValueError
|
If features have not been loaded yet. |
Examples:
load(method, tags, **kwargs)
¶
Load OpenStreetMap
features using the specified method and tags.
This method retrieves features from OpenStreetMap
that match the provided
tags, using one of several spatial query methods (address
, bbox
, place
, point
,
or polygon
). The specific parameters required depend on the method chosen.e
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
The spatial query method to use. One of: - "address": Load features around an address - "bbox": Load features within a bounding box - "place": Load features for a named place (city, neighborhood, etc.) - "point": Load features around a specific point - "polygon": Load features within a polygon |
required |
tags
|
Dict[str, str | bool | dict | list]
|
Dictionary specifying the OpenStreetMap tags to filter features. Examples: - {"amenity": "restaurant"} - All restaurants - {"building": True} - All buildings - {"leisure": ["park", "garden"]} - Parks and gardens - {"landuse": "residential"} - Residential areas |
required |
**kwargs
|
Additional arguments specific to the chosen method: - address: Requires "address" (str) and "dist" (float) - bbox: Requires "bbox" (tuple of left, bottom, right, top) - place: Requires "query" (str) - point: Requires "center_point" (tuple of lat, lon) and "dist" (float) - polygon: Requires "polygon" (Shapely Polygon/MultiPolygon) - All methods: Optional "timeout" (int) for Overpass API timeout in seconds |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If an invalid method is specified or required parameters are missing |
Examples:
>>> # Load all parks in Brooklyn
>>> admin_features = AdminFeatures()
>>> admin_features.load(
... "place",
... {"leisure": "park"},
... query="Brooklyn, New York"
... )
>>> # Load all hospitals within 5km of a point
>>> admin_features.load(
... "point",
... {"amenity": "hospital"},
... center_point=(40.7128, -74.0060), # New York City coordinates
... dist=5000 # 5km radius
... )
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_features_.py
AdminRegions
¶
Bases: OSMFeatures
Base class for administrative regions
at various levels
.
What to understand from this class?
In a nutshell? You barely will be using this out at all, unless you create a new
UrbanLayer
that needs to load OpenStreetMap
features. If not, you can skip reading.
This abstract class provides shared functionality for loading
and processing
administrative boundaries
from OpenStreetMap
. It's designed to be subclassed
for specific types of administrative regions (neighborhoods
, cities
, states
, countries
).
The class intelligently handles the complexities of OpenStreetMap's administrative
levels
, which vary across different countries
and regions
. It attempts to infer
the appropriate level based on the type of administrative division requested,
but also allows manual overriding of this inference.
Further can be read at: OpenStreetMap Wiki
to understand why it is complex to infer the right admin_level
.
Attributes:
Name | Type | Description |
---|---|---|
division_type |
str | None
|
The type of administrative division this layer represents (e.g., "neighborhood", "city", "state", "country"). |
tags |
Dict[str, str] | None
|
OpenStreetMap tags used to filter boundary features. |
layer |
GeoDataFrame | None
|
The GeoDataFrame containing the administrative boundary data (set after loading). |
Examples:
>>> # This is an abstract class - use concrete implementations like:
>>> from urban_mapper import UrbanMapper
>>> mapper = UrbanMapper()
>>> # For neighborhoods:
>>> neighborhoods = mapper.urban_layer.region_neighborhoods().from_place("Paris, France")
>>> # For cities:
>>> cities = mapper.urban_layer.region_cities().from_place("HΓ©rault, France")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
|
from_place(place_name, overwrite_admin_level=None, **kwargs)
¶
Load administrative regions
for a named place.
This method retrieves administrative boundaries for a specified place
name from OpenStreetMap
. It filters for the appropriate administrative
level
based on the division_type set for this layer, and can be manually
overridden if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
place_name
|
str
|
Name of the place to load administrative regions for (e.g., "New York City", "Bavaria, Germany"). |
required |
overwrite_admin_level
|
str | None
|
Manually specify the OpenStreetMap admin_level to use instead of inferring it. Admin levels differ by region but typically follow patterns like:
Feel free to look into OSM Wiki. |
None
|
**kwargs
|
Additional parameters passed to OSMnx's features_from_place. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If division_type is not set or if no administrative boundaries are found for the specified place. |
Examples:
>>> # Get neighborhoods in Manhattan
>>> neighborhoods = AdminRegions()
>>> neighborhoods.division_type = "neighborhood"
>>> neighborhoods.from_place("Manhattan, New York")
>>> # Override admin level for more control
>>> cities = AdminRegions()
>>> cities.division_type = "city"
>>> cities.from_place("France", overwrite_admin_level="6")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
from_address(address, dist, overwrite_admin_level=None, **kwargs)
¶
Load administrative regions
for a specific address.
This method retrieves administrative boundaries for a specified address
from OpenStreetMap
. It filters for the appropriate administrative
level
based on the division_type set for this layer, and can be manually
overridden if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
address
|
str
|
Address to load administrative regions for (e.g., "1600 Amphitheatre Parkway, Mountain View, CA"). |
required |
dist
|
float
|
Distance in meters to search around the address. Consider this a radius. |
required |
overwrite_admin_level
|
str | None
|
Manually specify the OpenStreetMap admin_level to use instead of inferring it. Admin levels differ by region but typically follow patterns like:
Feel free to look into OSM Wiki. |
None
|
**kwargs
|
Additional parameters passed to OSMnx's features_from_address. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If division_type is not set or if no administrative boundaries are found for the specified address. |
Examples:
>>> # Get neighborhoods around a specific address
>>> neighborhoods = AdminRegions()
>>> neighborhoods.division_type = "neighborhood"
>>> neighborhoods.from_address("1600 Amphitheatre Parkway, Mountain View, CA", dist=500)
>>> # Override admin level for more control
>>> cities = AdminRegions()
>>> cities.division_type = "city"
>>> cities.from_address("1600 Amphitheatre Parkway, Mountain View, CA", dist=500, overwrite_admin_level="6")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
from_bbox(bbox, overwrite_admin_level=None, **kwargs)
¶
Load administrative regions
for a specific bounding box.
This method retrieves administrative boundaries for a specified bounding
box from OpenStreetMap
. It filters for the appropriate administrative
level
based on the division_type set for this layer, and can be manually
overridden if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bbox
|
Tuple[float, float, float, float]
|
Tuple of (left, bottom, right, top) coordinates defining the bounding box. |
required |
overwrite_admin_level
|
str | None
|
Manually specify the OpenStreetMap admin_level to use instead of inferring it. Admin levels differ by region but typically follow patterns like:
Feel free to look into OSM Wiki. |
None
|
**kwargs
|
Additional parameters passed to OSMnx's features_from_bbox. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If division_type is not set or if no administrative boundaries are found for the specified bounding box. |
Examples:
>>> # Get neighborhoods within a specific bounding box
>>> bbox = (-73.935242, 40.730610, -73.925242, 40.740610) # Example coordinates
>>> neighborhoods = AdminRegions()
>>> neighborhoods.division_type = "neighborhood"
>>> neighborhoods.from_bbox(bbox)
>>> # Override admin level for more control
>>> cities = AdminRegions()
>>> cities.division_type = "city"
>>> cities.from_bbox(bbox, overwrite_admin_level="8")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
|
from_point(lat, lon, dist, overwrite_admin_level=None, **kwargs)
¶
Load administrative regions
for a specific point.
This method retrieves administrative boundaries for a specified point
from OpenStreetMap
. It filters for the appropriate administrative
level
based on the division_type set for this layer, and can be manually
overridden if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lat
|
float
|
Latitude of the point to load administrative regions for. |
required |
lon
|
float
|
Longitude of the point to load administrative regions for. |
required |
dist
|
float
|
Distance in meters to search around the point. Consider this a radius. |
required |
overwrite_admin_level
|
str | None
|
Manually specify the OpenStreetMap admin_level to use instead of inferring it. Admin levels differ by region but typically follow patterns like:
Feel free to look into OSM Wiki. |
None
|
**kwargs
|
Additional parameters passed to OSMnx's features_from_point. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If division_type is not set or if no administrative boundaries are found for the specified point. |
Examples:
>>> # Get neighborhoods around a specific point
>>> neighborhoods = AdminRegions()
>>> neighborhoods.division_type = "neighborhood"
>>> neighborhoods.from_point(40.730610, -73.935242, dist=500)
>>> # Override admin level for more control
>>> cities = AdminRegions()
>>> cities.division_type = "city"
>>> cities.from_point(40.730610, -73.935242, dist=500, overwrite_admin_level="8")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|
from_polygon(polygon, overwrite_admin_level=None, **kwargs)
¶
Load administrative regions
for a specific polygon.
This method retrieves administrative boundaries for a specified polygon
from OpenStreetMap
. It filters for the appropriate administrative
level
based on the division_type set for this layer, and can be manually
overridden if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Shapely Polygon or MultiPolygon to load administrative regions for. |
required |
overwrite_admin_level
|
str | None
|
Manually specify the OpenStreetMap admin_level to use instead of inferring it. Admin levels differ by region but typically follow patterns like:
Feel free to look into OSM Wiki. |
None
|
**kwargs
|
Additional parameters passed to OSMnx's features_from_polygon. |
{}
|
Returns:
Type | Description |
---|---|
None
|
Self, for method chaining. |
Raises:
Type | Description |
---|---|
ValueError
|
If division_type is not set or if no administrative boundaries are found for the specified polygon. |
Examples:
>>> # Create a polygon out of an address for instance, with the help of geopy
>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim(user_agent="urban_mapper")
>>> location = geolocator.geocode("1600 Amphitheatre Parkway, Mountain View, CA", geometry="wkt")
>>> polygon = loads(location.raw["geotext"])
>>> # Get neighborhoods within a specific polygon
>>> neighborhoods = AdminRegions()
>>> neighborhoods.division_type = "neighborhood"
>>> neighborhoods.from_polygon(polygon)
>>> # Override admin level for more control
>>> cities = AdminRegions()
>>> cities.division_type = "neighborhood"
>>> cities.from_polygon(polygon, overwrite_admin_level="8")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
|
from_file(file_path, overwrite_admin_level=None, **kwargs)
¶
Load administrative regions
from a file.
Not implemented
This method is not implemented for this class. It raises a NotImplementedError
to indicate that loading administrative regions from a file is not supported.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
Path to the file containing administrative regions data. |
required |
overwrite_admin_level
|
str | None
|
(Optional) Manually specify the OpenStreetMap admin_level to use instead of inferring it. Admin levels differ by region but typically follow patterns like:
|
None
|
**kwargs
|
Additional parameters passed to OSMnx's features_from_file. |
{}
|
Raises:
Type | Description |
---|---|
NotImplementedError
|
This method is not implemented for this class. |
Examples:
>>> # Load administrative regions from a file (not implemented)
>>> admin_regions = AdminRegions()
>>> admin_regions.from_file("path/to/file.geojson")
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py
_calculate_connectivity(gdf)
¶
Calculate the spatial connectivity
percentage for a set of polygons.
What is spatial connectivity?
Spatial connectivity refers to the degree to which polygons in a geographic dataset are adjacent or overlapping with each other.
In the context of administrative boundaries, it indicates how well-defined and interconnected the regions are. A high connectivity percentage suggests that the polygons are closely related and form a coherent administrative structure, while a low percentage may indicate isolated or poorly defined regions.
Note that this method is not a strict measure of connectivity but rather an approximation based on the number of polygons that share boundaries.
Lastly, note that this is also a static
method, consider this as an helper to only
use within the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf
|
GeoDataFrame
|
|
required |
Returns:
Type | Description |
---|---|
float
|
Percentage (0-100) of polygons that touch or overlap with at least |
float
|
one other polygon in the dataset. |
Source code in src/urban_mapper/modules/urban_layer/urban_layers/admin_regions_.py
preview(format='ascii')
¶
Preview the urban layer
in a human-readable format.
This method provides a summary of the urban layer
attributes, including
the division type, tags, coordinate reference system, and mappings.
It can return the preview in either ASCII or JSON format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
str
|
The format for the preview. Can be "ascii" or "json". Default is "ascii". |
'ascii'
|
Returns:
Type | Description |
---|---|
Any
|
A string or dictionary containing the preview of the urban layer. |
Any
|
If format is "ascii", returns a formatted string. If format is "json", |
Any
|
returns a dictionary. |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified format is not supported. |