Files
wiki/tasks/enduro-trails/scripts/regen_all.sh
2026-05-13 12:30:09 +03:00

93 lines
2.7 KiB
Bash

#!/bin/bash
set -e
echo '=== FULL REGENERATION (81 HGT files) ==='
echo "Start: $(date)"
SRTM_DIR='/home/slin/enduro-trails/data/srtm'
TERRAIN_DIR='/home/slin/enduro-trails/data/terrain'
TMP='/tmp/regen_full'
rm -rf $TMP
mkdir -p $TMP
echo ''
echo '=== Step 1: Build VRT ==='
find $SRTM_DIR -name '*.hgt' > $TMP/file_list.txt
gdalbuildvrt -vrtnodata -32768 -overwrite -input_file_list $TMP/file_list.txt $TMP/srtm_all.vrt 2>&1
echo "VRT: $(wc -l < $TMP/file_list.txt) files"
gdalinfo -stats $TMP/srtm_all.vrt 2>&1 | grep STATISTICS
echo ''
echo '=== Step 2: Generate HYPSO ==='
cat > $TMP/color_ramp.txt << 'EOF'
nv 0 0 0 0
-100 0 0 0 0
0 0 0 0 0
1 57 151 105 255
50 80 165 110 255
100 120 180 100 255
150 160 190 95 255
200 139 176 96 255
300 170 185 105 255
500 189 188 115 255
700 210 200 130 255
1000 220 206 148 255
1500 235 220 175 255
2000 210 185 140 255
2500 185 152 110 255
3000 160 120 80 255
4000 120 80 40 255
5000 200 200 200 255
EOF
gdaldem color-relief $TMP/srtm_all.vrt $TMP/color_ramp.txt $TMP/hypso.tif -alpha -of GTiff -co COMPRESS=LZW -co BIGTIFF=YES 2>&1
echo "Hypso TIF: $(du -sh $TMP/hypso.tif | cut -f1)"
rm -rf ${TERRAIN_DIR}/hypso
mkdir -p ${TERRAIN_DIR}/hypso
gdal2tiles.py --zoom=5-12 --processes=4 --tilesize=256 --webviewer=none $TMP/hypso.tif ${TERRAIN_DIR}/hypso/ 2>&1
echo "Hypso tiles: $(find ${TERRAIN_DIR}/hypso -name '*.png' | wc -l)"
echo ''
echo '=== Step 3: Generate TRI ==='
gdaldem TRI $TMP/srtm_all.vrt $TMP/tri_raw.tif -of GTiff -co COMPRESS=LZW -co BIGTIFF=YES -compute_edges 2>&1
cat > $TMP/tri_color.txt << 'EOF'
nv 0 0 0 0
0 0 0 0 0
2 0 0 0 0
3 255 255 100 60
4 255 230 50 100
5 255 200 0 140
7 255 150 0 180
10 255 100 0 200
15 230 50 0 220
20 200 0 0 235
30 180 0 50 245
50 150 0 100 255
EOF
gdaldem color-relief $TMP/tri_raw.tif $TMP/tri_color.txt $TMP/tri_colored.tif -alpha -of GTiff -co COMPRESS=LZW -co BIGTIFF=YES 2>&1
echo "TRI TIF: $(du -sh $TMP/tri_colored.tif | cut -f1)"
rm -rf ${TERRAIN_DIR}/tri
mkdir -p ${TERRAIN_DIR}/tri
gdal2tiles.py --zoom=5-12 --processes=4 --tilesize=256 --webviewer=none $TMP/tri_colored.tif ${TERRAIN_DIR}/tri/ 2>&1
echo "TRI tiles: $(find ${TERRAIN_DIR}/tri -name '*.png' | wc -l)"
echo ''
echo '=== Stats ==='
echo "Hypso:"
for z in 8 9 10 11 12; do
echo " zoom $z: $(find ${TERRAIN_DIR}/hypso/$z -name '*.png' -size +400c 2>/dev/null | wc -l) non-empty"
done
echo "TRI:"
for z in 8 9 10 11 12; do
echo " zoom $z: $(find ${TERRAIN_DIR}/tri/$z -name '*.png' -size +400c 2>/dev/null | wc -l) non-empty"
done
echo ''
echo "=== DONE ==="
echo "End: $(date)"