-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFeatures.py
37 lines (33 loc) · 1.12 KB
/
Features.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
import json
from shapely import from_geojson, affinity, MultiPolygon, is_valid
class Features:
def __init__(
self,
layer,
item_scale=1,
group_scale=1000):
self.item_scale = item_scale
self.group_scale = group_scale
self.data = []
self.polygons = []
self.scaled = []
[self.add_feature(feature)
for feature in layer]
self.scaled_group = affinity.scale(
MultiPolygon(self.scaled),
self.group_scale,
-self.group_scale)
def add_feature(self, feature):
geo_json = feature.ExportToJson(True)
a=from_geojson(json.dumps(geo_json))
if(is_valid(a)==False):
return False
self.data.append(geo_json)
self.polygons.append(from_geojson(json.dumps(geo_json)))
scaled_poly = affinity.scale(from_geojson(json.dumps(geo_json)),
self.item_scale, self.item_scale)
self.scaled.append(scaled_poly)
return True
def print_info(self):
for p in self.data:
print(p['properties'])