0d5fcf909c
- Extend PMTiles to include simplified terenuri (5m tolerance) and cladiri (3m) - map-viewer: terenuri z13 from PMTiles, z14+ from Martin (live detail) - map-viewer: cladiri z14 from PMTiles, z15+ from Martin - Martin sources start at higher minzoom when PMTiles active (less DB load) - Add warm-tile-cache.sh: pre-populate nginx cache for major cities - Rebuild script now includes cache warming step after PMTiles upload - Remove deprecated docker-compose version: "3.8" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
142 lines
5.3 KiB
Bash
142 lines
5.3 KiB
Bash
#!/usr/bin/env bash
|
|
# rebuild-overview-tiles.sh — Export all overview layers from PostGIS, generate PMTiles, upload to MinIO
|
|
# Includes: UAT boundaries, administrativ, simplified terenuri (z10-z14), simplified cladiri (z12-z14)
|
|
# Usage: ./scripts/rebuild-overview-tiles.sh
|
|
# Dependencies: ogr2ogr (GDAL), tippecanoe, mc (MinIO client)
|
|
|
|
set -euo pipefail
|
|
|
|
# ── Configuration ──
|
|
DB_HOST="${DB_HOST:-10.10.10.166}"
|
|
DB_PORT="${DB_PORT:-5432}"
|
|
DB_NAME="${DB_NAME:-architools_db}"
|
|
DB_USER="${DB_USER:-architools_user}"
|
|
DB_PASS="${DB_PASS:-stictMyFon34!_gonY}"
|
|
|
|
MINIO_ALIAS="${MINIO_ALIAS:-myminio}"
|
|
MINIO_BUCKET="${MINIO_BUCKET:-tiles}"
|
|
MINIO_ENDPOINT="${MINIO_ENDPOINT:-http://10.10.10.166:9002}"
|
|
MINIO_ACCESS_KEY="${MINIO_ACCESS_KEY:-admin}"
|
|
MINIO_SECRET_KEY="${MINIO_SECRET_KEY:-MinioStrongPass123}"
|
|
|
|
TMPDIR="${TMPDIR:-/tmp/tile-rebuild}"
|
|
OUTPUT_FILE="overview.pmtiles"
|
|
|
|
PG_CONN="PG:host=${DB_HOST} port=${DB_PORT} dbname=${DB_NAME} user=${DB_USER} password=${DB_PASS}"
|
|
|
|
echo "[$(date -Iseconds)] Starting overview tile rebuild..."
|
|
|
|
# ── Setup ──
|
|
mkdir -p "$TMPDIR"
|
|
cd "$TMPDIR"
|
|
|
|
# ── Step 1: Export views from PostGIS (parallel) ──
|
|
echo "[$(date -Iseconds)] Exporting PostGIS views to FlatGeobuf..."
|
|
|
|
# UAT boundaries (4 zoom levels)
|
|
ogr2ogr -f FlatGeobuf -s_srs EPSG:3844 -t_srs EPSG:4326 \
|
|
uats_z0.fgb "$PG_CONN" \
|
|
-sql "SELECT name, siruta, geom FROM gis_uats_z0 WHERE geom IS NOT NULL" &
|
|
|
|
ogr2ogr -f FlatGeobuf -s_srs EPSG:3844 -t_srs EPSG:4326 \
|
|
uats_z5.fgb "$PG_CONN" \
|
|
-sql "SELECT name, siruta, geom FROM gis_uats_z5 WHERE geom IS NOT NULL" &
|
|
|
|
ogr2ogr -f FlatGeobuf -s_srs EPSG:3844 -t_srs EPSG:4326 \
|
|
uats_z8.fgb "$PG_CONN" \
|
|
-sql "SELECT name, siruta, county, geom FROM gis_uats_z8 WHERE geom IS NOT NULL" &
|
|
|
|
ogr2ogr -f FlatGeobuf -s_srs EPSG:3844 -t_srs EPSG:4326 \
|
|
uats_z12.fgb "$PG_CONN" \
|
|
-sql "SELECT name, siruta, county, geom FROM gis_uats_z12 WHERE geom IS NOT NULL" &
|
|
|
|
# Administrativ (intravilan, arii speciale)
|
|
ogr2ogr -f FlatGeobuf -s_srs EPSG:3844 -t_srs EPSG:4326 \
|
|
administrativ.fgb "$PG_CONN" \
|
|
-sql "SELECT object_id, siruta, layer_id, cadastral_ref, geom FROM gis_administrativ WHERE geom IS NOT NULL" &
|
|
|
|
# Terenuri simplified for overview (ST_SimplifyPreserveTopology 5m tolerance — good for z10-z14)
|
|
# Only essential properties for overview display
|
|
ogr2ogr -f FlatGeobuf -s_srs EPSG:3844 -t_srs EPSG:4326 \
|
|
terenuri_overview.fgb "$PG_CONN" \
|
|
-sql "SELECT object_id, siruta, cadastral_ref, area_value, layer_id,
|
|
ST_SimplifyPreserveTopology(geom, 5) AS geom
|
|
FROM gis_terenuri WHERE geom IS NOT NULL" &
|
|
|
|
# Cladiri simplified for overview (3m tolerance — buildings are smaller)
|
|
ogr2ogr -f FlatGeobuf -s_srs EPSG:3844 -t_srs EPSG:4326 \
|
|
cladiri_overview.fgb "$PG_CONN" \
|
|
-sql "SELECT object_id, siruta, cadastral_ref, area_value, layer_id,
|
|
ST_SimplifyPreserveTopology(geom, 3) AS geom
|
|
FROM gis_cladiri WHERE geom IS NOT NULL" &
|
|
|
|
wait
|
|
echo "[$(date -Iseconds)] Export complete."
|
|
|
|
# ── Step 2: Generate PMTiles with tippecanoe ──
|
|
echo "[$(date -Iseconds)] Generating PMTiles..."
|
|
|
|
tippecanoe \
|
|
-o "$OUTPUT_FILE" \
|
|
--named-layer=gis_uats_z0:uats_z0.fgb \
|
|
--named-layer=gis_uats_z5:uats_z5.fgb \
|
|
--named-layer=gis_uats_z8:uats_z8.fgb \
|
|
--named-layer=gis_uats_z12:uats_z12.fgb \
|
|
--named-layer=gis_administrativ:administrativ.fgb \
|
|
--named-layer=gis_terenuri:terenuri_overview.fgb \
|
|
--named-layer=gis_cladiri:cladiri_overview.fgb \
|
|
--minimum-zoom=0 \
|
|
--maximum-zoom=14 \
|
|
--base-zoom=14 \
|
|
--drop-densest-as-needed \
|
|
--detect-shared-borders \
|
|
--hilbert \
|
|
--force
|
|
|
|
echo "[$(date -Iseconds)] PMTiles generated: $(du -h "$OUTPUT_FILE" | cut -f1)"
|
|
|
|
# ── Step 3: Upload to MinIO (atomic swap) ──
|
|
echo "[$(date -Iseconds)] Uploading to MinIO..."
|
|
|
|
# Configure MinIO client alias (idempotent)
|
|
mc alias set "$MINIO_ALIAS" "$MINIO_ENDPOINT" "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY" --api S3v4 2>/dev/null || true
|
|
|
|
# Ensure bucket exists
|
|
mc mb --ignore-existing "${MINIO_ALIAS}/${MINIO_BUCKET}" 2>/dev/null || true
|
|
|
|
# Upload as temp file first
|
|
mc cp "$OUTPUT_FILE" "${MINIO_ALIAS}/${MINIO_BUCKET}/overview_new.pmtiles"
|
|
|
|
# Atomic rename (zero-downtime swap)
|
|
mc mv "${MINIO_ALIAS}/${MINIO_BUCKET}/overview_new.pmtiles" "${MINIO_ALIAS}/${MINIO_BUCKET}/overview.pmtiles"
|
|
|
|
echo "[$(date -Iseconds)] Upload complete."
|
|
|
|
# ── Step 4: Warm nginx tile cache (detail layers only — overview served from PMTiles) ──
|
|
TILE_CACHE="${TILE_CACHE_URL:-http://10.10.10.166:3010}"
|
|
echo "[$(date -Iseconds)] Warming tile cache for detail layers..."
|
|
# Warm popular z14-z16 tiles for Bucharest + Cluj (Martin-served detail layers)
|
|
for z in 14 15; do
|
|
for source in gis_terenuri gis_cladiri; do
|
|
# Bucharest
|
|
for x in $(seq 9200 9220); do
|
|
for y in $(seq 5960 5975); do
|
|
echo "${TILE_CACHE}/${source}/${z}/${x}/${y}"
|
|
done
|
|
done
|
|
# Cluj
|
|
for x in $(seq 9058 9068); do
|
|
for y in $(seq 5842 5852); do
|
|
echo "${TILE_CACHE}/${source}/${z}/${x}/${y}"
|
|
done
|
|
done
|
|
done
|
|
done | xargs -P 8 -I {} curl -sf -o /dev/null {} 2>/dev/null || true
|
|
|
|
echo "[$(date -Iseconds)] Cache warming complete."
|
|
|
|
# ── Step 5: Cleanup ──
|
|
rm -f uats_z0.fgb uats_z5.fgb uats_z8.fgb uats_z12.fgb administrativ.fgb \
|
|
terenuri_overview.fgb cladiri_overview.fgb "$OUTPUT_FILE"
|
|
echo "[$(date -Iseconds)] Rebuild finished successfully."
|