-
Notifications
You must be signed in to change notification settings - Fork 1
/
importBoundaries.sh
154 lines (137 loc) · 4.47 KB
/
importBoundaries.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
#!/usr/bin/env bash
echo $BASH_VERSION
# change to the directory this script is located in
cd "$(dirname "$0")"
# the postgres database name.
DB_NAME=false
ASGS_VOL_1_LOCATION=false
ASGS_VOL_4_LOCATION=false
# Display help
function show_help()
{
echo "USAGE: importBoundaries.sh [OPTIONS]... "
echo "This script creates the database and its schemas."
echo "OPTIONS are:"
echo " -h, --help | Display this help message "
echo " -d, --database=DB_NAME | Database name "
echo " -1, --asgs_vol_1=ASGS_VOL_1_LOCATION | Location of ASGS volume 1 gpkg"
echo " -4, --asgs_vol_4=ASGS_VOL_4_LOCATION | Location of ASGS volume 4 gpkg"
}
# Parse command line arguments
for arg in "$@"
do
case "$arg" in
-h | --help ) show_help; exit 0 ;;
-d=* | --database=* ) DB_NAME="${arg#*=}" ;;
-1=* | --asgs_vol_1=* ) ASGS_VOL_1_LOCATION="${arg#*=}" ;;
-4=* | --asgs_vol_4=* ) ASGS_VOL_4_LOCATION="${arg#*=}" ;;
*) echo "Invalid option: $arg" >&2; show_help; exit 1 ;;
esac
done
if [ "$DB_NAME" = false ] ; then
echo 'No database name supplied'
show_help
exit
fi
if [ "$ASGS_VOL_1_LOCATION" = false ] ; then
echo 'No ASGS volume 1 geopackage location supplied'
show_help
exit
fi
if [ "$ASGS_VOL_4_LOCATION" = false ] ; then
echo 'No ASGS volume 4 geopackage location supplied'
show_help
exit
fi
#DB_NAME="jibe"
#ASGS_VOL_1_LOCATION="/Users/alan/Projects/JIBE/networkMelbourne/network/data/ASGS_volume_1.sqlite"
#ASGS_VOL_4_LOCATION="/Users/alan/Projects/JIBE/networkMelbourne/network/data/ASGS_volume_4.sqlite"
createdb -U postgres ${DB_NAME}
psql -c 'CREATE EXTENSION IF NOT EXISTS postgis' ${DB_NAME} postgres
# import all meshblocks
ogr2ogr \
-nln mb_import \
-lco OVERWRITE=YES \
-dim XY \
-f "PostgreSQL" \
PG:"host=localhost port=5432 user=postgres dbname=${DB_NAME}" \
-a_srs "EPSG:4326" \
-nlt PROMOTE_TO_MULTI \
-dialect SQLite -sql \
"SELECT CAST(mb_code_2016 AS DOUBLE PRECISION) AS mb_code, \
mb_category_name_2016 AS category, \
CAST(sa1_maincode_2016 AS DOUBLE PRECISION) AS sa1_code, \
mb_category_name_2016, geom FROM MB_2016_AUST" \
"$ASGS_VOL_1_LOCATION"
# import SA1
ogr2ogr \
-nln sa1 \
-lco OVERWRITE=YES \
-dim XY \
-f "PostgreSQL" \
PG:"host=localhost port=5432 user=postgres dbname=${DB_NAME}" \
-a_srs "EPSG:4326" \
-nlt PROMOTE_TO_MULTI \
-dialect SQLite -sql \
"SELECT CAST(sa1_maincode_2016 AS DOUBLE PRECISION) AS sa1_code,
geom FROM SA1_2016_AUST
WHERE GCCSA_NAME_2016 LIKE 'Greater Melbourne' " \
"$ASGS_VOL_1_LOCATION"
# import SA2
ogr2ogr \
-nln sa2 \
-lco OVERWRITE=YES \
-dim XY \
-f "PostgreSQL" \
PG:"host=localhost port=5432 user=postgres dbname=${DB_NAME}" \
-a_srs "EPSG:4326" \
-nlt PROMOTE_TO_MULTI \
-dialect SQLite -sql \
"SELECT CAST(sa2_maincode_2016 AS DOUBLE PRECISION) AS sa2_code,
geom FROM SA2_2016_AUST
WHERE GCCSA_NAME_2016 LIKE 'Greater Melbourne' " \
"$ASGS_VOL_1_LOCATION"
# import SA3
ogr2ogr \
-nln sa3 \
-lco OVERWRITE=YES \
-dim XY \
-f "PostgreSQL" \
PG:"host=localhost port=5432 user=postgres dbname=${DB_NAME}" \
-a_srs "EPSG:4326" \
-nlt PROMOTE_TO_MULTI \
-dialect SQLite -sql \
"SELECT CAST(sa3_code_2016 AS DOUBLE PRECISION) AS sa3_code,
geom FROM SA3_2016_AUST
WHERE GCCSA_NAME_2016 LIKE 'Greater Melbourne' " \
"$ASGS_VOL_1_LOCATION"
# import SOS (sections of state, i.e. our urban areas)
ogr2ogr \
-nln sos \
-lco OVERWRITE=YES \
-dim XY \
-f "PostgreSQL" \
PG:"host=localhost port=5432 user=postgres dbname=${DB_NAME}" \
-a_srs "EPSG:4326" \
-nlt PROMOTE_TO_MULTI \
-dialect SQLite -sql \
"SELECT CAST(SOS_CODE_2016 AS DOUBLE PRECISION) AS sos_code,
SOS_NAME_2016 AS sos_name, geom FROM SOS_2016_AUST
WHERE SOS_NAME_2016 IN ('Major Urban','Other Urban') AND
STATE_NAME_2016 ='Victoria'" \
"$ASGS_VOL_4_LOCATION"
# import study region (Greater Melbourne)
ogr2ogr \
-nln region \
-lco OVERWRITE=YES \
-dim XY \
-f "PostgreSQL" \
PG:"host=localhost port=5432 user=postgres dbname=${DB_NAME}" \
-a_srs "EPSG:4326" \
-nlt PROMOTE_TO_MULTI \
-dialect SQLite -sql \
"SELECT 'Melbourne' AS locale, geom FROM GCCSA_2016_AUST \
WHERE GCCSA_NAME_2016 LIKE 'Greater Melbourne' " \
"$ASGS_VOL_1_LOCATION"
# run the sql that processes the data
psql -U postgres -d ${DB_NAME} -a -f importBoundaries.sql