forked from valhalla/valhalla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalhalla_build_elevation
More file actions
executable file
·80 lines (73 loc) · 2.4 KB
/
valhalla_build_elevation
File metadata and controls
executable file
·80 lines (73 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
set -e
function usage() {
echo "Usage: $0 min_x max_x min_y max_y [target_dir=elevation] [parallelism=$(nproc)] [decompress=true]"
exit 1
}
#validate ranges
if [ -z "$4" ]; then
usage
fi
min_x=$(python -c "import math; print int(math.floor($1))")
max_x=$(python -c "import math; print int(math.ceil($2) - 1)")
min_y=$(python -c "import math; print int(math.floor($3))")
max_y=$(python -c "import math; print int(math.ceil($4) - 1)")
if [ $min_x -gt $max_x ] || [ $min_x -lt -180 ] || [ $max_x -gt 180 ]; then
usage
fi
if [ $min_y -gt $max_y ] || [ $min_y -lt -90 ] || [ $max_y -gt 90 ]; then
usage
fi
if [ -z $5 ]; then
dest=elevation
else
dest="$5"
fi
if [ -z $6 ]; then
para=$(nproc)
else
para="$6"
fi
if [[ -z $7 ]] || [[ $7 != "false" ]]; then
decomp=true
export decomp
else
unset decomp
fi
#get dirs
for y in $(seq ${min_y} 1 ${max_y}); do
dir=$(python -c "print '%s%02d' % ('S' if ${y} < 0 else 'N', abs(${y}))")
echo "${dest}/${dir}"
done | while read d; do mkdir -p $d; done
#get the data
expected=$((($max_x - $min_x + 1)*($max_y - $min_y + 1)))
echo "extracting $expected elevation tiles"
ext=$( [[ ${decomp} ]] && echo "" || echo ".gz" )
for x in $(seq ${min_x} 1 ${max_x}); do
for y in $(seq ${min_y} 1 ${max_y}); do
file=$(python -c "print '%s%02d%s%03d.hgt' % ('S' if ${y} < 0 else 'N', abs(${y}), 'W' if ${x} < 0 else 'E', abs(${x}))")
dir=$(echo ${file} | sed "s/^\([NS][0-9]\{2\}\).*/\1/g")
#if we dont already have it or its the wrong size
if [ ! -e ${dest}/${dir}/${file} ] || [ $(stat -c %s ${dest}/${dir}/${file}) -ne $((3601*3601*2)) ]; then
echo "http://s3.amazonaws.com/elevation-tiles-prod/skadi/${dir}/${file}.gz ${dest}/${dir}/${file}${ext}"
fi
done
done | parallel --env decomp --progress -C ' ' -P ${para} 'curl --retry 3 --retry-delay 0 --max-time 100 -s -o - {1} | ( [[ ! ${decomp} ]] && cat || gunzip ) > {2}'
#check they are all there
echo "checking all files exist"
total=$(find ${dest} | grep -cF hgt)
if [ ${total} -ne ${expected} ]; then
echo "try again, $((${expected} - ${total})) files are missing"
exit 1
fi
#check their sizes
echo "checking file sizes"
if [ ${decomp} ]; then
found=$(find ${dest} -type f -size $((3601*3601*2))c | wc -l)
else
found=$(for f in $(find ${dest} -type f); do gzip -l $f | tail -n 1; done | grep -cvF $((3601*3601*2)))
fi
if [ ${found} -ne ${expected} ]; then
echo "try again, $((${expected} - ${found})) files are corrupt"
exit 1
fi