osm_road_network

OpenStreetMap road network data retrieval and processing module.

This module provides functionality for accessing and processing road network data from OpenStreetMap (OSM) for various transportation modes (driving, walking, cycling). It serves as the foundation for service area calculations and travel time/distance analyses in the PISA package.

Examples

Retrieve and process a road network for walking travel time analysis:

>>> from pisa.administrative_area import AdministrativeArea
>>> from pisa.osm_road_network import OsmRoadNetwork
>>>
>>> # Get administrative area boundaries
>>> admin_area = AdministrativeArea("Timor-Leste", admin_level=1)
>>> boundaries = admin_area.get_admin_area_boundaries("Baucau")
>>>
>>> # Create a road network for walking travel time analysis
>>> road_network = OsmRoadNetwork(
>>>     admin_area_boundaries=boundaries,
>>>     mode_of_transport="walking",
>>>     distance_type="travel_time"
>>> )
>>>
>>> # Get the processed network with travel time attributes
>>> graph = road_network.get_osm_road_network()
>>>
>>> # Check some network statistics
>>> print(f"Number of nodes: {len(graph.nodes)}")
>>> print(f"Number of edges: {len(graph.edges)}")

See also

isopolygons

Module for calculating service areas using road networks

administrative_area

Module for defining the geographic scope of the road network

Attributes

logger

Classes

OsmRoadNetwork

Class to retrieve and process OpenStreetMap road network data.

Module Contents

osm_road_network.logger
class osm_road_network.OsmRoadNetwork(admin_area_boundaries: shapely.Polygon | shapely.MultiPolygon, mode_of_transport: str, distance_type: str, fallback_speed: int | float | None = None)

Class to retrieve and process OpenStreetMap road network data.

Parameters:
  • admin_area_boundaries (Polygon | MultiPolygon) – The geography of the administrative area object.

  • mode_of_transport (str) – The mode of transport for which the road network is required.

  • distance_type (str) – The type of distance to be calculated.

  • fallback_speed (int | float | None) – The speed to be used for road types where OSM does not provide a speed attribute. If not provided, osmnx will do the imputation (recommended).

admin_area_boundaries
distance_type
network_type
get_osm_road_network() networkx.MultiDiGraph

Get the processed OpenStreetMap road network for the administrative area.

This method retrieves the OSM road network for the specified administrative area and processes it according to the configured distance type. If the distance type is travel_time, travel times are added to the network edges.

Returns:

NetworkX MultiDiGraph representing the road network with appropriate attributes:

  • If distance_type is length, the graph has length attributes on edges (in meters)

  • If distance_type is travel_time, the graph has travel_time attributes on edges (in minutes)

Return type:

nx.MultiDiGraph