49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from imports.geometry.citygml_base import CityGmlBase
|
|
from city_model_structure.attributes.surface import Surface
|
|
from city_model_structure.attributes.polygon import Polygon
|
|
from imports.geometry.helpers.geometry_helper import GeometryHelper
|
|
|
|
|
|
class CityGmlLod2(CityGmlBase):
|
|
|
|
def __init__(self, o):
|
|
super().__init__()
|
|
self._o = o
|
|
self._surfaces = self._identify(self._o)
|
|
|
|
@classmethod
|
|
def _identify(cls, o):
|
|
if 'lod2Solid' in o:
|
|
return cls._solid(o)
|
|
elif 'lod2MultiSurface' in o:
|
|
return cls._multi_surface(o)
|
|
elif 'lod2MultiCurve' in o:
|
|
return cls._multi_curve(o)
|
|
|
|
@staticmethod
|
|
def _surface_encoding(surfaces):
|
|
if 'lod2MultiSurface' in surfaces:
|
|
return 'lod2MultiSurface', 'MultiSurface'
|
|
raise NotImplementedError('unknown surface type')
|
|
|
|
@classmethod
|
|
def _solid(cls, o):
|
|
surfaces = []
|
|
for b in o["boundedBy"]:
|
|
surface_type = next(iter(b))
|
|
surface_encoding, surface_subtype = cls._surface_encoding(b[surface_type])
|
|
for member in b[surface_type][surface_encoding][surface_subtype]['surfaceMember']:
|
|
sp = cls._solid_points(cls._remove_last_point(member['Polygon']['exterior']['LinearRing']['posList']))
|
|
p = Polygon(sp)
|
|
surface = Surface(p, p, surface_type=GeometryHelper.gml_surface_to_libs(surface_type))
|
|
surfaces.append(surface)
|
|
return surfaces
|
|
|
|
@classmethod
|
|
def _multi_curve(cls, o):
|
|
raise NotImplementedError
|
|
|
|
@classmethod
|
|
def _multi_surface(cls, o):
|
|
raise NotImplementedError
|