forked from jlmcgraw/aviationCharts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mergeCharts.sh
executable file
·485 lines (429 loc) · 11.6 KB
/
mergeCharts.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
#!/bin/bash
set -eu # Die on errors and unbound variables
IFS=$(printf '\n\t') # IFS is newline or tab
#Some other possible software options for tiling pipeline
#https://github.com/makinacorpus/landez.git
#https://github.com/ecometrica/gdal2mbtiles
#https://github.com/mj10777/gdal2mbtiles.git
main() {
# Get parameters
sourceRoot="$1"
destinationRoot="$2"
# Where are the individual tiled charts stored
srcDir="${sourceRoot}/6_tiles"
# Where to put merged tiled charts (each in its own directory
destDir="${destinationRoot}/merged_tiled_charts"
# Check that the source base directory exists
if [ ! -d "$srcDir" ]; then
echo "$srcDir doesn't exist"
exit 1
fi
# Check that the destination base directory exists
if [ ! -d "$destDir" ]; then
echo "$destDir doesn't exist"
exit 1
fi
# VFR Charts sorted by scale, highest to lowest
vfr_chart_list=(
U_S_VFR_Wall_Planning_Chart
Alaska_Wall_Planning_Chart
Caribbean_1_VFR_Chart
Caribbean_2_VFR_Chart
Albuquerque_SEC
Anchorage_SEC
Atlanta_SEC
Bethel_SEC
Billings_SEC
Brownsville_SEC
Cape_Lisburne_SEC
Charlotte_SEC
Cheyenne_SEC
Chicago_SEC
Cincinnati_SEC
Cold_Bay_SEC
Dallas_Ft_Worth_SEC
Dawson_SEC
Denver_SEC
Detroit_SEC
Dutch_Harbor_SEC
El_Paso_SEC
Fairbanks_SEC
Great_Falls_SEC
Green_Bay_SEC
Halifax_SEC
Hawaiian_Islands_SEC
Houston_SEC
Jacksonville_SEC
Juneau_SEC
Kansas_City_SEC
Ketchikan_SEC
Klamath_Falls_SEC
Kodiak_SEC
Lake_Huron_SEC
Las_Vegas_SEC
Los_Angeles_SEC
Mariana_Islands_Inset_SEC
McGrath_SEC
Memphis_SEC
Miami_SEC
Montreal_SEC
New_Orleans_SEC
New_York_SEC
Nome_SEC
Omaha_SEC
Phoenix_SEC
Point_Barrow_SEC
Salt_Lake_City_SEC
Samoan_Islands_Inset_SEC
San_Antonio_SEC
San_Francisco_SEC
Seattle_SEC
Seward_SEC
St_Louis_SEC
Twin_Cities_SEC
Washington_SEC
Western_Aleutian_Islands_East_SEC
Western_Aleutian_Islands_West_SEC
Whitehorse_SEC
Wichita_SEC
Anchorage_TAC
Atlanta_TAC
Baltimore_Washington_TAC
Boston_TAC
Charlotte_TAC
Chicago_TAC
Cincinnati_TAC
Cleveland_TAC
Colorado_Springs_TAC
Dallas_Ft_Worth_TAC
Denver_TAC
Detroit_TAC
Dutch_Harbor_Inset
Fairbanks_TAC
Grand_Canyon_Air_Tour_Operators
Grand_Canyon_General_Aviation
Honolulu_Inset_SEC
Houston_TAC
Jacksonville_Inset
Juneau_Inset
Kansas_City_TAC
Ketchikan_Inset
Kodiak_Inset
Las_Vegas_TAC
Los_Angeles_TAC
Memphis_TAC
Miami_TAC
Minneapolis_St_Paul_TAC
New_Orleans_TAC
New_York_TAC
Norfolk_Inset
Orlando_TAC
Philadelphia_TAC
Phoenix_TAC
Pittsburgh_TAC
Pribilof_Islands_Inset
Puerto_Rico_VI_TAC
Salt_Lake_City_TAC
San_Diego_TAC
San_Francisco_TAC
Seattle_TAC
St_Louis_TAC
Tampa_TAC
)
# IFR-LOW Charts sorted by scale, highest to lowest
ifr_low_chart_list=(
US_IFR_PLAN_EAST
US_IFR_PLAN_WEST
ENR_CL03
ENR_CL02
ENR_CL05
ENR_CL01
ENR_AKL01
ENR_AKL02C
ENR_AKL02E
ENR_AKL02W
ENR_AKL03
ENR_AKL04
ENR_CL06
ENR_L21
Mexico_City_Area
Miami_Nassau
Lima_Area
Guatemala_City_Area
Dominican_Republic_Puerto_Rico_Area
ENR_L13
Bogota_area
ENR_AKL01_JNU
ENR_L09
ENR_L11
ENR_L12
ENR_L14
ENR_L32
ENR_P02
Buenos_Aires_Area
ENR_L10
ENR_L31
Santiago_Area
ENR_AKL04_ANC
ENR_AKL03_FAI
ENR_AKL03_OME
ENR_L05
ENR_L06N
ENR_L06S
ENR_L08
ENR_L15
ENR_L16
ENR_L17
ENR_L18
ENR_L19
ENR_L20
ENR_L22
ENR_L23
ENR_L24
ENR_L27
ENR_L28
Rio_De_Janeiro_Area
ENR_A02_PHX
ENR_AKL01_VR
ENR_L01
ENR_L02
ENR_L03
Panama_Area
ENR_A01_DCA
ENR_A02_DEN
ENR_L04
ENR_L07
ENR_L25
ENR_L26
ENR_L29
ENR_L30
ENR_L33
ENR_L34
ENR_L35
ENR_L36
ENR_A01_ATL
ENR_A01_JAX
ENR_A01_MIA
ENR_A01_MSP
ENR_A01_STL
ENR_A02_DFW
ENR_A02_ORD
ENR_A02_SFO
ENR_A01_DET
ENR_A02_LAX
ENR_A02_MKC
)
# IFR-HIGH Charts sorted by scale, highest to lowest
ifr_high_chart_list=(
ENR_AKH01
ENR_AKH02
ENR_AKH01_SEA
ENR_H01
ENR_H02
ENR_H03
ENR_H04
ENR_H05
ENR_H06
ENR_H07
ENR_H08
ENR_H09
ENR_H10
ENR_H11
ENR_H12
)
# Helicopter charts sorted by scale, highest to lowest
heli_chart_list=(
U_S_Gulf_Coast_HEL
Eastern_Long_Island_HEL
Baltimore_HEL
Boston_HEL
Chicago_HEL
Dallas_Ft_Worth_HEL
Detroit_HEL
Houston_North_HEL
Houston_South_HEL
Los_Angeles_East_HEL
Los_Angeles_West_HEL
New_York_HEL
Washington_HEL
Chicago_O_Hare_Inset_HEL
Dallas_Love_Inset_HEL
Washington_Inset_HEL
Boston_Downtown_HEL
Downtown_Manhattan_HEL
)
#-------------------------------------------------------------------------------
# VFR
if [ -n "$should_create_vfr" ]
then
# What type of merged chart are we making
chart_type="VFR"
# Where will the merged tiles be stored
merged_tiles_directory="${destDir}/${chart_type}"
# The name of the mbtiles file to create from the merged tiles
mbtiles_file_name="${merged_tiles_directory}.mbtiles"
echo "Cleaning $merged_tiles_directory"
rm --force --recursive --dir "$merged_tiles_directory"
for chart in "${vfr_chart_list[@]}"
do
echo "${chart_type}: $chart"
individual_tiled_chart_directory="${srcDir}/${chart}.tms/"
# Merge the individual charts into an overall chart
./merge_tile_sets.pl \
"$individual_tiled_chart_directory" \
"$merged_tiles_directory"
done
# Optimize the tiled png files
./pngquant_all_files_in_directory.sh "$merged_tiles_directory"
if [ -n "$should_create_mbtiles" ]
then
# Remove the existing mbtiles
rm --force "$mbtiles_file_name"
# Package tiles into an .mbtiles file
./memoize.py \
-i "$merged_tiles_directory" \
-d "$destDir" \
python ./mbutil/mb-util \
--scheme=tms \
"$merged_tiles_directory" \
"$mbtiles_file_name"
fi
# Copy leaflet and the simple viewer to our tiled directory
cp -r ./leaflet/* "$merged_tiles_directory"
fi
#-------------------------------------------------------------------------------
# IFR LOW
if [ -n "$should_create_ifr_low" ]
then
echo "Cleaning $destDir/IFR-LOW"
rm --force --recursive --dir "$destDir/IFR-LOW"
for chart in "${ifr_low_chart_list[@]}"
do
echo "IFR LOW: $chart "
# Merge the individual charts into an overall chart
./merge_tile_sets.pl \
"${srcDir}/${chart}.tms/" \
"${destDir}/IFR-LOW"
done
# Optimize the tiled png files
./pngquant_all_files_in_directory.sh "${destDir}/IFR-LOW"
if [ -n "$should_create_mbtiles" ]
then
# Remove the existing mbtiles
rm --force "${destDir}/IFR-LOW.mbtiles"
# Package tiles into an .mbtiles file
./memoize.py -i "$destDir" -d "$destDir" \
python ./mbutil/mb-util \
--scheme=tms \
"${destDir}/IFR-LOW" \
"${destDir}/IFR-LOW.mbtiles"
fi
# Copy leaflet and the simple viewer to our tiled directory
cp -r ./leaflet/* "$destDir/IFR-LOW"
fi
#-------------------------------------------------------------------------------
# IFR HIGH
if [ -n "$should_create_ifr_high" ]
then
echo "Cleaning $destDir/IFR-HIGH"
rm --force --recursive --dir "$destDir/IFR-HIGH"
for chart in "${ifr_high_chart_list[@]}"
do
echo "IFR HIGH: $chart "
# Merge the individual charts into an overall chart
./merge_tile_sets.pl \
"${srcDir}/${chart}.tms/" \
"${destDir}/IFR-HIGH"
done
# Optimize the tiled png files
./pngquant_all_files_in_directory.sh "${destDir}/IFR-HIGH"
if [ -n "$should_create_mbtiles" ]
then
# Remove the existing mbtiles
rm --force "${destDir}/IFR-HIGH.mbtiles"
# Package tiles into an .mbtiles file
./memoize.py -i "$destDir" -d "$destDir" \
python ./mbutil/mb-util \
--scheme=tms \
"${destDir}/IFR-HIGH" \
"${destDir}/IFR-HIGH.mbtiles"
fi
# Copy leaflet and the simple viewer to our tiled directory
cp -r ./leaflet/* "$destDir/IFR-HIGH"
fi
#-------------------------------------------------------------------------------
# Heli
if [ -n "$should_create_heli" ]
then
echo "Cleaning $destDir/IFR-HELI"
rm --force --recursive --dir "$destDir/HELI"
for chart in "${heli_chart_list[@]}"
do
echo "HELI: $chart "
#Merge the individual charts into an overall chart
./merge_tile_sets.pl \
"${srcDir}/${chart}.tms/" \
"${destDir}/HELI"
done
# Optimize the tiled png files
./pngquant_all_files_in_directory.sh "${destDir}/HELI"
if [ -n "$should_create_mbtiles" ]
then
# Remove the existing mbtiles
rm --force "${destDir}/HELI.mbtiles"
# Package tiles into an .mbtiles file
./memoize.py -i "$destDir" -d "$destDir" \
python ./mbutil/mb-util \
--scheme=tms \
"${destDir}/HELI" \
"${destDir}/HELI.mbtiles"
fi
# Copy leaflet and the simple viewer to our tiled directory
cp -r ./leaflet/* "$destDir/HELI"
fi
exit 0
}
function USAGE {
echo "Usage: $0 <SOURCE_BASE_DIRECTORY> <DESTINATION_BASE_DIRECTORY>" >&2
echo " -v Create merged VFR"
echo " -h Create merged IFR-HIGH"
echo " -l Create merged IFR-LOW"
echo " -c Create merged HELICOPTER"
echo " -m Create mbtiles for each chart"
exit 1
}
# The script begins here
# Set some basic variables
declare -r PROGNAME=$(basename "$0")
declare -r PROGDIR=$(readlink -m "$(dirname "$0")")
declare -r ARGS="$@"
# Set fonts for Help.
declare -r NORM=$(tput sgr0)
declare -r BOLD=$(tput bold)
declare -r REV=$(tput smso)
should_create_vfr=''
should_create_ifr_high=''
should_create_ifr_low=''
should_create_heli=''
should_create_mbtiles=''
while getopts 'vhlcm' flag; do
case "${flag}" in
v) should_create_vfr='true' ;;
h) should_create_ifr_high='true' ;;
l) should_create_ifr_low='true' ;;
c) should_create_heli='true' ;;
m) should_create_mbtiles='true' ;;
*) error "Unexpected option ${flag}" ;;
esac
done
# Remove the flag operands
shift $((OPTIND-1))
#Get the number of remaining command line arguments
NUMARGS=$#
# Validate number of command line parameters
if [ "$NUMARGS" -ne 2 ] ; then
USAGE
fi
# Call the main routine
main "$@"
exit 0