""" CityGmlLod1 module parses citygml_classes files with level of detail 1 and import the geometry into the city model structure SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2021 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ from imports.geometry.citygml_classes.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): """ CityGmlLod1 class to parse level of detail 1 city gml files """ 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' print(surfaces) raise NotImplementedError('unknown surface type') @classmethod def _solid(cls, o): surfaces = [] for b in o["boundedBy"]: try: surface_type = next(iter(b)) except TypeError: continue try: surface_encoding, surface_subtype = cls._surface_encoding(b[surface_type]) except NotImplementedError: print("Ignore bounded") continue for member in b[surface_type][surface_encoding][surface_subtype]['surfaceMember']: if '@srsDimension' in member['Polygon']['exterior']['LinearRing']['posList']: gml_points = member['Polygon']['exterior']['LinearRing']['posList']["#text"] else: gml_points = member['Polygon']['exterior']['LinearRing']['posList'] sp = cls._solid_points(cls._remove_last_point(gml_points)) 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('multi curve') @classmethod def _multi_surface(cls, o): return cls._solid(o)