auto-sync: 2026-05-13 10:40:01
This commit is contained in:
87
tasks/enduro-trails/scripts/gen_tri.sh
Normal file
87
tasks/enduro-trails/scripts/gen_tri.sh
Normal file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo '=== TRI (Terrain Ruggedness) GENERATION ==='
|
||||
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"
|
||||
|
||||
rm -rf $TMP
|
||||
mkdir -p $TMP $TRI_DIR
|
||||
|
||||
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 built ($(wc -l < $TMP/file_list.txt) files)"
|
||||
|
||||
echo ''
|
||||
echo '=== Step 2: Generate TRI (Terrain Ruggedness Index) ==='
|
||||
gdaldem TRI \
|
||||
$TMP/srtm_all.vrt \
|
||||
$TMP/tri_raw.tif \
|
||||
-of GTiff \
|
||||
-co COMPRESS=LZW \
|
||||
-co BIGTIFF=YES \
|
||||
-compute_edges 2>&1
|
||||
|
||||
echo 'TRI stats:'
|
||||
gdalinfo -stats $TMP/tri_raw.tif 2>&1 | grep STATISTICS
|
||||
|
||||
echo ''
|
||||
echo '=== Step 3: Color-relief (transparent where flat, yellow-red where rugged) ==='
|
||||
# TRI values: 0=flat, 10=gentle, 30=moderate, 60+=steep
|
||||
cat > $TMP/tri_color.txt << 'EOF'
|
||||
nv 0 0 0 0
|
||||
0 0 0 0 0
|
||||
5 0 0 0 0
|
||||
10 255 255 100 80
|
||||
20 255 200 50 140
|
||||
30 255 140 0 180
|
||||
45 255 80 0 210
|
||||
60 230 30 0 230
|
||||
80 200 0 50 240
|
||||
100 180 0 100 250
|
||||
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 'Colored TRI stats:'
|
||||
gdalinfo -stats $TMP/tri_colored.tif 2>&1 | grep STATISTICS_MAX
|
||||
|
||||
echo ''
|
||||
echo '=== Step 4: Generate tiles (zoom 5-12) ==='
|
||||
gdal2tiles.py \
|
||||
--zoom=5-12 \
|
||||
--processes=4 \
|
||||
--tilesize=256 \
|
||||
--webviewer=none \
|
||||
$TMP/tri_colored.tif \
|
||||
${TRI_DIR}/ 2>&1
|
||||
|
||||
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 'Total:'
|
||||
find ${TRI_DIR} -name '*.png' | wc -l
|
||||
du -sh ${TRI_DIR}
|
||||
|
||||
echo ''
|
||||
echo '=== DONE ==='
|
||||
echo "End: $(date)"
|
||||
Reference in New Issue
Block a user