transitlos.map.routes¶
Build one map-ready line feature per GTFS route_id, for the map's transit-lines overlay.
Deliberately a small, dependency-light GTFS reader (plain pandas.read_csv
over routes.txt/trips.txt/shapes.txt/stop_times.txt/stops.txt)
rather than a pyGTFSHandler.feed.Feed load: this needs geometry only, no
service-calendar filtering, no headway/speed analysis, and no stop grouping --
all of which is what makes a full Feed load expensive (tens of seconds to
minutes per city). Nothing here is city-specific; a caller passes GTFS
directories in and gets a GeoDataFrame back.
Geometry source, in priority order (per the "shapes if available, else straight lines between consecutive stops" requirement):
shapes.txtpolylines referenced by that route's trips (the real, on-street alignment) -- EXCEPT a shape whose own points turn out to just be that trip's stops connected (see_stop_derived_shape_ids), which is treated the same as having no shape at all, not a real alignment.- If a route has no usable shape, the stop sequence of its longest trip
(
stop_times.txtordered bystop_sequence, joined tostops.txtcoordinates) connected by straight segments.
One feature per route_id (the explicit deliverable), not one per trip or
shape: a route's many trip shapes are collapsed by a greedy "does this
candidate add geometry the already-kept ones don't cover?" pass, so a route
with genuinely separate branches (e.g. a light-rail trunk splitting into
several tails) keeps them as a MultiLineString while the dozens of
near-identical per-trip variants of an ordinary bus route collapse to one
LineString.
build_route_lines(gtfs_dirs, aoi=None, exclude_no_shape_routes=True)
¶
Build one line feature per GTFS route_id across one or more feeds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gtfs_dirs
|
Union[str, Path, Iterable[Union[str, Path]]]
|
A GTFS directory, or an iterable of them (one per feed). Zipped feeds are not handled here -- pass extracted directories. |
required |
aoi
|
Optional[GeoDataFrame]
|
Optional area of interest (any CRS); routes whose geometry does not intersect its union are dropped, so a metro-scale map isn't carrying intercity coach routes running hundreds of km away. |
None
|
exclude_no_shape_routes
|
bool
|
2026-09-01, user-requested default: a route
with no real |
True
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A WGS84 GeoDataFrame with one row per |
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
|
GeoDataFrame
|
( |
GeoDataFrame
|
(GTFS |
GeoDataFrame
|
(GTFS |
GeoDataFrame
|
of the route's trips had real |
GeoDataFrame
|
every trip fell back to the straight-line stop-sequence |
GeoDataFrame
|
connect-the-dots geometry), plus LineString/MultiLineString |
GeoDataFrame
|
|