Files
jetlag-maps/copenhagen/scripts/gtfs_to_geopackage.py
T
marvin ac02320f1d Copenhagen Phase 1: scaffolding + area + OSM download
- pyproject.toml with all deps (geopandas, contextily, partridge, etc.)
- config/: area.json (3 OSM boundary relations), modes.yaml (subway/s_tog/
  light_rail/regional/bus, S-tog scoped to route=light_rail network=Takst),
  styling.yaml (zorder/widths/colours/palette/mask/labels)
- build_area.py: fetch 3 relations via OSM API, stitch rings, dissolve to
  area.gpkg/area.geojson (City Pass approximation)
- download_osm.py: per-mode Overpass (mirror+backoff, out geom + recurse for
  stops), writes {mode}.gpkg (lines+stops) + query text
- download_gtfs.py / gtfs_to_geopackage.py: stubs (blocked on Rejseplanen)
- data/ gitignored (regenerable); output/ tracked
2026-09-13 01:15:25 +02:00

43 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Convert raw GTFS txt files into portable GeoPackage layers + a colour table.
STATUS: BLOCKED on download_gtfs.py (no feed URL yet).
Intended outputs (data/processed):
gtfs_shapes.gpkg (shapes.txt -> LineString per shape_id, EPSG:4326)
gtfs_stops.gpkg (stops.txt -> Point per stop, EPSG:4326)
route_colors.csv (route_id, route_short_name, route_type, route_color)
Uses partridge for fast GTFS parsing. prepare.py reads these when present and
falls back to OSM-only data when absent.
"""
import sys
from pathlib import Path
from _common import GTFS_RAW, PROCESSED
def main():
if not (GTFS_RAW / "routes.txt").exists():
print(
"gtfs_to_geopackage: BLOCKED — no GTFS data found in "
f"{GTFS_RAW}. Run download_gtfs.py first once a feed URL is set.",
file=sys.stderr,
)
sys.exit(2)
# TODO (when GTFS available):
# import partridge as pt
# import geopandas as gpd
# from shapely.geometry import LineString, Point
# feed = pt.load_geo_feed(str(GTFS_RAW))
# shapes -> gtfs_shapes.gpkg (LineString per shape_id)
# stops -> gtfs_stops.gpkg
# routes -> route_colors.csv (route_id, route_short_name, route_type, route_color)
print("gtfs_to_geopackage: not yet implemented (GTFS feed unavailable).")
sys.exit(2)
if __name__ == "__main__":
main()