-
Notifications
You must be signed in to change notification settings - Fork 3
/
gdal-reproject.sh
executable file
·74 lines (62 loc) · 1.58 KB
/
gdal-reproject.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
#!/usr/bin/env bash
VARIABLE=$1
ZOOM_LEVELS=$2
LAYER_TYPE=$3
RESOLUTION=$4
OUT_BOUNDS=$5
SOURCE_PROJECTION=$6
SOURCE_BOUNDS=$7
TRIMMED_SOURCE_BOUNDS=$(echo $SOURCE_BOUNDS | sed 's/ *$//g')
FOLDER=/data/netcdfs/
timestamp_counter=0
for file in $(find $FOLDER -name *.nc -type f | sort -n); do
echo "--------------"
echo $file
if [ ! -z "$SOURCE_PROJECTION" ] && [ ! -z "$TRIMMED_SOURCE_BOUNDS" ]
then
echo "Updating projection information"
# if defined set projection and bounds in netcdf file
gdal_translate \
-of NETCDF \
-a_srs $SOURCE_PROJECTION \
-a_ullr $TRIMMED_SOURCE_BOUNDS \
NETCDF:\"$file\":$VARIABLE \
$file
fi
gdalwarp \
-t_srs EPSG:4326 \
-te $OUT_BOUNDS \
-ts $RESOLUTION \
-r near \
--config GDAL_CACHEMAX 90% \
-co compress=LZW \
NETCDF:\"$file\":$VARIABLE \
./tmp.tif
gdaldem\
color-relief \
./tmp.tif \
./data/gdal-colors/colors-$VARIABLE.txt \
--config GDAL_CACHEMAX 90% \
-co compress=LZW \
-alpha ./colored.tif
if [ "$LAYER_TYPE" = "tiles" ]; then
gdal2tiles.py \
--profile geodetic \
--zoom=$ZOOM_LEVELS \
--tmscompatible \
--no-kml \
--webviewer=none \
--resampling average \
--s_srs EPSG:4326 \
./colored.tif /data/images/$VARIABLE/$timestamp_counter
else
mkdir -p /data/images/$VARIABLE/$timestamp_counter
gdal_translate \
-of PNG \
./colored.tif \
/data/images/$VARIABLE/$timestamp_counter/full.png
fi
rm ./tmp.tif
rm ./colored.tif
timestamp_counter=$((timestamp_counter+1))
done