-
Notifications
You must be signed in to change notification settings - Fork 33
/
rasterize_Caribbean_charts.sh
executable file
·104 lines (85 loc) · 3.36 KB
/
rasterize_Caribbean_charts.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
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -eu # Always put this in Bourne shell scripts
IFS=$(printf '\n\t') # Always put this in Bourne shell scripts
shopt -s nullglob
#1. Get Caribbean charts from https://www.faa.gov/air_traffic/flight_info/aeronav/digital_products/ifr/#caribbean
#2. Unzip the PDFs
# unzip "*.zip"
if [ "$#" -ne 3 ] ; then
echo "Usage: $0 <SOURCE_DIRECTORY> <destinationRoot> <chartType>" >&2
exit 1
fi
#Get command line parameters
originalRastersDirectory="$1"
destinationRoot="$2"
chartType="$3"
output_raster_path="${destinationRoot}/2_normalized/"
if [ ! -d "$originalRastersDirectory" ]; then
echo "$originalRastersDirectory doesn't exist"
exit 1
fi
if [ ! -d "$output_raster_path" ]; then
echo "$output_raster_path doesn't exist"
exit 1
fi
#Get our initial directory as it is where memoize.py is located
pushd "$(dirname "$0")" > /dev/null
installedDirectory=$(pwd)
popd > /dev/null
echo "Change directory to $originalRastersDirectory"
cd "$originalRastersDirectory"
# Ignore unzipping errors
set +e
# Unzip the Caribbean PDFs
echo "Unzipping $chartType files for Caribbean"
unzip -qq -u -j "delcb*.zip" "*.pdf"
# Restore quit on error
set -e
# Convert them to .tiff
for f in ENR_C[AL]0[0-9].pdf
do
if [ -f "$f.tif" ]
then
echo "Rasterized $f already exists"
continue
fi
echo "--------------------------------------------"
echo "Converting $f to raster"
echo "--------------------------------------------"
# Needs to point to where memoize is
"${installedDirectory}/memoize.py" -t \
gs \
-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT \
-sDEVICE=tiff24nc \
-sOutputFile="$output_raster_path/$f-untiled.tif" \
-r300 \
-dTextAlphaBits=4 \
-dGraphicsAlphaBits=4 \
"$f"
echo "--------------------------------------------"
echo "Tile $f"
echo "--------------------------------------------"
# Needs to point to where memoize is
"$installedDirectory/memoize.py" -t \
gdal_translate \
-strict \
-co TILED=YES \
-co COMPRESS=LZW \
"$output_raster_path/$f-untiled.tif" \
"$output_raster_path/$f.tif"
echo "--------------------------------------------"
echo "Overviews $f"
echo "--------------------------------------------"
# Needs to point to where memoize is
"$installedDirectory/memoize.py" -t \
gdaladdo \
-ro \
-r gauss \
--config INTERLEAVE_OVERVIEW PIXEL \
--config COMPRESS_OVERVIEW JPEG \
--config BIGTIFF_OVERVIEW IF_NEEDED \
"$output_raster_path/$f.tif" \
2 4 8 16 32 64
# rm "$output_raster_path/$f-untiled.tif"
done
exit 0