Transportation Module¶
The transportation module loads GTFS public transport archives and local GBFS shared-mobility JSON feeds into DuckDB. It also derives stop-to-stop origin–destination records and aggregates GTFS schedules into transportation network graphs.
GTFS transportation network utilities.
The functions in this module load GTFS feeds into DuckDB, derive stop-to-stop origin/destination records, and aggregate those records into transport summary graphs for downstream network analysis.
Functions:
| Name | Description |
|---|---|
load_gtfs | Load a GTFS ZIP archive into an in-memory DuckDB database. |
load_gbfs | Load GBFS JSON feeds from a directory into an in-memory DuckDB database. |
get_od_pairs | Generate stop-to-stop OD pairs from GTFS trip stop sequences. |
travel_summary_graph | Aggregate GTFS service into a weighted stop-to-stop summary graph. |
load_gtfs ¶
Load a GTFS ZIP archive into an in-memory DuckDB database.
The function reads *.txt GTFS files as tables, registers a time parsing UDF, and materializes stops.geometry as points from stop_lon/stop_lat when stop coordinates are available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path | Path to a GTFS | required |
Returns:
| Type | Description |
|---|---|
DuckDBPyConnection | In-memory DuckDB connection containing imported GTFS tables. |
load_gbfs ¶
Load GBFS JSON feeds from a directory into an in-memory DuckDB database.
The function reads GBFS JSON files from a local directory, flattens common feed structures into DuckDB tables, and materializes geometry columns from lon/lat fields when available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path | Path to a GBFS directory containing JSON files. | required |
Returns:
| Type | Description |
|---|---|
DuckDBPyConnection | In-memory DuckDB connection containing imported GBFS tables. |
get_od_pairs ¶
Generate stop-to-stop OD pairs from GTFS trip stop sequences.
For each trip_id, consecutive stops are paired into directed legs with departure/arrival timestamps and per-leg travel time in seconds. Service activity is derived from calendar and optionally adjusted using calendar_dates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con | DuckDBPyConnection | DuckDB connection with GTFS tables loaded. | required |
start_date | str | None | Inclusive start date ( | None |
end_date | str | None | Inclusive end date ( | None |
include_geometry | bool | If | True |
directed | bool | If | False |
Returns:
| Type | Description |
|---|---|
DataFrame | GeoDataFrame | One row per directed (or undirected) stop-to-stop leg. |
travel_summary_graph ¶
travel_summary_graph(
con,
start_time=None,
end_time=None,
calendar_start=None,
calendar_end=None,
as_nx=None,
directed=False,
use_frequencies=True,
)
Aggregate GTFS service into a weighted stop-to-stop summary graph.
The function builds a stop-level graph from the GTFS feed, where each edge represents the aggregated service between two consecutive stops.
Edge attributes ~~~~~~~~~~~~~~~ travel_time_sec Service-weighted average travel time in seconds across all trips serving this stop pair. frequency Total number of scheduled leg traversals in the resolved calendar window. When use_frequencies=True and frequencies.txt is present, headway-based services are expanded into effective trip counts. For example, a trip running every 10 minutes for 1 hour contributes 6 traversals per active service day.
Edge geometry ~~~~~~~~~~~~~ Edge geometry is represented as a straight stop-to-stop line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con | DuckDBPyConnection | DuckDB connection with GTFS tables loaded. | required |
start_time | str | None | Optional lower bound (inclusive) for departure time, | None |
end_time | str | None | Optional upper bound (inclusive) for next-stop arrival time, | None |
calendar_start | str | None | Optional calendar window start, | None |
calendar_end | str | None | Optional calendar window end, | None |
as_nx | bool | If .. deprecated:: | None |
directed | bool | If | False |
use_frequencies | bool | If | True |
Returns:
| Type | Description |
|---|---|
tuple[GeoDataFrame, GeoDataFrame] | DiGraph | Graph |
|