transport_frames.graph

Module for creating city network graph from polygon

Functions

classify_nodes(graph)

Assigns reg_status to nodes based on edge data.

from_polygon_iduedu(polygon, local_crs[, buffer])

Downloads the drive graph from OSM.

get_graph_from_polygon(polygon, local_crs)

Collects a drive graph from polygon.

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_from_polygon(polygon: GeoDataFrame, local_crs: int) MultiDiGraph[source]

Collects a drive graph from polygon.

Parameters:
  • polygon (gpd.GeoDataFrame) – GeoDataFrame of territory boundary polygon

  • local_crs (int) – Local projection CRS

Returns:

City network drive graph.

Return type:

nx.MultiDiGraph

transport_frames.graph.from_polygon_iduedu(polygon: GeoDataFrame, local_crs: int, buffer=3000) MultiDiGraph[source]

Downloads the drive graph from OSM.

Parameters:
  • polygon (gpd.GeoDataFrame) – GeoDataFrame of the Polygon

  • local_crs (int) – Local projection CRS

  • buffer (int) – The size of buffer for edges cropping

Returns:

City network drive graph

Return type:

nx.MultiDiGraph

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