Terrain_MBtiles/ph1.sh
Fabio Micheluz acf5948fdb first commit
2026-02-08 15:56:14 +01:00

113 lines
2.4 KiB
Bash
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/zsh
###############################################
# CONFIG
###############################################
RIO="/opt/local/Library/Frameworks/Python.framework/Versions/3.11/bin/rio"
MANIFEST="manifest_dem.txt"
OUT_ROOT="terrain_rgb"
LOG_DIR="logs/dem"
RESUME_FILE="resume/dem_resume.txt"
mkdir -p "$OUT_ROOT" "$LOG_DIR" "resume"
###############################################
# CHECK BINARI
###############################################
check_bin() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "[ERRORE] Binario non trovato: $1"
exit 1
fi
}
check_bin gdalinfo
check_bin gdal_translate
if [ ! -x "$RIO" ]; then
echo "[ERRORE] rio non trovato: $RIO"
exit 1
fi
###############################################
# RESUME
###############################################
LAST_DONE=0
if [ -f "$RESUME_FILE" ]; then
LAST_DONE=$(cat "$RESUME_FILE")
fi
DEM_COUNT=0
###############################################
# LOOP DEM
###############################################
while IFS= read -r DEM; do
DEM=$(echo "$DEM" | tr -d '\r' | xargs)
[ -z "$DEM" ] && continue
if [ ! -f "$DEM" ]; then
echo "[WARN] DEM non trovato: $DEM"
continue
fi
DEM_COUNT=$((DEM_COUNT + 1))
if [ "$DEM_COUNT" -le "$LAST_DONE" ]; then
echo "[SKIP] DEM #$DEM_COUNT già processato"
continue
fi
BASENAME=$(basename "$DEM" .tif)
WORKDIR="$OUT_ROOT/$BASENAME"
mkdir -p "$WORKDIR"
LOGFILE="$LOG_DIR/${BASENAME}.log"
echo "[INFO] DEM #$DEM_COUNT$DEM"
echo "[INFO] Log: $LOGFILE"
OUT_TERRAIN="$WORKDIR/${BASENAME}_terrain_rgb.tif"
{
echo "----------------------------------------"
echo "DEM: $DEM"
echo "Output: $OUT_TERRAIN"
echo "Start: $(date)"
echo "----------------------------------------"
"$RIO" rgbify \
--min-z 0 \
--max-z 9000 \
--format png \
"$DEM" \
"$OUT_TERRAIN"
STATUS=$?
echo "End: $(date)"
echo "Status: $STATUS"
echo "----------------------------------------"
} >> "$LOGFILE" 2>&1
if [ "$STATUS" -ne 0 ]; then
echo "[ERRORE] rgbify fallito per $DEM"
continue
fi
echo "$DEM_COUNT" > "$RESUME_FILE"
echo "[OK] TerrainRGB generato per $BASENAME"
done < "$MANIFEST"
echo "[INFO] Fase 1 completata"