Files
wiki/tasks/enduro-trails/scripts/download_gap_v2.sh
2026-05-13 12:20:17 +03:00

82 lines
2.3 KiB
Bash

#!/bin/bash
set -e
cd /home/slin/enduro-trails/data/srtm
echo 'Downloading missing SRTM tiles from multiple mirrors...'
download_tile() {
local tile=$1
local f="${tile}.hgt"
if [ -f "$f" ]; then
echo " EXISTS: $f"
return 0
fi
# Mirror 1: USGS via e4ftl01 (SRTMGL3 - 3 arc-second, no auth for v003)
# Mirror 2: OpenData AWS terrain tiles
# Mirror 3: viewfinderpanoramas.org
local lat_num=${tile:1:2}
local lon_num=${tile:4:3}
# Try viewfinderpanoramas (grouped by lat band in zip)
# Individual files available at: http://viewfinderpanoramas.org/dem3/N55/N55E041.hgt.zip
local vfp_url="http://viewfinderpanoramas.org/dem3/${tile:0:3}/${tile}.hgt.zip"
wget -q --timeout=30 "$vfp_url" -O "/tmp/${tile}.zip" 2>/dev/null
if [ -s "/tmp/${tile}.zip" ]; then
unzip -o -q "/tmp/${tile}.zip" -d . 2>/dev/null
if [ -f "$f" ]; then
echo " OK (viewfinder): $f ($(du -h $f | cut -f1))"
rm -f "/tmp/${tile}.zip"
return 0
fi
fi
rm -f "/tmp/${tile}.zip"
# Try CGIAR SRTM v4 (5x5 degree tiles, different naming)
# Try direct NASA mirror
local nasa_url="https://e4ftl01.cr.usgs.gov/MEASURES/SRTMGL3.003/2000.02.11/${tile}.SRTMGL3.hgt.zip"
wget -q --timeout=30 "$nasa_url" -O "/tmp/${tile}.zip" 2>/dev/null
if [ -s "/tmp/${tile}.zip" ]; then
unzip -o -q "/tmp/${tile}.zip" -d . 2>/dev/null
if [ -f "$f" ]; then
echo " OK (nasa): $f ($(du -h $f | cut -f1))"
rm -f "/tmp/${tile}.zip"
return 0
fi
fi
rm -f "/tmp/${tile}.zip"
# Try sonny's mirror (reliable for SRTM3)
local sonny_url="https://srtm.kurviger.de/SRTM3/Eurasia/${tile}.hgt.zip"
wget -q --timeout=30 "$sonny_url" -O "/tmp/${tile}.zip" 2>/dev/null
if [ -s "/tmp/${tile}.zip" ]; then
unzip -o -q "/tmp/${tile}.zip" -d . 2>/dev/null
if [ -f "$f" ]; then
echo " OK (kurviger): $f ($(du -h $f | cut -f1))"
rm -f "/tmp/${tile}.zip"
return 0
fi
fi
rm -f "/tmp/${tile}.zip"
echo " FAIL: $tile (all mirrors failed)"
return 1
}
# Clean up stale downloads
rm -f /tmp/N*.hgt.zip
for lat in 54 55 56; do
for lon in 041 042 043 044 045 046; do
download_tile "N${lat}E${lon}"
done
done
echo ''
echo "Total HGT files: $(ls *.hgt | wc -l)"
echo "E041-E046 coverage:"
ls *E04[1-6]* 2>/dev/null | grep -E "N5[456]" | sort