city_retrofit/imports/geometry/citygml_lod2.py

49 lines
1.5 KiB
Python
Raw Normal View History

2021-06-03 10:12:06 -04:00
from imports.geometry.citygml_base import CityGmlBase
from city_model_structure.attributes.surface import Surface
from city_model_structure.attributes.polygon import Polygon
2021-06-03 10:12:06 -04:00
from imports.geometry.helpers.geometry_helper import GeometryHelper
2021-06-03 11:16:21 -04:00
class CityGmlLod2(CityGmlBase):
2021-06-03 10:12:06 -04:00
def __init__(self, o):
super().__init__()
self._o = o
self._surfaces = self._identify(self._o)
@classmethod
def _identify(cls, o):
2021-06-03 11:16:21 -04:00
if 'lod2Solid' in o:
2021-06-03 10:12:06 -04:00
return cls._solid(o)
2021-06-03 11:16:21 -04:00
elif 'lod2MultiSurface' in o:
2021-06-03 10:12:06 -04:00
return cls._multi_surface(o)
2021-06-03 11:16:21 -04:00
elif 'lod2MultiCurve' in o:
2021-06-03 10:12:06 -04:00
return cls._multi_curve(o)
@staticmethod
2021-06-03 10:12:06 -04:00
def _surface_encoding(surfaces):
if 'lod2MultiSurface' in surfaces:
return 'lod2MultiSurface', 'MultiSurface'
2021-06-03 11:16:21 -04:00
raise NotImplementedError('unknown surface type')
2021-06-03 10:12:06 -04:00
@classmethod
def _solid(cls, o):
surfaces = []
2021-06-03 11:16:21 -04:00
for b in o["boundedBy"]:
2021-06-03 10:12:06 -04:00
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)
2021-06-03 11:16:21 -04:00
surface = Surface(p, p, surface_type=GeometryHelper.gml_surface_to_libs(surface_type))
2021-06-03 10:12:06 -04:00
surfaces.append(surface)
return surfaces
@classmethod
def _multi_curve(cls, o):
raise NotImplementedError
@classmethod
def _multi_surface(cls, o):
raise NotImplementedError