#!/usr/bin/env bash # HuntGrid Offroad's OpenStreetMap tracks and trails (docs/offroad/PLAN.md R4.1a, RF24) → data/tiles/offroad-osm.pmtiles, # layers `ways` (Planetiler, offroad-osm.yml) and `routes` (GDAL + tippecanoe, offroad-osm/routes), one ODbL tileset # with the licence and the extract date in its metadata. Unofficial data: Offroad draws it in the lens's "unknown" style # and never joins it with official routes in tiles, tables or offline packs (RJ-14). # # tools/geodata/offroad-osm/build # Michigan (dev default, a few minutes) # HG_OSM_EXTRACT=north-america/us/utah tools/geodata/offroad-osm/build # any Geofabrik extract # # The launch-region build and its merge are R4.1b (owner, on the PC). Extracts are shared with outdoor/build in # data/downloads/osm (reused for a day). Runs on Linux, macOS and Git Bash on Windows. Needs: bash, curl, docker. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" EXTRACT="${HG_OSM_EXTRACT:-north-america/us/michigan}" PLANETILER_IMAGE="${HG_PLANETILER_IMAGE:-ghcr.io/onthegomap/planetiler:0.9.2}" JAVA_MEMORY="${HG_PLANETILER_MEMORY:-3g}" log() { printf '\033[1;32m==>\033[0m %s\n' "$*"; } [[ "$EXTRACT" =~ ^[a-z0-9/-]+$ ]] || { echo "bad extract: $EXTRACT" >&2; exit 1; } host_path() { if command -v cygpath >/dev/null 2>&1; then cygpath -w "$1"; else printf '%s' "$1"; fi; } mkdir -p "$ROOT/data/build" "$ROOT/data/tiles" "$ROOT/data/downloads/osm" pbf="${EXTRACT//\//-}-latest.osm.pbf" if [[ -z "$(find "$ROOT/data/downloads/osm/$pbf" -mtime -1 2>/dev/null)" ]]; then log "Downloading https://download.geofabrik.de/$EXTRACT-latest.osm.pbf" # -R keeps the server's date on the file: the extract date the tileset records. curl -fsSL -R --retry 3 -A "HuntGrid geodata pipeline" -o "$ROOT/data/downloads/osm/$pbf.part" \ "https://download.geofabrik.de/$EXTRACT-latest.osm.pbf" mv -f "$ROOT/data/downloads/osm/$pbf.part" "$ROOT/data/downloads/osm/$pbf" fi log "Planetiler: offroad ways for $EXTRACT" # MSYS_NO_PATHCONV: Git Bash must pass the container paths through unchanged. MSYS_NO_PATHCONV=1 docker run --rm -e JAVA_TOOL_OPTIONS="-Xmx$JAVA_MEMORY" \ -v "$(host_path "$ROOT/data"):/data" -v "$(host_path "$ROOT/tools/geodata/offroad-osm"):/schema:ro" \ "$PLANETILER_IMAGE" generate-custom --schema=/schema/offroad-osm.yml --osm_path="/data/downloads/osm/$pbf" \ --tmpdir=/data/build/planetiler-offroad-tmp --output=/data/build/offroad-osm-ways.pmtiles --force rm -rf "$ROOT/data/build/planetiler-offroad-tmp" # The routes layer and the join run in the geotools image; they use no database (HG_DB_URL only satisfies `run`). HG_DB_URL="${HG_DB_URL:-unused}" HG_OSM_PBF="/data/downloads/osm/$pbf" HG_WAYS=/data/build/offroad-osm-ways.pmtiles \ "$ROOT/tools/geodata/run" offroad-osm/routes rm -f "$ROOT/data/build/offroad-osm-ways.pmtiles" log "Done: data/tiles/offroad-osm.pmtiles ($(du -h "$ROOT/data/tiles/offroad-osm.pmtiles" | cut -f1))"