Files
jetlag-maps/copenhagen/scripts/download_gtfs.py
T
marvin b7d51ca29f Source Copenhagen transit data from Rejseplanen GTFS
- Replace OSM Overpass transit data with the Rejseplanen GTFS feed
  (routes keyed by (agency, short name); styles from modes.yaml)
- Draw one shape per (style, ref, direction), choosing the shape that
  serves the most in-area stops so lines pass the stops we show
- Collapse stops by names (verified unambiguous); prune stops whose
  serving refs have no drawn line within 300 m
- Patch Københavns Havn + Nordhavn into the area polygon so ferry
  routes and sub-harbour metro tunnels survive clipping; 100 m buffer
  closes relation boundary slivers
- Drop OSM download pipeline; keep tiled basemap
2026-09-17 21:07:40 +02:00

33 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Download the Rejseplanen GTFS feed (all of Denmark) and unzip into data/raw/gtfs/.
Source: https://www.rejseplanen.info/labs — a static GTFS zip published by
Rejseplanen covering DSB, DSB S-tog, Metroselskabet, Movia, Lokaltog,
Hovedstadens Letbane, Skånetrafiken, etc. Nationwide feed; gtfs_to_geopackage.py
filters it down to the Copenhagen area.
"""
import urllib.request
import zipfile
from _common import GTFS_RAW, UA
GTFS_URL = "https://www.rejseplanen.info/labs/GTFS.zip"
def main():
GTFS_RAW.mkdir(parents=True, exist_ok=True)
zip_path = GTFS_RAW / "feed.zip"
print(f"downloading {GTFS_URL} -> {zip_path} ...", flush=True)
req = urllib.request.Request(GTFS_URL, headers={"User-Agent": UA})
with urllib.request.urlopen(req) as r, zip_path.open("wb") as f:
while chunk := r.read(1 << 20):
f.write(chunk)
with zipfile.ZipFile(zip_path) as z:
z.extractall(GTFS_RAW)
zip_path.unlink(missing_ok=True)
print(f"extracted GTFS txt files into {GTFS_RAW}")
if __name__ == "__main__":
main()