maps: build overlay-only archives by default, and publish intermediate.bin
- Commit
52f1d1bedb47e00ff17e17e0238a138f30a994b4- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-23 21:41 UTC (3 months ago)
- Parents
237713c
Diff
scripts/maps/build_all.ps1
diff --git a/scripts/maps/build_all.ps1 b/scripts/maps/build_all.ps1index 0bfda692d6..77ea59146b 100644--- a/scripts/maps/build_all.ps1+++ b/scripts/maps/build_all.ps1@@ -6,17 +6,21 @@ # # WHAT THIS TWIN CAN AND CANNOT DO. Only `admin_country` and `admin_region` cannot # be built here, and never will be from OSM: they come from Natural Earth-# shapefiles. Everything else is cargo-only, so the tiles stage composites safety,-# maxspeed, transit_lines, admin_city, ma_pois and transit_stops on top of a base-# archive you point it at with -BaseArchive. It says so loudly rather than quietly-# emitting an archive with layers missing. For a complete v5, run build_all.sh under-# WSL. Stages graph, pois and transit are complete.+# shapefiles. Everything else is cargo-only, so the tiles stage builds safety,+# maxspeed, transit_lines, admin_city, ma_pois and transit_stops and merges them+# into an OVERLAY-ONLY archive -- no base. The app mounts that alongside the+# published base archive, which is also the only shape that fits in tile_join's+# memory at planet scale (see build_v5_pmtiles.sh --no-base). It says so loudly+# rather than quietly emitting an archive with layers missing. For the two+# Natural Earth admin levels, run build_all.sh under WSL. Stages graph, pois and+# transit are complete. #-# THE 9 ARTIFACTS, all landing in -OutDir:+# THE 11 ARTIFACTS, all landing in -OutDir: # graph metadata.bin road_names.bin nodes.bin edges.bin lanes.bin-# pois poi_names.bin poi_index.bin+# intermediate.bin+# pois poi_names.bin poi_index.bin poi_attrs.bin # transit world.transit-# tiles v5.pmtiles (name from -Out)+# tiles v5-overlay.pmtiles (name from -Out) # plus manifest.txt with each one's size and SHA-256, byte-comparable with the # manifest.txt build_all.sh writes. #@@ -48,9 +52,6 @@ param( [string] $OutDir = "build_all_out", [string] $Out = "", [string] $Work = "",- # Base tile archive to composite onto: a local .pmtiles, or a URL to fetch.- # Required by the tiles stage on Windows.- [string] $BaseArchive = "", # Stage control [switch] $SkipGraph,@@ -74,6 +75,13 @@ param( [switch] $Publish, [switch] $PublishDryRun, + # Graph build-time memory, forwarded to road_graph. None change the on-disk+ # contract, and -Rounds does not change the output at all. Required at planet+ # scale -- see osm_ingest/README.md 'Build-time memory'.+ [switch] $WithinWayChains,+ [int] $Rounds = 0,+ [string] $SpillDir = "",+ [int] $Jobs = 6 ) @@ -141,7 +149,7 @@ $OutDir = (Resolve-Path $OutDir).Path if (-not $Work) { $Work = Join-Path $OutDir "work" } New-Item -ItemType Directory -Force -Path $Work | Out-Null $Work = (Resolve-Path $Work).Path-if (-not $Out) { $Out = Join-Path $OutDir "v5.pmtiles" }+if (-not $Out) { $Out = Join-Path $OutDir "v5-overlay.pmtiles" } $Stamps = Join-Path $Work "stamps" New-Item -ItemType Directory -Force -Path $Stamps | Out-Null @@ -179,23 +187,27 @@ $AdminCityTile = Join-Path $Work "admin_city.pmtiles" $StopsTile = Join-Path $Work "transit_stops.pmtiles" $TransitWork = Join-Path $Work "transit" -# --- stage: graph (5 files) ---+# --- stage: graph (6 files) --- if (Test-Stage "graph") { if (Test-Stamp "graph") { Write-Host "=== graph: stamp present, skipping (-Force to redo) ===" } else { Assert-Pbf "Graph"- Write-Host "=== graph -> $OutDir (metadata/road_names/nodes/edges/lanes.bin) ==="+ Write-Host "=== graph -> $OutDir (metadata/road_names/nodes/edges/lanes/intermediate.bin) ===" # Gated deliberately: road_graph truncates its outputs as it writes, so a # failure here must not fall through to the manifest or the publish.- Invoke-Step "cargo" @("run", "--release", "--quiet", "--manifest-path", $OsmManifest,- "--bin", "road_graph", "--", $Pbf, "--out", $OutDir)+ $graphArgs = @($Pbf, "--out", $OutDir)+ if ($WithinWayChains) { $graphArgs += "--within-way-chains" }+ if ($Rounds -gt 0) { $graphArgs += @("--rounds", "$Rounds") }+ if ($SpillDir) { $graphArgs += @("--spill-dir", $SpillDir) }+ Invoke-Step "cargo" (@("run", "--release", "--quiet", "--manifest-path", $OsmManifest,+ "--bin", "road_graph", "--") + $graphArgs) Set-Stamp "graph" } } -# --- stage: pois (2 side files + the ma_pois tile layer) ----# One poi_extract pass produces the geojson the tiler reads AND the two side+# --- stage: pois (3 side files + the ma_pois tile layer) ---+# One poi_extract pass produces the geojson the tiler reads AND the three side # files, so they cannot disagree. The side files go straight to -OutDir. if (Test-Stage "pois") { if (Test-Stamp "pois") {@@ -203,12 +215,13 @@ if (Test-Stage "pois") { } else { Assert-Pbf "Pois" $poiGeo = Join-Path $Work "ma_pois.geojsonseq"- Write-Host "=== pois -> $OutDir\poi_names.bin + poi_index.bin ==="+ Write-Host "=== pois -> $OutDir\poi_names.bin + poi_index.bin + poi_attrs.bin ===" Invoke-Step "cargo" @("run", "--release", "--quiet", "--manifest-path", $OsmManifest, "--bin", "poi_extract", "--", $Pbf, "--geojson", $poiGeo, "--names", (Join-Path $OutDir "poi_names.bin"),- "--index", (Join-Path $OutDir "poi_index.bin"))+ "--index", (Join-Path $OutDir "poi_index.bin"),+ "--attrs", (Join-Path $OutDir "poi_attrs.bin")) Write-Host "=== pois -> $PoisTile (z12-16, tile_points) ===" Invoke-Step "cargo" @("run", "--release", "--quiet", "--manifest-path", $TileManifest, "--bin", "tile_points", "--",@@ -253,42 +266,11 @@ if (-not $script:EffectiveGtfsManifest) { elseif ($GtfsManifest) { $script:EffectiveGtfsManifest = $GtfsManifest } } -# --- stage: tiles (cargo-only layers onto a base archive) ---+# --- stage: tiles (the cargo-only overlay layers, merged without a base) --- if (Test-Stage "tiles") { if (Test-Stamp "tiles") { Write-Host "=== tiles: stamp present, skipping (-Force to redo) ===" } else {- if (-not $BaseArchive) {- throw @"-the tiles stage needs -BaseArchive on Windows.--Only admin_country and admin_region cannot be built here -- they come from Natural-Earth shapefiles, not OSM -- and the Planetiler base build needs Java. So this twin-composites the cargo-only layers onto an existing archive rather than building one:-- .\build_all.ps1 ... -BaseArchive https://data.vayunmathur.com/v5.pmtiles--For a complete v5 with every layer, run build_all.sh under WSL.-"@- }-- $base = $BaseArchive- if ($BaseArchive -match '^https?://') {- $base = Join-Path $Work "base.pmtiles"- if (Test-Path $base) {- Write-Host "[all] reusing cached base $base"- } else {- Write-Host "[all] fetching $BaseArchive (this can be very large)"- if (-not $DryRun) {- $partial = "$base.partial"- Invoke-WebRequest -Uri $BaseArchive -OutFile $partial -MaximumRedirection 5- Move-Item -Force $partial $base- }- }- } elseif (-not $DryRun -and -not (Test-Path $base)) {- throw "-BaseArchive not found: $base"- }- # safety, maxspeed, transit_lines and admin_city are all cargo-only: # osm_extract reads the PBF directly -- assembling boundary rings itself for # admin_city -- and the tile_build tilers tile it. No osmium, tippecanoe,@@ -333,8 +315,10 @@ For a complete v5 with every layer, run build_all.sh under WSL. Write-Warning "no GTFS manifest available; skipping the transit_stops layer" } - # Later inputs win a layer-name collision, so the overlays go after base.- $inputs = @($base)+ # Later inputs win a layer-name collision, so a rebuilt overlay replaces a+ # stale copy. No base is joined: the overlay names are disjoint from the+ # base schema's, so the app mounts the two archives side by side instead.+ $inputs = @() foreach ($t in @($SafetyTile, $MaxspeedTile, $TransitLinesTile, $AdminCityTile, $PoisTile, $StopsTile)) { if ((Test-Path $t) -or $DryRun) { $inputs += $t } }@@ -342,16 +326,18 @@ For a complete v5 with every layer, run build_all.sh under WSL. $inputs | ForEach-Object { Write-Host " + $_" } Invoke-Step "cargo" (@("run", "--release", "--quiet", "--manifest-path", $TileManifest, "--bin", "tile_join", "--", "--out", $Out) + $inputs)- Write-Warning "admin_country and admin_region are NOT in $Out (they come from Natural Earth shapefiles, not OSM -- build under WSL for a complete archive)"+ Write-Warning "admin_country and admin_region are NOT in $Out (they come from Natural Earth shapefiles, not OSM -- build under WSL for those two)" Set-Stamp "tiles" } } -# --- manifest.txt: name, size, SHA-256 for all 9 ---+# --- manifest.txt: name, size, SHA-256 for all 11 --- # Same column layout as build_all.sh so the two are diffable, and lowercase hex # so the digests compare directly. $artifacts = @("metadata.bin", "road_names.bin", "nodes.bin", "edges.bin", "lanes.bin",- "poi_names.bin", "poi_index.bin", "world.transit", (Split-Path $Out -Leaf))+ "intermediate.bin",+ "poi_names.bin", "poi_index.bin", "poi_attrs.bin", "world.transit",+ (Split-Path $Out -Leaf)) function Get-ArtifactPath { param([string] $Name)@@ -361,7 +347,7 @@ function Get-ArtifactPath { if ($DryRun) { Write-Host ""- Write-Host "[dry-run] would write $OutDir\manifest.txt over these 9 artifacts:"+ Write-Host "[dry-run] would write $OutDir\manifest.txt over these $($artifacts.Count) artifacts:" $artifacts | ForEach-Object { Write-Host " $_" } } else { $manifestFile = Join-Path $OutDir "manifest.txt"
scripts/maps/build_all.sh
diff --git a/scripts/maps/build_all.sh b/scripts/maps/build_all.shindex 3f59ad4062..7590f6fa17 100644--- a/scripts/maps/build_all.sh+++ b/scripts/maps/build_all.sh@@ -9,13 +9,14 @@ set -euo pipefail # and closes the gap where poi_names.bin/poi_index.bin had to be hand-copied # into the graph directory before the upload would pick them up. #-# THE 9 ARTIFACTS, all landing in --out-dir:+# THE 11 ARTIFACTS, all landing in --out-dir: # graph metadata.bin road_names.bin nodes.bin edges.bin lanes.bin-# pois poi_names.bin poi_index.bin+# intermediate.bin+# pois poi_names.bin poi_index.bin poi_attrs.bin # transit world.transit-# tiles v5.pmtiles (name from --out)-# plus manifest.txt listing every one with its size and SHA-256. The first eight-# are what MainActivity's InitialDownloadChecker fetches; the ninth is streamed.+# tiles v5-overlay.pmtiles (name from --out)+# plus manifest.txt listing every one with its size and SHA-256. The first ten+# are what MainActivity's InitialDownloadChecker fetches; the eleventh is streamed. # # Stages run in order graph -> pois -> transit -> tiles. Each writes a stamp file # under <work>/stamps on success, so a re-run skips what already finished;@@ -38,26 +39,35 @@ set -euo pipefail # ('-latest.osm.pbf' is appended). Cached in <work>. # --gtfs-manifest F feeds.manifest ('name=dir[=motis_prefix]' per line) for # world.transit and the transit_stops tile layer-# --gtfs-region GLOB build that manifest from the Transitous registry-# instead, e.g. 'us-ca' (see build_world_transit.sh)+# --gtfs-region GLOB build that manifest from Transitous' published gtfs+# directory instead, e.g. 'us-ca' (see build_world_transit.sh) # --bbox BOX "minlon,minlat,maxlon,maxlat". Clipped ONCE up front and # reused by every stage, so the graph honours it too. # Needs osmium. # Outputs-# --out-dir DIR where the 9 artifacts land (default ./build_all_out)-# --out FILE the tile archive (default <out-dir>/v5.pmtiles). Its-# basename becomes the published key, so match whatever-# style.json points at.+# --out-dir DIR where the 11 artifacts land (default ./build_all_out)+# --out FILE the tile archive (default <out-dir>/v5-overlay.pmtiles,+# or <out-dir>/v5.pmtiles with --with-base). Its basename+# becomes the published key, so match whatever the app+# points at. # --work DIR scratch + stamps (default <out-dir>/work)+# --with-base merge the Protomaps base INTO the tile archive, instead+# of the default overlay-only output. Only sane for a+# metro-sized extract: tile_join holds every input in+# memory, and a planet base is ~127 GB of a 137 GB result.+# The app streams the base from its own published archive+# (MapTileCache.BASEMAP_PMTILES_URL), so the overlay-only+# default is the shippable shape. # --base-archive URL published archive to reuse for the base layers-# (default: build_base_layers.sh's own)+# (--with-base only; default build_base_layers.sh's own) # --admin-reuse SRC carry admin_country and admin_region forward from an # existing archive (a local .pmtiles or a URL) instead of # rebuilding them from Natural Earth. Those two are the only # layers that still need ogr2ogr and python3, so with this # and --base-mode reuse the whole tile build is cargo-only # apart from curl.-# --base-mode M build|reuse (default reuse; build needs java 21 + --base-jar)+# --base-mode M build|reuse (--with-base only; default reuse; build needs+# java 21 + --base-jar) # --base-jar FILE protomaps basemap jar (--base-mode build only) # --base-area A planetiler area (--base-mode build only; default planet) # Stage control@@ -65,6 +75,21 @@ set -euo pipefail # --only STAGE run exactly one of graph|pois|transit|tiles # --force ignore stamps and redo every requested stage # --dry-run print what each stage would run; change nothing+# Graph build-time memory (forwarded to road_graph; none change the on-disk+# contract, and --rounds does not change the output at all)+# --within-way-chains confine chains to one OSM way, which removes the segment+# array and the incidence index entirely. REQUIRED at+# planet scale: without it the reference path peaked at+# 61.85 GiB on Europe alone, and a planet is 2.65x that.+# Costs ~9% more nodes and ~7% more edges.+# --rounds N write the pack in N source-partitioned rounds instead of+# one, so the write buffer is edges/N x 48 B rather than+# all of it. Planet wants 3.+# --spill-dir DIR put chains.pts somewhere other than --out-dir. It is the+# only file the build reads RANDOMLY, so it wants cheap+# seeks -- keep it off a network or /mnt/c mount even when+# the output lives there.+# See osm_ingest/README.md 'Build-time memory'. # Engines, per layer, so a ported layer rolls back with a flag # --engine-base E rust|legacy (default legacy) # --engine-safety E rust|legacy (default rust: osm_extract + tile_points,@@ -103,6 +128,10 @@ ADMIN_REUSE="" BASE_MODE="reuse" BASE_JAR="" BASE_AREA="planet"+WITH_BASE=0+WITHIN_WAY_CHAINS=0+ROUNDS=""+SPILL_DIR="" SKIP_GRAPH=0 SKIP_POIS=0 SKIP_TRANSIT=0@@ -131,6 +160,10 @@ while [[ $# -gt 0 ]]; do --out) OUT="$2"; shift 2 ;; --work) WORK="$2"; shift 2 ;; --base-archive) BASE_ARCHIVE="$2"; shift 2 ;;+ --with-base) WITH_BASE=1; shift ;;+ --within-way-chains) WITHIN_WAY_CHAINS=1; shift ;;+ --rounds) ROUNDS="$2"; shift 2 ;;+ --spill-dir) SPILL_DIR="$2"; shift 2 ;; --admin-reuse) ADMIN_REUSE="$2"; shift 2 ;; --base-mode) BASE_MODE="$2"; shift 2 ;; --base-jar) BASE_JAR="$2"; shift 2 ;;@@ -151,7 +184,7 @@ while [[ $# -gt 0 ]]; do --engine-admin) ENGINE_ADMIN="$2"; shift 2 ;; --engine-admin-city) ENGINE_ADMIN_CITY="$2"; shift 2 ;; --engine-pois) ENGINE_POIS="$2"; shift 2 ;;- -h|--help) sed -n '4,89p' "$0" | sed 's/^# \?//'; exit 0 ;;+ -h|--help) sed -n '4,114p' "$0" | sed 's/^# \?//'; exit 0 ;; *) echo "Unknown arg: $1" >&2; exit 1 ;; esac done@@ -189,7 +222,13 @@ OUT_DIR="$(cd "$OUT_DIR" && pwd)" WORK="${WORK:-$OUT_DIR/work}" mkdir -p "$WORK" WORK="$(cd "$WORK" && pwd)"-OUT="${OUT:-$OUT_DIR/v5.pmtiles}"+# Named after what it contains. The published v5.pmtiles has a base baked in, so+# an overlay-only archive must not silently reuse that name.+if [[ "$WITH_BASE" == "1" ]]; then+ OUT="${OUT:-$OUT_DIR/v5.pmtiles}"+else+ OUT="${OUT:-$OUT_DIR/v5-overlay.pmtiles}"+fi STAMPS="$WORK/stamps" mkdir -p "$STAMPS" @@ -262,23 +301,27 @@ POIS_TILE="$WORK/ma_pois.pmtiles" TRANSIT_WORK="$WORK/transit" EFFECTIVE_GTFS_MANIFEST="$TRANSIT_WORK/feeds.manifest" -# --- stage: graph (5 files) ---+# --- stage: graph (6 files) --- if want_stage graph; then if stage_done graph; then echo "=== graph: stamp present, skipping (--force to redo) ===" else require_pbf graph- echo "=== graph -> $OUT_DIR (metadata/road_names/nodes/edges/lanes.bin) ==="+ echo "=== graph -> $OUT_DIR (metadata/road_names/nodes/edges/lanes/intermediate.bin) ==="+ GRAPH_ARGS=("$PBF" --out "$OUT_DIR")+ [[ "$WITHIN_WAY_CHAINS" == "1" ]] && GRAPH_ARGS+=(--within-way-chains)+ [[ -n "$ROUNDS" ]] && GRAPH_ARGS+=(--rounds "$ROUNDS")+ [[ -n "$SPILL_DIR" ]] && GRAPH_ARGS+=(--spill-dir "$SPILL_DIR") # Gated deliberately: road_graph truncates its outputs as it writes, so a # failure here must not fall through to the manifest or the publish. run cargo run --release --quiet --manifest-path "$HERE/osm_ingest/Cargo.toml" \- --bin road_graph -- "$PBF" --out "$OUT_DIR"+ --bin road_graph -- "${GRAPH_ARGS[@]}" mark_done graph fi fi -# --- stage: pois (2 side files + the ma_pois tile layer) ----# One poi_extract pass produces the geojson the tiler reads AND the two side+# --- stage: pois (3 side files + the ma_pois tile layer) ---+# One poi_extract pass produces the geojson the tiler reads AND the three side # files, so they cannot disagree. The side files go straight to --out-dir; that # is the manual copy step run_generator.sh used to ask for. if want_stage pois; then@@ -286,12 +329,13 @@ if want_stage pois; then echo "=== pois: stamp present, skipping (--force to redo) ===" else require_pbf pois- echo "=== pois -> $OUT_DIR/poi_{names,index}.bin + $POIS_TILE ==="+ echo "=== pois -> $OUT_DIR/poi_{names,index,attrs}.bin + $POIS_TILE ===" run "$HERE/build_pois_layer.sh" \ --pbf "$PBF" \ --out "$POIS_TILE" \ --names-out "$OUT_DIR/poi_names.bin" \ --index-out "$OUT_DIR/poi_index.bin" \+ --attrs-out "$OUT_DIR/poi_attrs.bin" \ --engine "$ENGINE_POIS" mark_done pois fi@@ -321,30 +365,38 @@ if want_stage transit; then fi fi -# --- stage: tiles (v5.pmtiles) ---+# --- stage: tiles ($OUT) --- if want_stage tiles; then if stage_done tiles; then echo "=== tiles: stamp present, skipping (--force to redo) ===" else require_pbf tiles echo "=== tiles -> $OUT ==="- V5_ARGS=(--pbf "$PBF" --out "$OUT" --workdir "$WORK/v5" --base-mode "$BASE_MODE")+ V5_ARGS=(--pbf "$PBF" --out "$OUT" --workdir "$WORK/v5")+ # Overlay-only unless asked otherwise. The base options only mean anything+ # when there IS a base, and build_v5_pmtiles.sh rejects them alongside+ # --no-base rather than ignoring them, so they are passed only here.+ if [[ "$WITH_BASE" == "1" ]]; then+ V5_ARGS+=(--base-mode "$BASE_MODE")+ [[ -n "$BASE_ARCHIVE" ]] && V5_ARGS+=(--base-source "$BASE_ARCHIVE")+ [[ "$BASE_MODE" == "build" ]] && V5_ARGS+=(--base-jar "$BASE_JAR" --base-area "$BASE_AREA")+ V5_ARGS+=(--engine-base "$ENGINE_BASE")+ else+ V5_ARGS+=(--no-base)+ fi # The pois stage already built the layer and the side files; --skip-pois # plus --extra-layer folds that archive into the merge without a second # poi_extract pass. if [[ -f "$POIS_TILE" || "$DRY_RUN" == "1" ]]; then V5_ARGS+=(--skip-pois --extra-layer "$POIS_TILE") fi- [[ -n "$BASE_ARCHIVE" ]] && V5_ARGS+=(--base-source "$BASE_ARCHIVE") [[ -n "$ADMIN_REUSE" ]] && V5_ARGS+=(--admin-reuse "$ADMIN_REUSE")- [[ "$BASE_MODE" == "build" ]] && V5_ARGS+=(--base-jar "$BASE_JAR" --base-area "$BASE_AREA") if [[ -f "$EFFECTIVE_GTFS_MANIFEST" ]]; then V5_ARGS+=(--gtfs-manifest "$EFFECTIVE_GTFS_MANIFEST") elif [[ -n "$GTFS_MANIFEST" ]]; then V5_ARGS+=(--gtfs-manifest "$GTFS_MANIFEST") fi- V5_ARGS+=(--engine-base "$ENGINE_BASE"- --engine-safety "$ENGINE_SAFETY"+ V5_ARGS+=(--engine-safety "$ENGINE_SAFETY" --engine-maxspeed "$ENGINE_MAXSPEED" --engine-transit-lines "$ENGINE_TRANSIT_LINES" --engine-admin "$ENGINE_ADMIN"@@ -356,8 +408,8 @@ if want_stage tiles; then fi # --- manifest.txt: name, size, SHA-256 for all 9 ----ARTIFACTS=(metadata.bin road_names.bin nodes.bin edges.bin lanes.bin- poi_names.bin poi_index.bin world.transit)+ARTIFACTS=(metadata.bin road_names.bin nodes.bin edges.bin lanes.bin intermediate.bin+ poi_names.bin poi_index.bin poi_attrs.bin world.transit) sha256_of() { if command -v sha256sum >/dev/null; then@@ -376,7 +428,7 @@ artifact_path() { if [[ "$DRY_RUN" == "1" ]]; then echo ""- echo "[dry-run] would write $OUT_DIR/manifest.txt over these 9 artifacts:"+ echo "[dry-run] would write $OUT_DIR/manifest.txt over these $(( ${#ARTIFACTS[@]} + 1 )) artifacts:" printf ' %s\n' "${ARTIFACTS[@]}" "$(basename "$OUT")" else MANIFEST_FILE="$OUT_DIR/manifest.txt"@@ -394,7 +446,7 @@ else fi done echo ""- echo "=== $OUT_DIR/manifest.txt (${#PRESENT[@]}/9 present) ==="+ echo "=== $OUT_DIR/manifest.txt (${#PRESENT[@]}/$(( ${#ARTIFACTS[@]} + 1 )) present) ===" cat "$MANIFEST_FILE" if [[ ${#MISSING[@]} -gt 0 ]]; then # Not fatal: --skip-*/--only runs are expected to leave holes. Naming them
scripts/maps/build_pois_layer.sh
diff --git a/scripts/maps/build_pois_layer.sh b/scripts/maps/build_pois_layer.shindex 024d5c692e..b9298f44f6 100644--- a/scripts/maps/build_pois_layer.sh+++ b/scripts/maps/build_pois_layer.sh@@ -8,8 +8,8 @@ set -euo pipefail # when the user taps a POI. This deliberately does NOT reuse the Protomaps base # `pois` layer (the app suppresses that one). #-# Produces three mutually-consistent outputs from a single `poi_extract` pass-# (same POI set, same coordinates):+# Produces four mutually-consistent outputs from a single `poi_extract` pass+# (same POI set, same order, same coordinates): # # * <out>.pmtiles source-layer `ma_pois` (Point) — attrs: name, type, osm_id # * poi_names.bin deduped NUL-terminated UTF-8 name table (each unique name@@ -17,10 +17,12 @@ set -euo pipefail # * poi_index.bin flat 14-byte records (little-endian): # int32 lat_e7, int32 lon_e7, uint32 name_off, uint16 type # sorted by Morton (Z-order) key of (lat,lon)+# * poi_attrs.bin attribute sidecar keyed by poi_index.bin RECORD ORDINAL:+# opening_hours, phone, website, addr:*, cuisine, wheelchair #-# See scripts/maps/osm_ingest (src/poi_build.rs) for the full TYPE MAP + the exact-# on-disk layouts, and the README (`ma_pois` schema + file formats) for the-# app-side contract.+# See scripts/maps/osm_ingest (src/poi_build.rs, src/poi_attrs.rs) for the full+# TYPE MAP + the exact on-disk layouts, and the README (`ma_pois` schema + file+# formats) for the app-side contract. # # Usage: # ./build_pois_layer.sh --pbf planet.osm.pbf --out ma_pois.pmtiles@@ -32,6 +34,8 @@ set -euo pipefail # --out FILE Output .pmtiles (default: ma_pois.pmtiles) # --names-out FILE Output name table (default: poi_names.bin) # --index-out FILE Output record index (default: poi_index.bin)+# --attrs-out FILE Output attribute sidecar (default: poi_attrs.bin beside+# --index-out) # --bbox BOX Optional "minlon,minlat,maxlon,maxlat" metro extract (dry runs) # --minzoom N tiler minzoom (default 12) # --maxzoom N tiler maxzoom (default 16)@@ -42,7 +46,7 @@ set -euo pipefail # --keep-tmp Don't delete intermediate files # # Tools required: cargo. Additionally osmium (osmium-tool) only for --bbox, and-# tippecanoe only for --engine legacy. The two side files can also be built on+# tippecanoe only for --engine legacy. The three side files can also be built on # their own, on any platform, with: # cargo run --release --manifest-path osm_ingest/Cargo.toml --bin poi_extract -- ... @@ -51,6 +55,7 @@ PBF="" OUT="ma_pois.pmtiles" NAMES_OUT="poi_names.bin" INDEX_OUT="poi_index.bin"+ATTRS_OUT="" BBOX="" MINZOOM=12 MAXZOOM=16@@ -63,16 +68,21 @@ while [[ $# -gt 0 ]]; do --out) OUT="$2"; shift 2 ;; --names-out) NAMES_OUT="$2"; shift 2 ;; --index-out) INDEX_OUT="$2"; shift 2 ;;+ --attrs-out) ATTRS_OUT="$2"; shift 2 ;; --bbox) BBOX="$2"; shift 2 ;; --minzoom) MINZOOM="$2"; shift 2 ;; --maxzoom) MAXZOOM="$2"; shift 2 ;; --engine) ENGINE="$2"; shift 2 ;; --keep-tmp) KEEP_TMP=1; shift ;;- -h|--help) sed -n '4,47p' "$0" | sed 's/^# \?//'; exit 0 ;;+ -h|--help) sed -n '4,51p' "$0" | sed 's/^# \?//'; exit 0 ;; *) echo "Unknown arg: $1" >&2; exit 1 ;; esac done +# Beside the index by default, because that is where the app looks for it and+# because the two are only meaningful as a pair.+[[ -n "$ATTRS_OUT" ]] || ATTRS_OUT="$(dirname "$INDEX_OUT")/poi_attrs.bin"+ [[ -n "$PBF" ]] || { echo "ERROR: --pbf required" >&2; exit 1; } [[ -f "$PBF" ]] || { echo "ERROR: pbf not found: $PBF" >&2; exit 1; } case "$ENGINE" in@@ -100,12 +110,13 @@ if [[ -n "$BBOX" ]]; then SRC="$TMP/metro.osm.pbf" fi -echo "[ma_pois] extracting POIs -> geojsonseq + $NAMES_OUT + $INDEX_OUT"+echo "[ma_pois] extracting POIs -> geojsonseq + $NAMES_OUT + $INDEX_OUT + $ATTRS_OUT" cargo run --release --manifest-path "$HERE/osm_ingest/Cargo.toml" --bin poi_extract -- \ "$SRC" \ --geojson "$TMP/ma_pois.geojsonseq" \ --names "$NAMES_OUT" \- --index "$INDEX_OUT"+ --index "$INDEX_OUT" \+ --attrs "$ATTRS_OUT" FEATURES="$(wc -l < "$TMP/ma_pois.geojsonseq" | tr -d ' ')" echo "[ma_pois] $FEATURES POI feature(s)"
scripts/maps/build_v5_pmtiles.sh
diff --git a/scripts/maps/build_v5_pmtiles.sh b/scripts/maps/build_v5_pmtiles.shindex 5bf453977c..e95b5fa3be 100644--- a/scripts/maps/build_v5_pmtiles.sh+++ b/scripts/maps/build_v5_pmtiles.sh@@ -3,6 +3,21 @@ set -euo pipefail # build_v5_pmtiles.sh — build the custom v5.pmtiles for the maps app. #+# Two shapes come out of this script, and which one you want is a choice about+# size, not about content:+#+# v5.pmtiles base + overlays in one archive. ~137 GB at planet scale,+# essentially all of it base — the overlays add under 3%.+# v5-overlay.pmtiles overlays only (--no-base). ~2-7 GB at planet scale, and+# the app pairs it with the published base archive.+#+# Prefer --no-base for anything planet-sized. tile_join holds every input in RAM+# (see tile_build/src/bin/tile_join.rs), which a 127 GB base makes impossible;+# never joining the base removes that limit rather than engineering around it.+# The layer namespaces are disjoint by construction — build_base_layers.sh fixes+# the base names and every overlay name is additive — so the split needs no+# renaming and the app can mount both archives side by side.+# # v5.pmtiles = Protomaps base schema (unchanged, style.json-compatible) # + safety (baked road-furniture: cameras/ALPR/stops/signals) # + maxspeed (posted speed limits for the P5b MaxspeedSource)@@ -12,9 +27,9 @@ set -euo pipefail # 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-# (poi_names.bin + poi_index.bin) that the app mmaps for POI lookup — see-# build_pois_layer.sh / osm_ingest / README for the exact formats.+# The ma_pois step ALSO emits three compact side files next to --out+# (poi_names.bin + poi_index.bin + poi_attrs.bin) that the app mmaps for POI+# lookup — see build_pois_layer.sh / osm_ingest / README for the exact formats. # # This single file REPLACES both: # * https://data.vayunmathur.com/v4.pmtiles (base tiles)@@ -22,13 +37,14 @@ set -euo pipefail # # Pipeline (each step is a standalone script in this dir): # 1. build_base_layers.sh -> base.pmtiles (planetiler OR reuse v4)+# (skipped by --no-base) # 2. build_safety_layer.sh -> safety.pmtiles (osmium + tippecanoe) # 3. build_maxspeed_layer.sh-> maxspeed.pmtiles (osmium + tippecanoe) # 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+# 5. build_pois_layer.sh -> ma_pois.pmtiles + poi_{names,index,attrs}.bin # 6. build_admin_layers.sh -> admin_*.pmtiles (Natural Earth/OSM + tippecanoe) # 7. build_transit_stops_layer.sh -> transit_stops.pmtiles (GTFS, cargo-only)-# 8. tile_join -> v5.pmtiles (merge all layers)+# 8. tile_join -> $OUT (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.@@ -38,13 +54,24 @@ set -euo pipefail # ./build_v5_pmtiles.sh --pbf norcal.osm.pbf --bbox -122.6,37.2,-121.7,37.9 \ # --base-mode reuse --out v5-sf.pmtiles #-# Planet build:+# Planet build (overlays only -- the shippable shape):+# ./build_v5_pmtiles.sh --pbf planet.osm.pbf --no-base --out v5-overlay.pmtiles+#+# Planet build including the base, if you have the RAM for a 137 GB join: # ./build_v5_pmtiles.sh --pbf planet.osm.pbf --base-mode build \ # --base-jar protomaps-basemap-HEAD-with-deps.jar --out v5.pmtiles # # Options: # --pbf FILE OSM extract for safety + city layers (required unless --skip-*)-# --out FILE final output (default v5.pmtiles)+# --out FILE final output (default v5.pmtiles, or v5-overlay.pmtiles+# under --no-base)+# --no-base build the overlays ONLY: skip step 1 and leave the base out+# of the merge entirely. The result is a standalone overlay+# archive the app mounts alongside the published base, and it+# is the only way a planet build fits in tile_join's memory.+# Mutually exclusive with --skip-base, and rejects the+# base-only options (--base-mode build, --base-jar,+# --base-source) rather than ignoring them. # --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]`@@ -77,7 +104,7 @@ set -euo pipefail # --skip-safety omit safety layer # --skip-maxspeed omit maxspeed layer # --skip-transit-lines omit transit_lines layer-# --skip-pois omit ma_pois layer + poi_names.bin/poi_index.bin side files+# --skip-pois omit ma_pois layer + poi_{names,index,attrs}.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;@@ -92,7 +119,7 @@ set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PBF=""-OUT="v5.pmtiles"+OUT="" WORK="./v5_work" BBOX="" BASE_MODE="reuse"@@ -108,6 +135,7 @@ ENGINE_ADMIN="legacy" ENGINE_ADMIN_CITY="rust" ADMIN_REUSE="" DRY_RUN=0+NO_BASE=0 SKIP_BASE=0 SKIP_SAFETY=0 SKIP_MAXSPEED=0@@ -139,6 +167,7 @@ while [[ $# -gt 0 ]]; do --engine-admin-city) ENGINE_ADMIN_CITY="$2"; shift 2 ;; --admin-reuse) ADMIN_REUSE="$2"; shift 2 ;; --dry-run) DRY_RUN=1; shift ;;+ --no-base) NO_BASE=1; shift ;; --skip-base) SKIP_BASE=1; shift ;; --skip-safety) SKIP_SAFETY=1; shift ;; --skip-maxspeed) SKIP_MAXSPEED=1; shift ;;@@ -150,11 +179,43 @@ while [[ $# -gt 0 ]]; do --keep-work) KEEP_WORK=1; shift ;; --publish) PUBLISH=1; shift ;; --publish-key) PUBLISH_KEY="$2"; shift 2 ;;- -h|--help) sed -n '4,91p' "$0" | sed 's/^# \?//'; exit 0 ;;+ -h|--help) sed -n '4,118p' "$0" | sed 's/^# \?//'; exit 0 ;; *) echo "Unknown arg: $1" >&2; exit 1 ;; esac done +# --no-base is about the merge, --skip-base is about step 1 reusing an existing+# intermediate: one omits the base, the other insists on having built it. Asking+# for both is a contradiction, and guessing which was meant is worse than+# stopping.+if [[ "$NO_BASE" == "1" && "$SKIP_BASE" == "1" ]]; then+ echo "ERROR: --no-base and --skip-base are contradictory (omit the base vs. reuse a built one)" >&2+ exit 1+fi++# These only describe how to produce a base. Under --no-base there is no base to+# produce, so accepting them would silently do nothing -- which reads as a+# successful build of the wrong thing.+if [[ "$NO_BASE" == "1" ]]; then+ for pair in "--base-jar:$BASE_JAR" "--base-source:$BASE_SOURCE"; do+ if [[ -n "${pair#*:}" ]]; then+ echo "ERROR: ${pair%%:*} makes no sense with --no-base (no base is built)" >&2+ exit 1+ fi+ done+ if [[ "$BASE_MODE" == "build" ]]; then+ echo "ERROR: --base-mode build makes no sense with --no-base (no base is built)" >&2+ exit 1+ fi+fi++# Named after what it contains. v5.pmtiles is published with the base baked in+# and the app points at it today, so redefining that name mid-rollout would+# break any client that had already fetched the old bytes.+if [[ -z "$OUT" ]]; then+ if [[ "$NO_BASE" == "1" ]]; then OUT="v5-overlay.pmtiles"; else OUT="v5.pmtiles"; fi+fi+ # Every layer keeps a rust|legacy switch even before it has a rust path, so the # superscript can pass one uniformly. Asking for an unported engine is an error # rather than a silent fall-back to legacy.@@ -198,17 +259,20 @@ INPUTS=() # --- 1. base --- BASE="$WORK/base.pmtiles"-if [[ "$SKIP_BASE" == "1" ]]; then+if [[ "$NO_BASE" == "1" ]]; then+ echo "[v5] --no-base: overlays only, pairing with the published base archive"+elif [[ "$SKIP_BASE" == "1" ]]; then [[ -f "$BASE" ]] || { echo "ERROR: --skip-base but $BASE missing" >&2; exit 1; } echo "[v5] using existing base $BASE"+ INPUTS+=("$BASE") else BASE_ARGS=(--mode "$BASE_MODE" --out "$BASE") [[ -n "$BBOX" ]] && BASE_ARGS+=(--bbox "$BBOX") [[ -n "$BASE_SOURCE" ]] && BASE_ARGS+=(--source "$BASE_SOURCE") [[ "$BASE_MODE" == "build" ]] && BASE_ARGS+=(--jar "$BASE_JAR" --area "$BASE_AREA") run "$HERE/build_base_layers.sh" "${BASE_ARGS[@]}"+ INPUTS+=("$BASE") fi-INPUTS+=("$BASE") # --- 2. safety --- if [[ "$SKIP_SAFETY" == "0" ]]; then@@ -241,7 +305,8 @@ fi if [[ "$SKIP_POIS" == "0" ]]; then [[ -n "$PBF" ]] || { echo "ERROR: --pbf required for ma_pois layer (or --skip-pois)" >&2; exit 1; } POIS_ARGS=(--pbf "$PBF" --out "$WORK/ma_pois.pmtiles" \- --names-out "$OUTDIR/poi_names.bin" --index-out "$OUTDIR/poi_index.bin")+ --names-out "$OUTDIR/poi_names.bin" --index-out "$OUTDIR/poi_index.bin" \+ --attrs-out "$OUTDIR/poi_attrs.bin") [[ -n "$BBOX" ]] && POIS_ARGS+=(--bbox "$BBOX") run "$HERE/build_pois_layer.sh" "${POIS_ARGS[@]}" INPUTS+=("$WORK/ma_pois.pmtiles")@@ -330,7 +395,11 @@ 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"+if [[ "$NO_BASE" == "1" ]]; then+ echo " (no base layers -- pair this with the published base archive)"+else+ echo " base : earth landcover landuse water roads buildings boundaries pois places"+fi echo " new : safety maxspeed transit_lines ma_pois transit_stops" echo " admin_country admin_region admin_city" echo ""@@ -338,6 +407,7 @@ if [[ "$SKIP_POIS" == "0" ]]; then echo "POI side files (emitted beside $OUT for the app to mmap):" echo " $OUTDIR/poi_names.bin (deduped NUL-terminated UTF-8 name table)" echo " $OUTDIR/poi_index.bin (flat 14-byte records: lat_e7,lon_e7,name_off,type)"+ echo " $OUTDIR/poi_attrs.bin (attribute sidecar, keyed by poi_index record ordinal)" echo "" fi @@ -350,9 +420,13 @@ else echo "Publish (creds from environment variables — see README 'Publishing to R2'):" echo " export R2_ENDPOINT=https://<ACCOUNT_ID>.r2.cloudflarestorage.com" echo " export R2_ACCESS_KEY_ID=... R2_SECRET_ACCESS_KEY=..."- echo " ./scripts/maps/publish_r2.sh $OUT --key v5.pmtiles"+ echo " ./scripts/maps/publish_r2.sh $OUT --key $(basename "$OUT")" echo " # or re-run this build with --publish"- echo "Then P13 updates style.json url -> pmtiles://https://data.vayunmathur.com/v5.pmtiles"+ if [[ "$NO_BASE" == "1" ]]; then+ echo "Then point MapTileCache.OVERLAY_PMTILES_URL at the published key."+ else+ echo "Then P13 updates style.json url -> pmtiles://https://data.vayunmathur.com/v5.pmtiles"+ fi fi # Intermediates are never deleted, by design -- they are what makes a re-run cheap.