-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrhinopostsites.py
More file actions
executable file
·78 lines (63 loc) · 2.06 KB
/
rhinopostsites.py
File metadata and controls
executable file
·78 lines (63 loc) · 2.06 KB
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
# Standard library imports
import json
# home-baked imports
from rhinopythonscripts.GeoJson2Rhino import *
class RhinoFeature():
def __init__(self, geometry, attributes):
self.geom = geometry
self.att = attributes
def asTuple(self):
return (self.geom, self.att)
class Layer(object):
"""Used to hold information about individual layers."""
def __init__(self, name):
self.name = name
self.name_in_db = name
self.cols = None
self.features = []
self.color = None
self.zColumn = None
self.geoJson = None
def __unicode__(self):
return 'Layer: %s' % self.name
def __str__(self):
return unicode(self).encode('utf-8')
class Site(object):
"""Used to hold information about individual sites."""
def __init__(self, id):
self.id = None
self.layers = []
self.siteLayer = None
self.terrainLayer = None
self.connection = None
self.json = None
def __unicode__(self):
return 'Site: id=%s' % self.id
def __str__(self):
return unicode(self).encode('utf-8')
def buildSiteLayer(rawLayer):
layer = Layer(rawLayer['name'])
if 'color' in rawLayer: # get the color if it exists
layer.color = rlayer['color']
jsonFeatures = rawLayer['contents']['features']
for jsonFeature in jsonFeatures:
# jsonToRhinoCommon comes from
# rhinopythonscripts.GeoJson2Rhino
geom = jsonToRhinoCommon(jsonFeature)
att = jsonFeature['properties']
rhFeature = RhinoFeature(geom, att)
layer.features.append(rhFeature)
return layer
def buildSite(id, layerCollection):
site = Site(id)
for rLayer in layerCollection['layers']:
if len(rLayer['contents']['features']):
site.layers.append(buildSiteLayer(rLayer))
return site
def jsonsToPostSites(jsonSiteDict):
sites = []
for idKey in jsonSiteDict:
layerColl = json.loads(jsonSiteDict[idKey])
site = buildSite(idKey, layerColl)
sites.append(site)
return sites