transport_frames.graph

Module for creating city network graph from polygon

Functions

classify_nodes(graph)

Assigns reg_status to nodes based on edge data.

get_graph(*[, osm_id, territory, buffer])

Collect a drive graph from OSM relation id or input territory.

get_intermodal_graph(*[, osm_id, territory])

Collect an intermodal graph (public transport + walking) from OSM id or territory.

Classes

PolygonSchema(*args, **kwargs)

Schema for validating polygons.

class transport_frames.graph.PolygonSchema(*args, **kwargs)[source]

Bases: BaseSchema

Schema for validating polygons.

Variables:

_geom_types (list) – List of allowed geometry types for the blocks, default is [shapely.Polygon]

class Config

Bases: Config

name = 'PolygonSchema'
transport_frames.graph.get_graph(*, osm_id: int | None = None, territory: GeoDataFrame | None = None, buffer: int = 3000) MultiDiGraph[source]

Collect a drive graph from OSM relation id or input territory.

Parameters:
  • osm_id (int | None, optional) – OSM relation id. If provided, territory is downloaded from OSM by id.

  • territory (gpd.GeoDataFrame | None, optional) – Territory boundary as GeoDataFrame.

  • local_crs (int | None, optional) – Local projection CRS. If None, estimated from territory via estimate_utm_crs().

  • buffer (int, optional) – Buffer distance (meters) used before graph download.

Returns:

Region network drive graph.

Return type:

nx.MultiDiGraph

transport_frames.graph.get_intermodal_graph(*, osm_id: int | None = None, territory: GeoDataFrame | None = None) MultiDiGraph[source]

Collect an intermodal graph (public transport + walking) from OSM id or territory.

Parameters:
  • osm_id (int | None, optional) – OSM relation id. If provided, territory is downloaded from OSM by id.

  • territory (gpd.GeoDataFrame | None, optional) – Territory boundary as GeoDataFrame.

Returns:

Intermodal graph.

Return type:

nx.MultiDiGraph

transport_frames.graph._category_to_reg(category) int | None[source]

Convert iduedu road category into legacy numeric reg code.

transport_frames.graph._ensure_reg_attr(graph: MultiDiGraph) MultiDiGraph[source]

Ensure every edge has numeric reg attribute derived from category if needed.

transport_frames.graph.classify_nodes(graph: MultiDiGraph) MultiDiGraph[source]

Assigns reg_status to nodes based on edge data.

Parameters:

graph (nx.MultiDiGraph) – The road network graph with classified edges

Returns:

City network drive graph with classified nodes and edges

Return type:

nx.MultiDiGraph

transport_frames.graph._crop_edges_by_polygon(graph: MultiDiGraph, polygon: Polygon) MultiDiGraph[source]

Updates edge geometries based on intersections with the city boundary.

Parameters:
  • graph (nx.MultiDiGraph) – The city network graph

  • polygon (Polygon) – The Polygon to crop edges with

Returns:

City network drive graph with cropped edges

Return type:

nx.MultiDiGraph

transport_frames.graph._create_graph(edges: GeoDataFrame, nodes_coord: dict) MultiDiGraph[source]

Create a graph based on edges and node coordinates.

Parameters:
  • edges (gpd.GeoDataFrame:) – The edges with their attributes and geometries

  • nodes_coord (dict) – A dictionary containing node coordinates

Returns:

The constructed graph

Return type:

nx.MultiDiGraph