-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpolygons.py
121 lines (96 loc) · 4.5 KB
/
polygons.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
"""
Creates a tessellating polygon data set:
counts of Coastline (Boundary), Islands and GNAF locality (Locality)
"""
import os
import argparse
from isotiles.tiles import Tiles
from utils import from_json_file, file_deploy, to_geojson_file, to_kml_file, \
to_shp_file, add_poly_nb
#from isotiles.visual import Visual
def hex(bounds_north, bounds_south, bounds_east, bounds_west,
theradial):
"""
Hexagons specific functions to create hexagon mapping layer
"""
theshape = 'hex'
t_mod = Tiles(shape=theshape, north=bounds_north,
south=bounds_south, east=bounds_east,
west=bounds_west, radial=theradial)
#u_mod = Util(shape=theshape, radial=theradial)
datasets = from_json_file('datasets.json',t_mod.json_files_path)
ref_data = datasets['DataSets']['Australia']['ShapeFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['AGILDataset']['CSVFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['MBSP']['CSVFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['NASAActiveFireData']['ModisC61km']['CSVFormat']
file_deploy(ref_data)
aus_hex_array = t_mod.hexagons()
nb_aus_hex_array = add_poly_nb(aus_hex_array,"p")
f_path_shp = os.path.join(t_mod.shape_files_path,'aus_{}_{}km_layer'.
format(theshape, str(int(theradial))))
f_path_kml = os.path.join(t_mod.kml_files_path,'aus_{}_{}km_layer'.
format(theshape, str(int(theradial))))
f_path_geojson = os.path.join(t_mod.geojson_files_path,'aus_{}_{}km_layer'.
format(theshape, str(int(theradial))))
to_shp_file(nb_aus_hex_array, f_path_shp)
to_kml_file(nb_aus_hex_array, f_path_kml,'Active_Fires')
to_geojson_file(nb_aus_hex_array, f_path_geojson)
def box(bounds_north, bounds_south, bounds_east, bounds_west, theradial):
"""
Boxes specific functions to create hexagon mapping
"""
theshape = 'box'
t_mod = Tiles(shape=theshape, north=bounds_north,
south=bounds_south, east=bounds_east,
west=bounds_west, radial=theradial)
#u_mod = Util(shape=theshape, radial=theradial)
datasets = from_json_file('datasets.json',t_mod.json_files_path)
ref_data = datasets['DataSets']['Australia']['ShapeFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['AGILDataset']['CSVFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['MBSP']['CSVFormat']
file_deploy(ref_data)
ref_data = datasets['DataSets']['NASAActiveFireData']['ModisC61km']['CSVFormat']
file_deploy(ref_data)
aus_box_array = t_mod.boxes()
nb_aus_box_array = add_poly_nb(aus_box_array,"p")
f_path_shp = os.path.join(t_mod.shape_files_path,
'aus_{}_{}km_layer'.format(theshape, str(int(theradial))))
f_path_kml = os.path.join(t_mod.kml_files_path,
'aus_{}_{}km_layer'.format(theshape, str(int(theradial))))
f_path_geojson = os.path.join(t_mod.geojson_files_path,
'aus_{}_{}km_layer'.format(theshape, str(int(theradial))))
to_shp_file(nb_aus_box_array, f_path_shp)
to_kml_file(nb_aus_box_array, f_path_kml, 'Active_Fires')
to_geojson_file(nb_aus_box_array, f_path_geojson)
PARSER = argparse.ArgumentParser(
prog='polygons',
description='''
Creates a tessellating polygon data set:
counts of Coastline (Boundary), Islands and GNAF locality (Locality)
''')
PARSER.add_argument('-bn', '--north', default=-8,
help="bounds north (-90 to 90)")
PARSER.add_argument('-bs', '--south', default=-45,
help="bounds south (-90 to 90)")
PARSER.add_argument('-be', '--east', default=169,
help="bounds east (-180 to 180)")
PARSER.add_argument('-bw', '--west', default=96,
help="bounds west (-180 to 180)")
PARSER.add_argument('-rl', '--radial', default=59,
help="radial length in km")
PARSER.add_argument('-sh', '--shape', default='hex',
help="shape (hex or box)")
ARGS = PARSER.parse_args()
#test(float(ARGS.north), float(ARGS.south), float(ARGS.east),
# float(ARGS.west), float(ARGS.radial))
if ARGS.shape == 'hex':
hex(float(ARGS.north), float(ARGS.south), float(ARGS.east),
float(ARGS.west), float(ARGS.radial))
if ARGS.shape == "box":
box(float(ARGS.north), float(ARGS.south), float(ARGS.east),
float(ARGS.west), float(ARGS.radial))