summer_course_2024/imports/geometry/citygml_lod2.py
2021-06-03 12:42:00 -04:00

61 lines
2.1 KiB
Python

"""
CityGmlLod1 module parses citygml 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_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'
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']:
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):
raise NotImplementedError('multi surface')