forked from jlmcgraw/processFaaData
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_databases.sh
executable file
·146 lines (121 loc) · 4.71 KB
/
create_databases.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
#!/bin/bash
set -eu # Always put this in Bourne shell scripts
IFS=$(printf '\n\t') # Always put this in Bourne shell scripts
# Where to save files we create
outputdir=.
# Check count of command line parameters
if [ "$#" -ne 1 ] ; then
echo "Usage: $0 28_Day_Subscription_Zip_file" >&2
echo "eg. $0 28DaySubscription_Effective_2017-06-22.zip" >&2
echo " Download most recent data from https://nfdc.faa.gov/xwiki/bin/view/NFDC/28+Day+NASR+Subscription" >&2
exit 1
fi
# Get command line parameters
nasr28dayFileName=$1
if [ ! -f "$nasr28dayFileName" ]; then
echo "No 28-day source zip file found" >&2
exit 1
fi
# Get command line parameter and construct the full path to the unzipped data
datadir=$(readlink -m "$(dirname "$nasr28dayFileName")")
datadir+="/"
datadir+=$(basename "$nasr28dayFileName" .zip)
datadir+="/"
readonly nasr_database="$outputdir/nasr.sqlite"
readonly nasr_spatialite_database="$outputdir/spatialite_nasr.sqlite"
readonly controlled_airspace_spatialite_database="$outputdir/controlled_airspace_spatialite.sqlite"
readonly special_use_airspace_spatialite_database="$outputdir/special_use_airspace_spatialite.sqlite"
# Location of airspace files
sua_input_directory=$datadir/Additional_Data/AIXM/SAA-AIXM_5_Schema/SaaSubscriberFile/SaaSubscriberFile/Saa_Sub_File
controlled_airspace_input_directory=$datadir/Additional_Data/Shape_Files
#-------------------------------------------------------------------------------
# Recursively unzip NASR .zip file to $datadir
echo "---------- Recursively unzipping $nasr28dayFileName"
./recursiveUnzip.sh "$nasr28dayFileName"
if [ ! -d "$sua_input_directory" ]; then
echo "No Special Use Airspace information found in ${sua_input_directory}" >&2
exit 1
fi
if [ ! -d "$controlled_airspace_input_directory" ]; then
echo "No Controlled Airspace information found in ${controlled_airspace_input_directory}" >&2
exit 1
fi
# Delete any existing files
rm --force "$nasr_database"
rm --force "$nasr_spatialite_database"
rm --force ./DAILY_DOF.ZIP ./DOF.DAT
rm --force "$controlled_airspace_spatialite_database"
rm --force "$special_use_airspace_spatialite_database"
# Get the daily obstacle file
echo "---------- Download and process daily obstacle file"
wget --timestamping http://tod.faa.gov/tod/DAILY_DOF.ZIP
unzip DAILY_DOF.ZIP
# Remove the header lines from obstacle file and put output in $datadir as "OBSTACLE.txt"
sed '1,4d' ./DOF.DAT > $datadir/OBSTACLE.txt
echo "---------- Create the database"
# Create the new sqlite database
# options for Create geometry and expand text
./parse_nasr.pl -g -e "$datadir" "$nasr_database"
echo "---------- Adding indexes"
# Add indexes
sqlite3 "$nasr_database" < add_indexes.sql
echo "---------- Create the spatialite version of database"
cp "$nasr_database" "$nasr_spatialite_database"
# Convert the copy to spatialite
set +e
sqlite3 "$nasr_spatialite_database" < sqlite_to_spatialite.sql
set -e
# Lump the airspaces into spatialite databases
echo "---------- Convert controlled and special use airspaces into spatialite databases"
# GML related environment variables for the conversion
export GML_FETCH_ALL_GEOMETRIES=YES
export GML_SKIP_RESOLVE_ELEMS=NONE
# dbfile=SpecialUseAirspace.sqlite
#if [ -e $outputdir/$dbfile ]; then (rm $outputdir/$dbfile) fi
find "$sua_input_directory" \
-iname "*.xml" \
-type f \
-print \
-exec ogr2ogr \
-f SQLite \
"$special_use_airspace_spatialite_database" \
{} \
-explodecollections \
-a_srs WGS84 \
-update \
-append \
-wrapdateline \
-fieldTypeToString ALL \
-dsco SPATIALITE=YES \
-skipfailures \
-lco SPATIAL_INDEX=YES \
-lco LAUNDER=NO \
--config OGR_SQLITE_SYNCHRONOUS OFF \
--config OGR_SQLITE_CACHE 128 \
-gt 65536 \
\;
ogrinfo "$special_use_airspace_spatialite_database" -sql "VACUUM"
# dbfile=ControlledAirspace.sqlite
#if [ -e $outputdir/$dbfile ]; then (rm $outputdir/$dbfile) fi
find "$controlled_airspace_input_directory" \
-iname "*.shp" \
-type f \
-print \
-exec ogr2ogr \
-f SQLite \
"$controlled_airspace_spatialite_database" \
{} \
-explodecollections \
-update \
-append \
-wrapdateline \
-dsco SPATIALITE=YES \
-skipfailures \
-lco SPATIAL_INDEX=YES \
-lco LAUNDER=NO \
--config OGR_SQLITE_SYNCHRONOUS OFF \
--config OGR_SQLITE_CACHE 128 \
-gt 65536 \
\;
# Vacuum the database if needed
ogrinfo "$controlled_airspace_spatialite_database" -sql "VACUUM"