auto-sync: 2026-05-14 09:20:01
This commit is contained in:
125
tasks/enduro-trails/scripts/tri_max_regen.sh
Normal file
125
tasks/enduro-trails/scripts/tri_max_regen.sh
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo '=== TRI REGENERATION WITH MAX-AGGREGATION FOR LOW ZOOMS ==='
|
||||
echo "Start: $(date)"
|
||||
|
||||
TMP='/tmp/tri_gen'
|
||||
SRTM_DIR='/home/slin/enduro-trails/data/srtm'
|
||||
TERRAIN_DIR='/home/slin/enduro-trails/data/terrain'
|
||||
TRI_DIR="${TERRAIN_DIR}/tri"
|
||||
|
||||
mkdir -p $TMP
|
||||
|
||||
echo ''
|
||||
echo '=== Step 1: Check tri_raw_full.tif ==='
|
||||
if [ -f "$TMP/tri_raw_full.tif" ]; then
|
||||
echo "tri_raw_full.tif exists:"
|
||||
gdalinfo -stats $TMP/tri_raw_full.tif 2>&1 | grep -E "Size|STATISTICS" || true
|
||||
else
|
||||
echo "tri_raw_full.tif NOT FOUND — regenerating from SRTM..."
|
||||
find $SRTM_DIR -name '*.hgt' > $TMP/hgt_list.txt
|
||||
echo "HGT files: $(wc -l < $TMP/hgt_list.txt)"
|
||||
gdalbuildvrt -vrtnodata -32768 -overwrite -input_file_list $TMP/hgt_list.txt $TMP/srtm.vrt
|
||||
gdaldem TRI $TMP/srtm.vrt $TMP/tri_raw_full.tif -of GTiff -co COMPRESS=LZW -co BIGTIFF=YES -compute_edges
|
||||
echo "TRI computed:"
|
||||
gdalinfo -stats $TMP/tri_raw_full.tif 2>&1 | grep -E "Size|STATISTICS" || true
|
||||
fi
|
||||
|
||||
echo ''
|
||||
echo '=== Step 2: Add overviews with MAX resampling ==='
|
||||
# Check GDAL version for -r max support
|
||||
GDAL_VER=$(gdal-config --version 2>/dev/null || gdalinfo --version | grep -oP '\d+\.\d+')
|
||||
echo "GDAL version: $GDAL_VER"
|
||||
|
||||
# Try gdaladdo -r max
|
||||
if gdaladdo -r max --config COMPRESS_OVERVIEW LZW $TMP/tri_raw_full.tif 2 4 8 16 32 64 2>&1; then
|
||||
echo "Overviews with MAX added successfully"
|
||||
gdalinfo $TMP/tri_raw_full.tif 2>&1 | grep -i "overview" || true
|
||||
else
|
||||
echo "gdaladdo -r max FAILED — using gdalwarp fallback"
|
||||
# Fallback: create a low-res version with max resampling
|
||||
gdalwarp -r max \
|
||||
-tr 0.01 0.01 \
|
||||
$TMP/tri_raw_full.tif \
|
||||
$TMP/tri_raw_lowres.tif \
|
||||
-co COMPRESS=LZW -overwrite
|
||||
echo "Low-res TRI created:"
|
||||
gdalinfo -stats $TMP/tri_raw_lowres.tif 2>&1 | grep -E "Size|STATISTICS" || true
|
||||
fi
|
||||
|
||||
echo ''
|
||||
echo '=== Step 3: Color relief (v5 ramp, threshold 15) ==='
|
||||
cat > $TMP/tri_color_max.txt << 'RAMP'
|
||||
nv 0 0 0 0
|
||||
0 0 0 0 0
|
||||
14 0 0 0 0
|
||||
15 255 255 100 60
|
||||
20 255 230 50 100
|
||||
25 255 200 0 140
|
||||
30 255 150 0 180
|
||||
40 255 100 0 200
|
||||
50 230 50 0 220
|
||||
65 200 0 0 235
|
||||
80 180 0 50 245
|
||||
100 150 0 100 255
|
||||
RAMP
|
||||
|
||||
gdaldem color-relief \
|
||||
$TMP/tri_raw_full.tif \
|
||||
$TMP/tri_color_max.txt \
|
||||
$TMP/tri_colored_max.tif \
|
||||
-alpha \
|
||||
-of GTiff \
|
||||
-co COMPRESS=LZW \
|
||||
-co BIGTIFF=YES
|
||||
|
||||
echo "Colored TRI created:"
|
||||
gdalinfo -stats $TMP/tri_colored_max.tif 2>&1 | grep STATISTICS_MAX || true
|
||||
|
||||
echo ''
|
||||
echo '=== Step 3-alt: Add overviews to colored file (max on RGBA) ==='
|
||||
gdaladdo -r max --config COMPRESS_OVERVIEW LZW $TMP/tri_colored_max.tif 2 4 8 16 32 64 2>&1 || true
|
||||
echo "Overviews on colored file:"
|
||||
gdalinfo $TMP/tri_colored_max.tif 2>&1 | grep -i "overview" || true
|
||||
|
||||
echo ''
|
||||
echo '=== Step 4: Generate tiles ==='
|
||||
rm -rf ${TRI_DIR}
|
||||
mkdir -p ${TRI_DIR}
|
||||
|
||||
gdal2tiles.py \
|
||||
--zoom=5-12 \
|
||||
--processes=4 \
|
||||
--tilesize=256 \
|
||||
--resampling=average \
|
||||
--webviewer=none \
|
||||
$TMP/tri_colored_max.tif \
|
||||
${TRI_DIR}/
|
||||
|
||||
echo ''
|
||||
echo '=== Step 5: Stats ==='
|
||||
for z in 5 6 7 8 9 10 11 12; do
|
||||
total=$(find ${TRI_DIR}/$z/ -name '*.png' 2>/dev/null | wc -l)
|
||||
nonempty=$(find ${TRI_DIR}/$z/ -name '*.png' -size +400c 2>/dev/null | wc -l)
|
||||
echo " zoom $z: $total total, $nonempty non-empty"
|
||||
done
|
||||
|
||||
echo ''
|
||||
echo '=== Step 6: Sample tile check ==='
|
||||
TILE=$(find ${TRI_DIR}/7/ -name '*.png' -size +1000c 2>/dev/null | head -1)
|
||||
if [ -n "$TILE" ]; then
|
||||
echo "Sample tile: $TILE"
|
||||
python3 -c "from PIL import Image; im=Image.open('$TILE'); print('Size:', im.size, 'Mode:', im.mode, 'Extrema:', im.getextrema())" 2>/dev/null || file "$TILE"
|
||||
else
|
||||
echo "No non-empty tiles found at zoom 7!"
|
||||
fi
|
||||
|
||||
echo ''
|
||||
echo '=== Step 7: Average tile size at zoom 7 ==='
|
||||
find ${TRI_DIR}/7/ -name '*.png' -size +400c -exec ls -la {} \; 2>/dev/null | awk '{sum+=$5; n++} END {if(n>0) print "avg:", sum/n, "bytes, count:", n; else print "no tiles"}'
|
||||
|
||||
echo ''
|
||||
du -sh ${TRI_DIR}
|
||||
echo '=== DONE ==='
|
||||
echo "End: $(date)"
|
||||
117
tasks/enduro-trails/scripts/tri_max_regen_v2.sh
Normal file
117
tasks/enduro-trails/scripts/tri_max_regen_v2.sh
Normal file
@@ -0,0 +1,117 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo '=== TRI MAX-AGGREGATION REGEN (GDAL 3.4 compatible) ==='
|
||||
echo "Start: $(date)"
|
||||
|
||||
TMP='/tmp/tri_gen'
|
||||
TERRAIN_DIR='/home/slin/enduro-trails/data/terrain'
|
||||
TRI_DIR="${TERRAIN_DIR}/tri"
|
||||
|
||||
mkdir -p $TMP
|
||||
|
||||
echo ''
|
||||
echo '=== Step 1: Verify tri_raw_full.tif ==='
|
||||
if [ ! -f "$TMP/tri_raw_full.tif" ]; then
|
||||
echo "FATAL: tri_raw_full.tif not found"
|
||||
exit 1
|
||||
fi
|
||||
echo "OK: $(gdalinfo $TMP/tri_raw_full.tif 2>&1 | grep 'Size is')"
|
||||
|
||||
echo ''
|
||||
echo '=== Step 2: Color relief (v5 ramp, threshold 15) ==='
|
||||
cat > $TMP/tri_color_max.txt << 'RAMP'
|
||||
nv 0 0 0 0
|
||||
0 0 0 0 0
|
||||
14 0 0 0 0
|
||||
15 255 255 100 60
|
||||
20 255 230 50 100
|
||||
25 255 200 0 140
|
||||
30 255 150 0 180
|
||||
40 255 100 0 200
|
||||
50 230 50 0 220
|
||||
65 200 0 0 235
|
||||
80 180 0 50 245
|
||||
100 150 0 100 255
|
||||
RAMP
|
||||
|
||||
gdaldem color-relief \
|
||||
$TMP/tri_raw_full.tif \
|
||||
$TMP/tri_color_max.txt \
|
||||
$TMP/tri_colored_max.tif \
|
||||
-alpha \
|
||||
-of GTiff \
|
||||
-co COMPRESS=LZW \
|
||||
-co BIGTIFF=YES
|
||||
echo "Colored TRI: $(du -sh $TMP/tri_colored_max.tif | cut -f1)"
|
||||
|
||||
echo ''
|
||||
echo '=== Step 3: Create low-res version with MAX resampling ==='
|
||||
# Target resolution ~0.005 deg (~500m) for zooms 5-9
|
||||
# gdalwarp -r max works on GDAL 3.4 (unlike gdaladdo -r max)
|
||||
gdalwarp -r max \
|
||||
-tr 0.005 0.005 \
|
||||
-srcnodata "0 0 0 0" \
|
||||
$TMP/tri_colored_max.tif \
|
||||
$TMP/tri_colored_lowres.tif \
|
||||
-co COMPRESS=LZW \
|
||||
-co BIGTIFF=YES \
|
||||
-overwrite
|
||||
echo "Low-res colored TRI: $(du -sh $TMP/tri_colored_lowres.tif | cut -f1)"
|
||||
echo "Size: $(gdalinfo $TMP/tri_colored_lowres.tif 2>&1 | grep 'Size is')"
|
||||
|
||||
echo ''
|
||||
echo '=== Step 4: Clean output directory ==='
|
||||
rm -rf ${TRI_DIR}
|
||||
mkdir -p ${TRI_DIR}
|
||||
|
||||
echo ''
|
||||
echo '=== Step 5: Generate tiles z5-9 from LOW-RES (max-aggregated) ==='
|
||||
gdal2tiles.py \
|
||||
--zoom=5-9 \
|
||||
--processes=4 \
|
||||
--tilesize=256 \
|
||||
--resampling=average \
|
||||
--webviewer=none \
|
||||
$TMP/tri_colored_lowres.tif \
|
||||
${TRI_DIR}/
|
||||
echo "Low zoom tiles done"
|
||||
|
||||
echo ''
|
||||
echo '=== Step 6: Generate tiles z10-12 from FULL-RES ==='
|
||||
gdal2tiles.py \
|
||||
--zoom=10-12 \
|
||||
--processes=4 \
|
||||
--tilesize=256 \
|
||||
--resampling=average \
|
||||
--webviewer=none \
|
||||
$TMP/tri_colored_max.tif \
|
||||
${TRI_DIR}/
|
||||
echo "High zoom tiles done"
|
||||
|
||||
echo ''
|
||||
echo '=== Step 7: Stats ==='
|
||||
for z in 5 6 7 8 9 10 11 12; do
|
||||
total=$(find ${TRI_DIR}/$z/ -name '*.png' 2>/dev/null | wc -l)
|
||||
nonempty=$(find ${TRI_DIR}/$z/ -name '*.png' -size +400c 2>/dev/null | wc -l)
|
||||
echo " zoom $z: $total total, $nonempty non-empty"
|
||||
done
|
||||
|
||||
echo ''
|
||||
echo '=== Step 8: Sample tile check (zoom 7) ==='
|
||||
TILE=$(find ${TRI_DIR}/7/ -name '*.png' -size +1000c 2>/dev/null | head -1)
|
||||
if [ -n "$TILE" ]; then
|
||||
echo "Sample: $TILE"
|
||||
python3 -c "from PIL import Image; im=Image.open('$TILE'); print('Size:', im.size, 'Mode:', im.mode); bands=im.split(); print('R range:', bands[0].getextrema(), 'A range:', bands[3].getextrema())" 2>/dev/null || file "$TILE"
|
||||
else
|
||||
echo "No large tiles at zoom 7"
|
||||
fi
|
||||
|
||||
echo ''
|
||||
echo '=== Step 9: Avg tile size at zoom 7 ==='
|
||||
find ${TRI_DIR}/7/ -name '*.png' -size +400c -exec ls -la {} \; 2>/dev/null | awk '{sum+=$5; n++} END {if(n>0) print "avg:", sum/n, "bytes, count:", n; else print "no tiles"}'
|
||||
|
||||
echo ''
|
||||
du -sh ${TRI_DIR}
|
||||
echo '=== DONE ==='
|
||||
echo "End: $(date)"
|
||||
Reference in New Issue
Block a user