-
Notifications
You must be signed in to change notification settings - Fork 0
/
03.country.hgtToGTiff.sh
91 lines (72 loc) · 2.17 KB
/
03.country.hgtToGTiff.sh
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
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
main_dir=$(pwd)
. ${main_dir}/config
. ${main_dir}/regions
wbt="${main_dir}/tools/whitebox_tools"
work_dir="${main_dir}/work/${country}/dem"
mkdir -p $work_dir
# ---- Functions ----------------------------------------------------------
function fixingSRTM() {
local _base=$1
local _dir=$2
echo -n " > [Fixing 3601x3601 SRTM]: ${_base} ... "
local _latitude=`echo ${_base} | cut -b2-3`
local _longitude=`echo ${_base} | cut -b5-7`
local _semisphere_x=`echo $base | cut -b1`
if [ "${_semisphere_x}" = "S" ] ; then
local _latitude=`echo ${_latitude} | awk '{printf "%.10f", $1 * -1 }'`
fi
local _semisphere_y=`echo ${_base} | cut -b4`
if [ "${_semisphere_y}" = "W" ] ; then
local _longitude=`echo ${_longitude} | awk '{printf "%.10f", $1 * -1 }'`
fi
local _x=`echo ${_longitude} | awk '{printf "%.0f", $1}'`
local _y=`echo ${_latitude} | awk '{printf "%.0f", $1}'`
gdalwarp \
-of GTiff \
-multi \
-r ${resample_method} \
-te $((${_x}-1)).99986111 $((${_y}-1)).99986111 $((${_x}+1)).00013889 $((${_y}+1)).00013889 \
-tr 0.000277777777778 -0.000277777777778 \
"${_dir}/${_base}.hgt" \
"${_dir}/${_base}.fix.tif"
echo " > [CLEAR]: "
rm -vf "${_dir}/${_base}.hgt"
}
function fillingVoids() {
local _base=$1
local _dir=$2
echo -n " > [Fill all voids]: ${_base}: "
gdal_fillnodata.py \
-of GTiff \
"${_dir}/${_base}.fix.tif" \
"${_dir}/${_base}.fill.tif"
echo " > [CLEAR]: "
rm -vf "${_dir}/${_base}.fix.tif"
}
function smoothing() {
local _base=$1
local _dir=$2
echo -n " > [Smoothing DEM]: ${_base} ... "
$wbt \
-r=FeaturePreservingSmoothing \
--wd="${_dir}" \
--dem="${_base}.fill.tif" \
-o="${_base}.tif" \
--filter=${smooth_filter} \
--norm_diff=${smooth_norm_diff} \
--num_iter=${smooth_num_iter} \
--max_diff=${smooth_max_diff}
echo "done."
echo " > [CLEAR]: "
rm -vf "${_dir}/${_base}.fill.tif"
}
#------------------------------------------------------------------------------------
pushd $work_dir
for i in *.hgt; do
base=`basename ${i} .hgt`
fixingSRTM $base $work_dir
fillingVoids $base $work_dir
smoothing $base $work_dir
done
popd