maps: wire the transit_stops layer into the v5 build
- Commit
113fbca875df8d3223257c6cb17ba4914b342507- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-21 04:05 UTC (3 months ago)
- Parents
f65c58c
Adds build_transit_stops_layer in both .sh and .ps1 form, chaining gtfs_ingest's transit_stops binary into tile_build's tile_points. Both produce byte-identical archives from the same manifest, verified on this box. The layer takes GTFS dirs rather than --pbf, so build_v5_pmtiles.sh gets --gtfs-manifest instead of reusing the require-PBF guard, and skips the step with a message when it is absent rather than failing a build that never asked for stops. The final merge now calls our own tile_join instead of tippecanoe's, so neither the merge nor this layer needs tippecanoe installed. Widened the --help sed range to cover the grown header and updated the reported layer list. README: reworked the prerequisites around cargo being sufficient for a growing share of the pipeline, added the new scripts and both Rust crates to the files table, noted which steps run on Windows, and flagged that tile_join holds inputs in memory so compositing against the 1.5 GB published basemap needs a big-memory machine.
Diff
scripts/maps/README.md
diff --git a/scripts/maps/README.md b/scripts/maps/README.mdindex 5be9bf63fe..f20e312431 100644--- a/scripts/maps/README.md+++ b/scripts/maps/README.md@@ -163,7 +163,7 @@ mutually consistent (same POI set, same coordinates). See | File | Purpose | |---|---|-| `build_v5_pmtiles.sh` | **Top-level orchestrator**: base + safety + maxspeed + transit_lines + admin → merge → `v5.pmtiles` |+| `build_v5_pmtiles.sh` | **Top-level orchestrator**: base + safety + maxspeed + transit_lines + ma_pois + admin + transit_stops → merge → `v5.pmtiles` | | `build_base_layers.sh` | Base tiles (Planetiler build **or** reuse upstream `v4.pmtiles`) | | `build_safety_layer.sh` | osmium → GeoJSON → `normalize_safety.py` → tippecanoe → `safety.pmtiles` | | `build_maxspeed_layer.sh` | osmium → GeoJSON → `normalize_maxspeed.py` → tippecanoe → `maxspeed.pmtiles` |@@ -172,6 +172,10 @@ mutually consistent (same POI set, same coordinates). See | `osm_ingest/` | Rust OSM ingest crate (detached, `.osm.pbf` read natively): `poi_extract` (POI layer + side files) and `road_graph` (routing graph). Full TYPE MAP and on-disk layouts in `src/poi_build.rs` / `src/graph_build.rs`; see [`osm_ingest/README.md`](osm_ingest/README.md) | | `build_graph.ps1` | Windows entry point for the routing-graph build (no WSL, no g++) | | `build_admin_layers.sh` | Natural Earth / OSM → `normalize_admin.py` → tippecanoe → `admin_*.pmtiles` |+| `build_transit_stops_layer.sh` | GTFS dirs → `gtfs_ingest` `transit_stops` → geojsonseq → `tile_build` `tile_points` → `transit_stops.pmtiles`. **No tippecanoe, no osmium** |+| `build_transit_stops_layer.ps1` | **Windows** entry point for the same layer (cargo-only) |+| `gtfs_ingest/` | Rust GTFS crate (detached): `gtfs_ingest` (the on-device `.transit` pack) and `transit_stops` (the basemap stop layer). TRX2 on-disk format documented in `src/index.rs` |+| `tile_build/` | Rust MVT + PMTiles v3 crate (detached), **replacing tippecanoe and tile-join**: `tile_points` (tile a point geojsonseq) and `tile_join` (merge archives). Container layout documented in `src/pmtiles.rs` | | `publish_r2.sh` | Upload built `.pmtiles` to Cloudflare R2 (creds from env vars only) | | `normalize_safety.py` | OSM tags → `safety` layer schema (pure stdlib, unit-tested) | | `normalize_maxspeed.py` | OSM maxspeed ways → `maxspeed` layer schema (pure stdlib, unit-tested) |@@ -187,19 +191,44 @@ mutually consistent (same POI set, same coordinates). See Full build needs (all are existing off-the-shelf tools — the only code authored here is Rust and Python): -* **tippecanoe** ≥ 2.x (provides `tippecanoe` + `tile-join`, both write `.pmtiles`)-* **osmium-tool** (`osmium`)-* **GDAL** (`ogr2ogr`)-* **cargo** (https://rustup.rs) — for the `ma_pois` extractor and the routing- graph, both in [`osm_ingest`](osm_ingest/). No C/C++ toolchain and no- libosmium: `osm_ingest` reads `.osm.pbf` natively, so the routing graph and the- two POI side files build on **Windows** as well (`build_graph.ps1`). Only the- `.pmtiles` steps still need tippecanoe/osmium.-* **python3** (stdlib only)+* **cargo** (https://rustup.rs) — and for a growing share of the pipeline, the+ *only* thing needed. It builds:+ * [`osm_ingest`](osm_ingest/) — the `ma_pois` extractor and the routing graph.+ No C/C++ toolchain and no libosmium: it reads `.osm.pbf` natively.+ * [`gtfs_ingest`](gtfs_ingest/) — the on-device `.transit` pack and the+ `transit_stops` basemap layer.+ * [`tile_build`](tile_build/) — MVT and PMTiles v3 read/write, which **replaces+ tippecanoe and tile-join**. The final merge and the `transit_stops` layer both+ go through it, so they run on **Windows**.+* **tippecanoe** ≥ 2.x — still required by the safety, maxspeed, transit_lines,+ ma_pois and admin layer scripts, which pipe GeoJSON through it. The merge no+ longer uses its `tile-join`.+* **osmium-tool** (`osmium`) — still required by those same OSM-derived layers.+* **GDAL** (`ogr2ogr`) — transit_lines only.+* **python3** (stdlib only) — the `normalize_*.py` schema mappers. * Base build mode only: **Java 21** + the Protomaps basemap jar (build once from `github.com/protomaps/basemaps`, `tiles/` → `mvn package`) * Base reuse mode only: `curl`, and `go-pmtiles` (`pmtiles`) if using `--bbox` +### What builds on Windows++Everything that is cargo-only: the routing graph (`build_graph.ps1`), the offline+transit pack (`build_ca_transit.ps1`), the `transit_stops` layer+(`build_transit_stops_layer.ps1`) and the final merge (`tile_join`). The+OSM-derived vector layers still need tippecanoe + osmium and therefore a Linux+box or WSL.++That is why `tile_build` exists rather than shelling out to tippecanoe: there is+no Windows path for it (see the note at `build_graph.ps1:29`), which would+otherwise have left `transit_stops` unbuildable on the dev box.++> **`tile_join` memory.** It reads every input archive wholly into memory. That is+> fine for the overlay layers (tens of MB each) but **not** for compositing against+> the full 1.5 GB published basemap — do that on a machine with the RAM for it, or+> merge the overlays first and composite once.++Install+ Install (Fedora/Amazon Linux, matching `run_generator.sh` conventions): ```bash@@ -562,9 +591,16 @@ R2 (no `*_zone_*.bin`). ## Dry-run result (this checkout) `tippecanoe`/`osmium`/`ogr2ogr` are not installed on the dev box, so the-tile-level build was not executed here. The **schema-mapping core** (the part-that defines the new `safety` + admin layers) was dry-run via the unit test and-passes:+OSM-derived tile builds were not executed here. The **schema-mapping core** (the+part that defines the new `safety` + admin layers) was dry-run via the unit test+and passes:++> **Since updated.** The `transit_stops` layer and the final merge no longer go+> through tippecanoe at all — they run entirely on `cargo` via+> [`tile_build`](tile_build/), and both *were* exercised on this dev box. That+> crate's PMTiles reader is additionally pinned against the real published+> `v5-ca.pmtiles`: its header parses to the known values and its gzipped root+> directory re-serializes byte-exactly. See `tile_build/tests/fixtures/README.md`. ``` $ python3 scripts/maps/test/test_normalize.py
scripts/maps/build_transit_stops_layer.ps1
diff --git a/scripts/maps/build_transit_stops_layer.ps1 b/scripts/maps/build_transit_stops_layer.ps1new file mode 100644index 0000000000..02e19bbe76--- /dev/null+++ b/scripts/maps/build_transit_stops_layer.ps1@@ -0,0 +1,81 @@+# build_transit_stops_layer.ps1 -- bake GTFS stops into a transit_stops .pmtiles.+#+# Native counterpart to build_transit_stops_layer.sh, and cargo-only: unlike the+# other layer scripts this needs neither osmium nor tippecanoe, so it runs on the+# Windows dev box. Two stages, both Rust:+#+# 1. gtfs_ingest --bin transit_stops -> transit_stops.geojsonseq+# 2. tile_build --bin tile_points -> transit_stops.pmtiles+#+# Input is the SAME unzipped GTFS directories build_ca_transit.ps1 already+# downloads for the offline routing pack, addressed through the same+# feeds.manifest -- so the stop pins on the map and the stops the on-device+# planner routes through come from one source of truth.+#+# Each feature carries `motis_id` (<Transitous prefix>_<gtfs stop_id>), `name` and+# `route_type`. The motis_id is what lets a tapped pin fetch live departures from+# MOTIS /stoptimes without the removed /api/v1/map/stops lookup.+#+# Usage:+# .\build_transit_stops_layer.ps1 -Manifest ca_transit_work\feeds.manifest+# .\build_transit_stops_layer.ps1 -Manifest m.txt -Out transit_stops.pmtiles `+# -MinZoom 11 -MaxZoom 14+#+# Requires: cargo (https://rustup.rs). Nothing else.+[CmdletBinding()]+param(+ # feeds.manifest written by build_ca_transit.ps1: one+ # `name=dir[=motis_prefix]` line per feed.+ [Parameter(Mandatory = $true)][string]$Manifest,+ [string]$Out = "transit_stops.pmtiles",+ # Scratch dir for the intermediate geojsonseq.+ [string]$Work = "transit_stops_work",+ # 11 because stops are denser than ma_pois (12) but far sparser than roads.+ [int]$MinZoom = 11,+ [int]$MaxZoom = 14,+ # Keep the intermediate geojsonseq for inspection.+ [switch]$KeepWork+)+$ErrorActionPreference = "Stop"++if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) {+ throw "cargo not found. Install Rust from https://rustup.rs"+}+if (-not (Test-Path $Manifest)) {+ throw "manifest not found: $Manifest"+}+if ($MinZoom -gt $MaxZoom) {+ throw "-MinZoom $MinZoom is above -MaxZoom $MaxZoom"+}++New-Item -ItemType Directory -Force -Path $Work | Out-Null+$Work = (Resolve-Path $Work).Path+$Manifest = (Resolve-Path $Manifest).Path+$geojson = Join-Path $Work "transit_stops.geojsonseq"++$gtfsIngest = Join-Path $PSScriptRoot "gtfs_ingest\Cargo.toml"+$tileBuild = Join-Path $PSScriptRoot "tile_build\Cargo.toml"++Write-Host "[transit_stops] 1/2 GTFS -> geojsonseq"+cargo run --release --quiet --manifest-path $gtfsIngest --bin transit_stops -- `+ --geojson $geojson --manifest $Manifest+if ($LASTEXITCODE -ne 0) { throw "transit_stops (gtfs_ingest) failed with exit code $LASTEXITCODE" }++$features = (Get-Content $geojson | Measure-Object -Line).Lines+Write-Host "[transit_stops] $features stop feature(s)"+if ($features -eq 0) { throw "no stop features produced - check the manifest" }++Write-Host "[transit_stops] 2/2 geojsonseq -> $Out (z$MinZoom-$MaxZoom)"+cargo run --release --quiet --manifest-path $tileBuild --bin tile_points -- `+ --geojson $geojson --out $Out --layer transit_stops `+ --minzoom $MinZoom --maxzoom $MaxZoom+if ($LASTEXITCODE -ne 0) { throw "tile_points failed with exit code $LASTEXITCODE" }++if (-not $KeepWork) { Remove-Item $geojson -Force -ErrorAction SilentlyContinue }++$size = [math]::Round((Get-Item $Out).Length / 1MB, 2)+Write-Host ""+Write-Host "[transit_stops] done: $Out ($size MB), layer 'transit_stops'"+Write-Host "Merge it into the basemap with:"+Write-Host " cargo run --release --manifest-path scripts/maps/tile_build/Cargo.toml \"+Write-Host " --bin tile_join -- --out v5-ca.pmtiles base.pmtiles $Out"
scripts/maps/build_transit_stops_layer.sh
diff --git a/scripts/maps/build_transit_stops_layer.sh b/scripts/maps/build_transit_stops_layer.shnew file mode 100644index 0000000000..21094acf44--- /dev/null+++ b/scripts/maps/build_transit_stops_layer.sh@@ -0,0 +1,81 @@+#!/bin/bash+set -euo pipefail+# build_transit_stops_layer.sh - bake GTFS stops into a transit_stops .pmtiles.+#+# Cargo-only: unlike the other layer scripts this needs neither osmium nor+# tippecanoe, so it also runs on the Windows dev box via its .ps1 twin. Two+# stages, both Rust:+#+# 1. gtfs_ingest --bin transit_stops -> transit_stops.geojsonseq+# 2. tile_build --bin tile_points -> transit_stops.pmtiles+#+# Input is the SAME unzipped GTFS directories the offline routing pack is built+# from, addressed through the same feeds.manifest - so the stop pins on the map and+# the stops the on-device planner routes through come from one source of truth.+#+# Each feature carries `motis_id` (<Transitous prefix>_<gtfs stop_id>), `name` and+# `route_type`. The motis_id is what lets a tapped pin fetch live departures from+# MOTIS /stoptimes without the removed /api/v1/map/stops lookup. A feed whose+# Transitous source name the build does not know contributes stops with no+# motis_id; they still open an offline departure board, just no live delays.+#+# Usage:+# ./build_transit_stops_layer.sh --manifest world_transit_work/feeds.manifest+# ./build_transit_stops_layer.sh --manifest m.txt --out transit_stops.pmtiles \+# --minzoom 11 --maxzoom 14+#+# Options:+# --manifest FILE feeds.manifest: `name=dir[=motis_prefix]` per line (required)+# --out FILE output .pmtiles (default transit_stops.pmtiles)+# --workdir DIR scratch dir for the geojsonseq (default ./transit_stops_work)+# --minzoom N default 11 (stops are denser than ma_pois, sparser than roads)+# --maxzoom N default 14+# --keep-work keep the intermediate geojsonseq+#+# Tools required: cargo. Nothing else.+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+MANIFEST=""+OUT="transit_stops.pmtiles"+WORK="./transit_stops_work"+MINZOOM=11+MAXZOOM=14+KEEP_WORK=0+while [[ $# -gt 0 ]]; do+ case "$1" in+ --manifest) MANIFEST="$2"; shift 2 ;;+ --out) OUT="$2"; shift 2 ;;+ --workdir) WORK="$2"; shift 2 ;;+ --minzoom) MINZOOM="$2"; shift 2 ;;+ --maxzoom) MAXZOOM="$2"; shift 2 ;;+ --keep-work) KEEP_WORK=1; shift ;;+ -h|--help) sed -n '3,34p' "$0" | sed 's/^# \?//'; exit 0 ;;+ *) echo "Unknown arg: $1" >&2; exit 1 ;;+ esac+done++[[ -n "$MANIFEST" ]] || { echo "ERROR: --manifest required" >&2; exit 1; }+[[ -f "$MANIFEST" ]] || { echo "ERROR: manifest not found: $MANIFEST" >&2; exit 1; }+(( MINZOOM <= MAXZOOM )) || { echo "ERROR: --minzoom above --maxzoom" >&2; exit 1; }+command -v cargo >/dev/null || { echo "ERROR: cargo not installed (https://rustup.rs)" >&2; exit 1; }++mkdir -p "$WORK"+GEOJSON="$WORK/transit_stops.geojsonseq"++echo "[transit_stops] 1/2 GTFS -> geojsonseq"+cargo run --release --quiet --manifest-path "$HERE/gtfs_ingest/Cargo.toml" \+ --bin transit_stops -- --geojson "$GEOJSON" --manifest "$MANIFEST"++FEATURES="$(wc -l < "$GEOJSON" | tr -d ' ')"+echo "[transit_stops] $FEATURES stop feature(s)"+[[ "$FEATURES" -gt 0 ]] || { echo "ERROR: no stop features - check the manifest" >&2; exit 1; }++echo "[transit_stops] 2/2 geojsonseq -> $OUT (z$MINZOOM-$MAXZOOM)"+cargo run --release --quiet --manifest-path "$HERE/tile_build/Cargo.toml" \+ --bin tile_points -- --geojson "$GEOJSON" --out "$OUT" --layer transit_stops \+ --minzoom "$MINZOOM" --maxzoom "$MAXZOOM"++[[ "$KEEP_WORK" == "1" ]] || rm -f "$GEOJSON"++SIZE="$(stat -c%s "$OUT" 2>/dev/null || stat -f%z "$OUT" 2>/dev/null || echo '?')"+echo ""+echo "[transit_stops] done: $OUT (${SIZE} bytes), layer 'transit_stops'"
scripts/maps/build_v5_pmtiles.sh
diff --git a/scripts/maps/build_v5_pmtiles.sh b/scripts/maps/build_v5_pmtiles.shindex 597ef703b9..a3cb487e55 100644--- a/scripts/maps/build_v5_pmtiles.sh+++ b/scripts/maps/build_v5_pmtiles.sh@@ -8,6 +8,8 @@ set -euo pipefail # + maxspeed (posted speed limits for the P5b MaxspeedSource) # + transit_lines (OSM rail/subway/tram/… lines for the P22 highlight) # + ma_pois (OUR baked OSM POI layer: placement/name/type from OSM)+# + transit_stops (GTFS stop pins + their MOTIS ids, replacing the+# removed /api/v1/map/stops per-viewport fetch) # + admin_country / admin_region / admin_city (borders; replaces .fgb) # # The ma_pois step ALSO emits two compact side files next to --out@@ -25,7 +27,11 @@ set -euo pipefail # 4. build_transit_lines_layer.sh -> transit_lines.pmtiles (osmium/ogr2ogr + tippecanoe) # 5. build_pois_layer.sh -> ma_pois.pmtiles + poi_names.bin + poi_index.bin # 6. build_admin_layers.sh -> admin_*.pmtiles (Natural Earth/OSM + tippecanoe)-# 7. tile-join -> v5.pmtiles (merge all layers)+# 7. build_transit_stops_layer.sh -> transit_stops.pmtiles (GTFS, cargo-only)+# 8. tile_join -> v5.pmtiles (merge all layers)+#+# Steps 7 and 8 are cargo-only (scripts/maps/tile_build), so they need neither+# tippecanoe nor osmium. The rest still do -- see README.md. # # Full planet build is the user's infra step (large + long). Prove correctness # first with a metro dry run:@@ -41,6 +47,10 @@ set -euo pipefail # --out FILE final output (default v5.pmtiles) # --workdir DIR scratch dir for intermediates (default ./v5_work) # --bbox BOX metro bbox "minlon,minlat,maxlon,maxlat" (dry runs)+# --gtfs-manifest F feeds.manifest for the transit_stops layer (`name=dir[=motis_prefix]`+# per line, as build_ca_transit.ps1 writes). Without it the+# transit_stops step is skipped -- this layer takes GTFS dirs,+# not --pbf. # --base-mode M build|reuse (passed to build_base_layers.sh; default reuse) # --base-jar FILE protomaps basemap jar (base-mode build) # --base-area A planetiler area name/path (base-mode build; default planet)@@ -50,13 +60,16 @@ set -euo pipefail # --skip-transit-lines omit transit_lines layer # --skip-pois omit ma_pois layer + poi_names.bin/poi_index.bin side files # --skip-admin omit admin layers+# --skip-transit-stops omit transit_stops layer # --publish after a successful build, upload $OUT to R2 (publish_r2.sh; # reads R2_ENDPOINT/R2_ACCESS_KEY_ID/R2_SECRET_ACCESS_KEY from env) # --publish-key K remote object key when publishing (default: basename of --out) # --keep-work keep intermediates #-# Tools: tile-join + tippecanoe, osmium, ogr2ogr (GDAL), python3, and either-# java+planetiler (base build) or curl/pmtiles (base reuse). See README.md.+# Tools: osmium, ogr2ogr (GDAL), python3, tippecanoe (base/safety/maxspeed/+# transit_lines/pois/admin layers), and either java+planetiler (base build)+# or curl/pmtiles (base reuse). The transit_stops layer and the final merge+# need only cargo. See README.md. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PBF=""@@ -72,6 +85,8 @@ SKIP_MAXSPEED=0 SKIP_TRANSIT_LINES=0 SKIP_POIS=0 SKIP_ADMIN=0+SKIP_TRANSIT_STOPS=0+GTFS_MANIFEST="" KEEP_WORK=0 PUBLISH=0 PUBLISH_KEY=""@@ -91,15 +106,17 @@ while [[ $# -gt 0 ]]; do --skip-transit-lines) SKIP_TRANSIT_LINES=1; shift ;; --skip-pois) SKIP_POIS=1; shift ;; --skip-admin) SKIP_ADMIN=1; shift ;;+ --skip-transit-stops) SKIP_TRANSIT_STOPS=1; shift ;;+ --gtfs-manifest) GTFS_MANIFEST="$2"; shift 2 ;; --keep-work) KEEP_WORK=1; shift ;; --publish) PUBLISH=1; shift ;; --publish-key) PUBLISH_KEY="$2"; shift 2 ;;- -h|--help) sed -n '4,52p' "$0" | sed 's/^# \?//'; exit 0 ;;+ -h|--help) sed -n '4,72p' "$0" | sed 's/^# \?//'; exit 0 ;; *) echo "Unknown arg: $1" >&2; exit 1 ;; esac done -command -v tile-join >/dev/null || { echo "ERROR: tile-join (tippecanoe pkg) not installed" >&2; exit 1; }+command -v cargo >/dev/null || { echo "ERROR: cargo not installed (https://rustup.rs)" >&2; exit 1; } mkdir -p "$WORK" INPUTS=()@@ -167,18 +184,37 @@ if [[ "$SKIP_ADMIN" == "0" ]]; then done fi -# --- 7. merge ---+# --- 7. transit_stops (GTFS stop pins; cargo-only, takes GTFS dirs not --pbf) ---+if [[ "$SKIP_TRANSIT_STOPS" == "0" ]]; then+ if [[ -z "$GTFS_MANIFEST" ]]; then+ # Not an error: this layer's input is a set of GTFS feeds, which a plain+ # --pbf build has no way to produce. Say so rather than failing a build+ # that never asked for stops.+ echo "[v5] no --gtfs-manifest given; skipping transit_stops layer" >&2+ else+ "$HERE/build_transit_stops_layer.sh" \+ --manifest "$GTFS_MANIFEST" \+ --out "$WORK/transit_stops.pmtiles" \+ --workdir "$WORK/transit_stops"+ INPUTS+=("$WORK/transit_stops.pmtiles")+ fi+fi+# --- 8. merge --- echo "[v5] merging ${#INPUTS[@]} source(s) -> $OUT" printf ' + %s\n' "${INPUTS[@]}"-# --no-tile-size-limit: don't drop features when combining dense base + overlays.-tile-join --force --no-tile-size-limit -o "$OUT" "${INPUTS[@]}"+# Our own tile_join, not tippecanoe's: it unions each tile's layers and carries+# line/polygon geometry through untouched, and needs no tippecanoe install. Later+# inputs win a layer-name collision, so a rebuilt overlay replaces a stale copy.+cargo run --release --quiet --manifest-path "$HERE/tile_build/Cargo.toml" \+ --bin tile_join -- --out "$OUT" "${INPUTS[@]}" SIZE="$(stat -c%s "$OUT" 2>/dev/null || stat -f%z "$OUT" 2>/dev/null || echo '?')" echo "[v5] done: $OUT (${SIZE} bytes)" echo "" echo "Layers now in $OUT:" echo " base : earth landcover landuse water roads buildings boundaries pois places"-echo " new : safety maxspeed transit_lines ma_pois admin_country admin_region admin_city"+echo " new : safety maxspeed transit_lines ma_pois transit_stops"+echo " admin_country admin_region admin_city" echo "" if [[ "$SKIP_POIS" == "0" ]]; then echo "POI side files (emitted beside $OUT for the app to mmap):"