The dev directory now holds source code + compiled binaries only:
~/trips/osm/ OSM PBF extracts (was osm/, 1.4 GB)
~/trips/tilecache/ mock tile cache (was mock/.tilecache)
~/trips/store/mock/ per-trip uploads + chat logs (was mock/store, PII)
~/trips/logs/ server.log
~/trips/stale-osm-build/ stale source/tarball dup of ~/osm-build
(repo osm/build had no binaries; the live OSRM
toolchain + graphs already lived in ~/osm-build)
Code now points at the new locations, all overridable via env:
- mock/server.js: TRIPS_HOME (default ~/trips) for tile cache + store
- setup-osrm.sh / setup-osrm-colombia.sh: OSM_DIR (default ~/trips/osm)
- spatial/compose+import.sh: OSM_DIR (default ~/trips/osm)
- .gitignore: rewritten — no artifact paths remain in-tree
65 lines
2.2 KiB
Bash
Executable File
65 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Pre-cache OSM tiles for the trip's map extent through the local proxy
|
|
# (the proxy stores them in ~/trips/tilecache). Usage:
|
|
# pre-cache-tiles.sh # all trips
|
|
# pre-cache-tiles.sh colombia z16 # one trip, one zoom
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
BASE="${BASE:-http://localhost:8077}"
|
|
TRIPS=("$@")
|
|
[ ${#TRIPS[@]} -eq 0 ] && TRIPS=(colombia boston florence)
|
|
|
|
# tile range for a lon/lat box
|
|
range() { # z minlon minlat maxlon maxlat -> "x0 x1 y0 y1"
|
|
python3 -c "
|
|
import math
|
|
z, minlo, minla, maxlo, maxla = float('$1'), float('$2'), float('$3'), float('$4'), float('$5')
|
|
def tx(lon): return int((lon + 180) / 360 * 2**z)
|
|
def ty(lat):
|
|
r = math.radians(lat)
|
|
return int((1 - math.log(math.tan(r) + 1 / math.cos(r)) / math.pi) / 2 * 2**z)
|
|
print(tx(minlo), tx(maxlo), ty(maxla), ty(minla))"
|
|
}
|
|
|
|
fetch() { # trip z
|
|
local trip="$1" z="$2"
|
|
case "$trip" in
|
|
colombia)
|
|
# Cartagena + Santa Marta boxes
|
|
for box in "-75.62 10.36 -75.42 10.48" "-74.27 11.08 -74.13 11.28"; do
|
|
set -- $box
|
|
read -r x0 x1 y0 y1 <<< "$(range "$z" "$1" "$2" "$3" "$4")"
|
|
echo " $trip z$z box($1,$2,$3,$4): x $x0-$x1 y $y0-$y1" >&2
|
|
for ((x=x0; x<=x1; x++)); do for ((y=y0; y<=y1; y++)); do
|
|
echo "$BASE/tiles/$z/$x/$y.png"
|
|
done; done
|
|
done
|
|
;;
|
|
boston)
|
|
set -- -71.16 42.29 -71.00 42.41
|
|
read -r x0 x1 y0 y1 <<< "$(range "$z" "$1" "$2" "$3" "$4")"
|
|
for ((x=x0; x<=x1; x++)); do for ((y=y0; y<=y1; y++)); do
|
|
echo "$BASE/tiles/$z/$x/$y.png"
|
|
done; done
|
|
;;
|
|
florence)
|
|
set -- 11.19 43.72 11.32 43.80
|
|
read -r x0 x1 y0 y1 <<< "$(range "$z" "$1" "$2" "$3" "$4")"
|
|
for ((x=x0; x<=x1; x++)); do for ((y=y0; y<=y1; y++)); do
|
|
echo "$BASE/tiles/$z/$x/$y.png"
|
|
done; done
|
|
;;
|
|
esac
|
|
}
|
|
|
|
for trip in "${TRIPS[@]}"; do
|
|
for z in 14 15 16; do
|
|
echo "== $trip z$z"
|
|
# one URL per curl: -o applies to the first URL only, otherwise the rest
|
|
# print to stdout
|
|
fetch "$trip" "$z" | xargs -P 8 -n 1 curl -s -o /dev/null -m 20 --retry 2 > /dev/null
|
|
done
|
|
done
|
|
CACHE_DIR="${TRIPS_HOME:-$HOME/trips}/tilecache"
|
|
echo "done. cache size: $(du -sh "$CACHE_DIR" 2>/dev/null | cut -f1)"
|