iduedu.get_single_public_transport_graph¶
- iduedu.get_single_public_transport_graph(public_transport_type, *, osm_id=None, territory=None, clip_by_territory=False, keep_edge_geometry=True, osm_edge_tags=None)[source]¶
Build a directed graph for a single public-transport mode within a given territory.
The function resolves a boundary (by osm_id or territory), downloads OpenStreetMap routes inside that boundary, converts them into a projected nx.DiGraph, and computes per-edge length (meters) and travel time (minutes). When the mode is subway, additional station context is incorporated: entrances/exits and inter-station transfers are added; station metadata (e.g., name, depth) is attached to nodes where available.
- Parameters:
public_transport_type (
str | PublicTrasport) – One mode, e.g. “bus”, “tram”, “trolleybus”, “subway”. You may pass a PublicTrasport enum or its string value.osm_id (
int | None) – OSM relation/area id of the territory. Provide this or territory.territory (
Polygon | MultiPolygon | gpd.GeoDataFrame | None) – Boundary geometry in EPSG:4326 (or a GeoDataFrame). Used when osm_id is not given.clip_by_territory (
bool) – If True, the resulting graph is clipped to the boundary (in the local CRS).keep_edge_geometry (
bool) – If True, edge shapes (shapely geometries in local CRS) are stored on edges.osm_edge_tags (
list[str] | None) – Subset of OSM tags to retain on edges/nodes. If None, a sensible default is used from configuration; only requested keys are joined from OSM element tags.
- Returns:
- Directed PT graph with:
node attrs: x, y (floats, local CRS), type, route, ref_id, plus merged station extra_data (if any);
edge attrs: type, route, length_meter, time_min, optional geometry, and selected OSM tags.
Graph attrs: graph[“crs”] (EPSG int of the local projected CRS), graph[“type”] = “public_trasport”.
- Return type:
(nx.DiGraph)
Notes
Lengths and times are computed in a local projected CRS estimated from the boundary; per-edge speeds are taken from mode-specific defaults (and, for subway connectors, from connector-type defaults).