#!/usr/bin/env bash # The join step of backcountry-osm/build-all (docs/backcountry/PLAN.md B2.2a), in the geotools image (no database): the # regions' backcountry-osm archives → one /data/tiles/backcountry-osm.pmtiles with tile-join, every layer and zoom kept # (-pk: no tile size limit), stamped with the ODbL notice, the 4.6 offer and the oldest extract date. Only # backcountry-osm archives go in: the result stays one ODbL tileset. # # tools/geodata/run backcountry-osm/join /data/build/backcountry-osm-all/minnesota.pmtiles /data/build/backcountry-osm-all/ontario.pmtiles set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" log() { printf '\033[1;32m==>\033[0m %s\n' "$*"; } die() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; } [[ $# -ge 1 ]] || die "usage: backcountry-osm/join …" oldest="" for f in "$@"; do [[ -f "$f" ]] || die "no archive at $f" meta="$(python3 -I "$HERE/../lib/pmtiles_meta.py" show "$f")" python3 -I -c 'import json, sys; m = json.load(sys.stdin) sys.exit(0 if m.get("dataset") == "backcountry-osm" else "%s is not a backcountry-osm archive" % sys.argv[1])' "$f" <<<"$meta" v="$(python3 -I -c 'import json, sys; print(json.load(sys.stdin).get("source_version", ""))' <<<"$meta")" [[ -z "$oldest" || "$v" < "$oldest" ]] && oldest="$v" done BUILD_DIR="${HG_BUILD_DIR:-/tmp/hg-build}/backcountry-osm-join" rm -rf "$BUILD_DIR" && mkdir -p "$BUILD_DIR" # Docker Desktop bind mounts can fail tile-join on big inputs (docs/10 §4c): read copies on the container's own disk. local_inputs=() for f in "$@"; do cp "$f" "$BUILD_DIR/in-${#local_inputs[@]}.pmtiles"; local_inputs+=("$BUILD_DIR/in-${#local_inputs[@]}.pmtiles"); done tile-join -o "$BUILD_DIR/backcountry-osm.pmtiles" -f -q -pk -n "HuntGrid Backcountry OSM" \ -A '© OpenStreetMap contributors' "${local_inputs[@]}" python3 "$HERE/../lib/pmtiles_meta.py" odbl "$BUILD_DIR/backcountry-osm.pmtiles" backcountry-osm "$oldest" mkdir -p /data/tiles cp "$BUILD_DIR/backcountry-osm.pmtiles" /data/tiles/.backcountry-osm.pmtiles.part mv -f /data/tiles/.backcountry-osm.pmtiles.part /data/tiles/backcountry-osm.pmtiles rm -rf "$BUILD_DIR" log "Joined $# regions into /data/tiles/backcountry-osm.pmtiles ($oldest)"