-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-polygons-heights.py
40 lines (29 loc) · 979 Bytes
/
add-polygons-heights.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
import json
from turfpy.measurement import boolean_point_in_polygon
from geojson import Point, Polygon, Feature
import random
f = open('data/add-polygon-heights/input.geojson', encoding='utf-8')
data = json.load(f)
count = 0
newFeatures = []
for feature in data['features']:
count += 1
insert = True
geometry = feature['geometry']
coordinates = geometry['coordinates']
if geometry['type'] != 'Polygon':
newFeatures.append(feature)
continue
feature['properties']['level'] = 0
feature['properties']['height'] = 5
feature['properties']['base_height'] = 0
r = lambda: random.randint(0,255)
feature['properties']['color'] = '#%02X%02X%02X' % (r(),r(),r())
newFeatures.append(feature)
newGeojson = {}
newGeojson['type'] = 'FeatureCollection'
newGeojson['features'] = newFeatures
with open('data/add-polygon-heights/output.geojson', 'w', encoding='utf-8') as f:
json.dump(newGeojson, f)
f.close()
print(count)