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
This commit is contained in:
2026-09-17 21:07:40 +02:00
parent 4aca62ca1a
commit b7d51ca29f
12 changed files with 522 additions and 751 deletions
+11 -24
View File
@@ -1,40 +1,27 @@
#!/usr/bin/env python3
"""Download the Rejseplanen GTFS feed for the Copenhagen area.
"""Download the Rejseplanen GTFS feed (all of Denmark) and unzip into data/raw/gtfs/.
STATUS: BLOCKED. Rejseplanen (journey planner) does not currently expose a
public GTFS download. This script documents the intended flow and exits
non-zero with guidance.
When a feed URL becomes available, set it here and the script will download
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 sys
import urllib.request
import zipfile
from pathlib import Path
from _common import GTFS_RAW
from _common import GTFS_RAW, UA
# Fill in once access is granted. Likely candidates:
# - Rejseplanen / DOT open-data portal
# - a static GTFS zip provided on request
GTFS_URL = None # e.g. "https://.../rejseplanen.zip"
GTFS_URL = "https://www.rejseplanen.info/labs/GTFS.zip"
def main():
if not GTFS_URL:
print(
"download_gtfs: BLOCKED — no GTFS feed URL configured.\n"
"Set GTFS_URL in this script once Rejseplanen grants access, then re-run.\n"
"The OSM-only pipeline (build_area -> download_osm -> prepare -> render)\n"
"is fully functional without GTFS; GTFS only enriches colours/stops.",
file=sys.stderr,
)
sys.exit(2)
GTFS_RAW.mkdir(parents=True, exist_ok=True)
zip_path = GTFS_RAW / "feed.zip"
print(f"downloading {GTFS_URL} -> {zip_path} ...", flush=True)
urllib.request.urlretrieve(GTFS_URL, zip_path)
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)