-
Notifications
You must be signed in to change notification settings - Fork 2
/
poly_wt.py
203 lines (170 loc) · 8.28 KB
/
poly_wt.py
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
"""
Script used to postprocess the polygon data set
Tabular data appended to existing polygon data set:
ABS Census polygon data intersecting polygon weighted data and
OpenStreetMaps points of interest
"""
import argparse
from isotiles.postprocess import PostProcess
from utils import from_json_file, file_deploy
def area_wt(the_shape, the_radial):
"""
Area based weighting used to post process the polygon data set
:param: the_shape
:param: the_radial
"""
p_mod = PostProcess(shape=the_shape, radial=the_radial)
#u_mod = Util(shape=the_shape, radial=the_radial)
shape_and_size = p_mod.shape +'_' + str(p_mod.radial)
aust_shape_file_name = 'aust_' + p_mod.shape +'_shape_' + \
str(p_mod.radial) +'km'
gj_name = 'aus_' + shape_and_size + 'km_layer'
vrt_ref = 'all_' + shape_and_size
vrt_file = 'all_' + shape_and_size + '.vrt'
feat_sa1_11 = 'feat_aust_' + str(p_mod.radial) +'km_sa1_11'
feat_sa1_16 = 'feat_aust_' + str(p_mod.radial) +'km_sa1_16'
db_name = 'db_area_' + shape_and_size
tabular_sql_name = 'tabular_area_wt_' + shape_and_size + '.txt'
output_shape = shape_and_size + 'km_area_11_16'
p_mod.vrt_shape_and_size('vrt', 'template.vrt', vrt_file)
p_mod.do_spatialite('table_goes_here.txt', db_name)
datasets = from_json_file('datasets', p_mod.json_files_path, p_mod.slash)
ref_data = datasets['DataSets']['Australia']['ShapeFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['StatisticalAreasLevel12011']['ShapeFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['StatisticalAreasLevel12016']['ShapeFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['AGILDataset']['CSVFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['OpenStreetMaps']['ShapeFormat']
file_deploy(ref_data)
print('aust_shape')
p_mod.geojson_to_shp(gj_name, aust_shape_file_name, 4283)
p_mod.shp_to_db(aust_shape_file_name, db_name, aust_shape_file_name, 4823)
print('feat_aust_11_area')
p_mod.sql_to_ogr('feat_aust_11', vrt_ref, feat_sa1_11)
p_mod.shp_to_db(feat_sa1_11, db_name, feat_sa1_11, 4823)
print('feat_aust_16_area')
p_mod.sql_to_ogr('feat_aust_16', vrt_ref, feat_sa1_16)
p_mod.shp_to_db(feat_sa1_16, db_name, feat_sa1_16, 4823)
print('tabular_area_wt')
p_mod.csv_to_db('2011Census_B18_AUST_SA1_long', db_name,\
'2011Census_B18_AUST_SA1_long')
p_mod.csv_to_db('2011Census_B21_AUST_SA1_long', db_name,\
'2011Census_B21_AUST_SA1_long')
p_mod.csv_to_db('2011Census_B22B_AUST_SA1_long', db_name,\
'2011Census_B22B_AUST_SA1_long')
p_mod.csv_to_db('2016Census_G18_AUS_SA1', db_name,\
'2016Census_G18_AUS_SA1')
p_mod.csv_to_db('2016Census_G21_AUS_SA1', db_name,\
'2016Census_G21_AUS_SA1')
p_mod.csv_to_db('2016Census_G22B_AUS_SA1', db_name,\
'2016Census_G22B_AUS_SA1')
p_mod.shp_to_db(aust_shape_file_name, db_name, aust_shape_file_name, 4823)
p_mod.shp_to_db(feat_sa1_11, db_name, feat_sa1_11, 4823)
p_mod.shp_to_db(feat_sa1_16, db_name, feat_sa1_16, 4823)
p_mod.shp_to_db('gis_osm_places_free_1', db_name,\
'gis_osm_places_free_1', 4823)
p_mod.shp_to_db('gis_osm_roads_free_1', db_name,\
'gis_osm_roads_free_1', 4823)
p_mod.sql_to_ogr('shape_pois_shp', vrt_ref, 'POI')
p_mod.shp_to_db('POI', db_name, 'POI', 4823)
p_mod.shape_and_size('spatialite_db', 'tabular_area_wt.txt', \
tabular_sql_name)
p_mod.do_spatialite(tabular_sql_name, db_name)
print('shape_11_16_area')
p_mod.sql_to_ogr('shape_11_16_area', vrt_ref, output_shape)
p_mod.shp_to_geojson(output_shape, output_shape)
p_mod.shp_to_kml(output_shape, output_shape)
def place_wt(the_shape, the_radial):
"""
Place count based weighting used to post process the polygon data set
:param: the_shape
:param: the_radial
"""
p_mod = PostProcess(shape=the_shape, radial=the_radial)
#u_mod = Util(shape=the_shape, radial=the_radial)
shape_and_size = p_mod.shape +'_' + str(p_mod.radial)
aust_shape_file_name = 'aust_' + p_mod.shape +'_shape_' + \
str(p_mod.radial) +'km'
gj_name = 'aus_' + shape_and_size + 'km_layer'
vrt_ref = 'all_' +shape_and_size
vrt_file = 'all_' + shape_and_size + '.vrt'
feat_sa1_11 = 'feat_aust_' + str(p_mod.radial) +'km_sa1_11'
feat_sa1_16 = 'feat_aust_' + str(p_mod.radial) +'km_sa1_16'
db_name = 'db_place_' + shape_and_size
tabular_sql_name = 'tabular_place_wt_' + shape_and_size + '.txt'
output_shape = shape_and_size + 'km_place_11_16'
p_mod.vrt_shape_and_size('vrt', 'template.vrt', vrt_file)
p_mod.do_spatialite('table_goes_here.txt', db_name)
datasets = from_json_file('datasets', p_mod.json_files_path, p_mod.slash)
ref_data = datasets['DataSets']['Australia']['ShapeFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['StatisticalAreasLevel12011']['ShapeFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['StatisticalAreasLevel12016']['ShapeFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['AGILDataset']['CSVFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['OpenStreetMaps']['ShapeFormat']
file_deploy(ref_data)
#ref_files_poly_wt('datasets',p_mod.json_files_path, p_mod.slash)
print('aust_shape')
p_mod.geojson_to_shp(gj_name, aust_shape_file_name, 4283)
p_mod.shp_to_db(aust_shape_file_name, db_name, aust_shape_file_name, 4823)
print('feat_aust_11_area')
p_mod.sql_to_ogr('feat_aust_11', vrt_ref, feat_sa1_11)
p_mod.shp_to_db(feat_sa1_11, db_name, feat_sa1_11, 4823)
print('feat_aust_16_area')
p_mod.sql_to_ogr('feat_aust_16', vrt_ref, feat_sa1_16)
p_mod.shp_to_db(feat_sa1_16, db_name, feat_sa1_16, 4823)
print('tabular_place_wt')
p_mod.csv_to_db('2011Census_B18_AUST_SA1_long',\
db_name, '2011Census_B18_AUST_SA1_long')
p_mod.csv_to_db('2011Census_B21_AUST_SA1_long',\
db_name, '2011Census_B21_AUST_SA1_long')
p_mod.csv_to_db('2011Census_B22B_AUST_SA1_long',\
db_name, '2011Census_B22B_AUST_SA1_long')
p_mod.csv_to_db('2016Census_G18_AUS_SA1',\
db_name, '2016Census_G18_AUS_SA1')
p_mod.csv_to_db('2016Census_G21_AUS_SA1',\
db_name, '2016Census_G21_AUS_SA1')
p_mod.csv_to_db('2016Census_G22B_AUS_SA1',\
db_name, '2016Census_G22B_AUS_SA1')
file_name = 'aust_{shape}_shape_{size}km'.\
format(shape=p_mod.shape,\
size=p_mod.radial)
p_mod.shp_to_db(file_name, db_name, file_name, 4823)
p_mod.shp_to_db(feat_sa1_11, db_name, feat_sa1_11, 4823)
p_mod.shp_to_db(feat_sa1_16, db_name, feat_sa1_16, 4823)
p_mod.shp_to_db('gis_osm_places_free_1',\
db_name, 'gis_osm_places_free_1', 4823)
p_mod.shp_to_db('gis_osm_roads_free_1',\
db_name, 'gis_osm_roads_free_1', 4823)
p_mod.sql_to_ogr('shape_pois_shp', vrt_ref, 'POI')
p_mod.shp_to_db('POI', db_name, 'POI', 4823)
p_mod.shape_and_size('spatialite_db', 'tabular_place_wt.txt',\
tabular_sql_name)
p_mod.do_spatialite(tabular_sql_name, db_name)
print('shape_11_16_place')
p_mod.sql_to_ogr('shape_11_16_place', vrt_ref, output_shape)
p_mod.shp_to_geojson(output_shape, output_shape)
p_mod.shp_to_kml(output_shape, output_shape)
PARSER = argparse.ArgumentParser(
prog='poly_wt',
description='''
Tabular data appended to existing polygon data set:
ABS Census polygon data intersecting polygon weighted data and
OpenStreetMaps points of interest''')
PARSER.add_argument('-rl', '--radial', default=57, help="radial length in km")
PARSER.add_argument('-wt', '--weight', default='place',
help="polygon intersection weight variable (place or area)")
PARSER.add_argument('-sh', '--shape', default='hex', help="shape (hex or box)")
ARGS = PARSER.parse_args()
if ARGS.weight == 'place':
place_wt(ARGS.shape, ARGS.radial)
if ARGS.weight == 'area':
area_wt(ARGS.shape, ARGS.radial)
else:
print('weight is place or area')