#!/usr/bin/env bash # HuntGrid Backcountry's OpenStreetMap tileset for the US and Canada (docs/backcountry/PLAN.md B2.2a): backcountry-osm/build # for every US state and Canadian province and territory (Geofabrik extracts), then one file joined with tile-join → # data/tiles/backcountry-osm.pmtiles, re-stamped with the ODbL notice and the oldest extract date, and # data/build/backcountry-osm-all/sizes.json (bytes per region and the total) for BJ-13. PC only (owner step; hours, # about 20 GB of downloads): the VM never builds tiles. # # tools/geodata/backcountry-osm/build-all # every state, province and territory # HG_BACKCOUNTRY_REGIONS="north-america/us/minnesota north-america/canada/ontario" tools/geodata/backcountry-osm/build-all # # Neighbouring extracts overlap a little at their borders, so a portage or route crossing one can be in two inputs; # tile-join keeps both copies (drawn on top of each other: harmless for a display tileset). A region already built is # reused (HG_REBUILD=1 rebuilds); each region's download is deleted after its build unless HG_KEEP_EXTRACTS=1. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)" US_STATES="alabama alaska arizona arkansas california colorado connecticut delaware district-of-columbia florida georgia hawaii idaho illinois indiana iowa kansas kentucky louisiana maine maryland massachusetts michigan minnesota mississippi missouri montana nebraska nevada new-hampshire new-jersey new-mexico new-york north-carolina north-dakota ohio oklahoma oregon pennsylvania rhode-island south-carolina south-dakota tennessee texas utah vermont virginia washington west-virginia wisconsin wyoming" CA_REGIONS="alberta british-columbia manitoba new-brunswick newfoundland-and-labrador northwest-territories nova-scotia nunavut ontario prince-edward-island quebec saskatchewan yukon" DEFAULT_REGIONS="$(for s in $US_STATES; do printf 'north-america/us/%s ' "$s"; done; for p in $CA_REGIONS; do printf 'north-america/canada/%s ' "$p"; done)" REGIONS="${HG_BACKCOUNTRY_REGIONS:-$DEFAULT_REGIONS}" OUT="$ROOT/data/build/backcountry-osm-all" log() { printf '\033[1;32m==>\033[0m %s\n' "$*"; } mkdir -p "$OUT" sizes="{" for extract in $REGIONS; do name="${extract##*/}" if [[ -f "$OUT/$name.pmtiles" && -z "${HG_REBUILD:-}" ]]; then log "$name: reusing $OUT/$name.pmtiles (HG_REBUILD=1 to rebuild)" else pbf="$ROOT/data/downloads/osm/${extract//\//-}-latest.osm.pbf" fresh="$([[ -f "$pbf" ]] && echo yes || true)" HG_OSM_EXTRACT="$extract" "$ROOT/tools/geodata/backcountry-osm/build" mv -f "$ROOT/data/tiles/backcountry-osm.pmtiles" "$OUT/$name.pmtiles" # Only a download this run made is deleted: extracts other pipelines left are theirs. [[ -z "$fresh" && -z "${HG_KEEP_EXTRACTS:-}" ]] && rm -f "$pbf" fi sizes+="\"$name\": $(wc -c <"$OUT/$name.pmtiles")," done log "Joining $(wc -w <<<"$REGIONS") regions" inputs=() for extract in $REGIONS; do inputs+=("/data/build/backcountry-osm-all/${extract##*/}.pmtiles"); done HG_DB_URL="${HG_DB_URL:-unused}" "$ROOT/tools/geodata/run" backcountry-osm/join "${inputs[@]}" total="$(wc -c <"$ROOT/data/tiles/backcountry-osm.pmtiles")" printf '%s "total": %s}\n' "$sizes" "$total" >"$OUT/sizes.json" log "Done: data/tiles/backcountry-osm.pmtiles ($(du -h "$ROOT/data/tiles/backcountry-osm.pmtiles" | cut -f1)); sizes in $OUT/sizes.json"