70 lines
2.6 KiB
Python
70 lines
2.6 KiB
Python
"""
|
|
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 imports.geometry.helpers.geometry_helper import GeometryHelper
|
|
from city_model_structure.building_demand.surface import Surface
|
|
from city_model_structure.attributes.polygon import Polygon
|
|
|
|
|
|
class CityGmlLod2(CityGmlBase):
|
|
"""
|
|
CityGmlLod1 class to parse level of detail 1 city gml files
|
|
"""
|
|
def __init__(self, city_object_member):
|
|
super().__init__()
|
|
self._city_object_member = city_object_member
|
|
self._surfaces = self._identify(self._city_object_member)
|
|
|
|
@classmethod
|
|
def _identify(cls, city_object_member):
|
|
if 'lod2Solid' in city_object_member:
|
|
return cls._solid(city_object_member)
|
|
if 'lod2MultiSurface' in city_object_member:
|
|
return cls._multi_surface(city_object_member)
|
|
if 'lod2MultiCurve' in city_object_member:
|
|
return cls._multi_curve(city_object_member)
|
|
raise NotImplementedError(city_object_member)
|
|
|
|
@staticmethod
|
|
def _surface_encoding(surfaces):
|
|
if 'lod2MultiSurface' in surfaces:
|
|
return 'lod2MultiSurface', 'MultiSurface'
|
|
raise NotImplementedError('unknown surface type')
|
|
|
|
@classmethod
|
|
def _solid(cls, city_object_member):
|
|
surfaces = []
|
|
for bounded in city_object_member["boundedBy"]:
|
|
try:
|
|
surface_type = next(iter(bounded))
|
|
except TypeError:
|
|
continue
|
|
try:
|
|
surface_encoding, surface_subtype = cls._surface_encoding(bounded[surface_type])
|
|
except NotImplementedError:
|
|
|
|
continue
|
|
for member in bounded[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']
|
|
solid_points = cls._solid_points(cls._remove_last_point(gml_points))
|
|
polygon = Polygon(solid_points)
|
|
surface = Surface(polygon, polygon, surface_type=GeometryHelper.gml_surface_to_libs(surface_type))
|
|
surfaces.append(surface)
|
|
return surfaces
|
|
|
|
@classmethod
|
|
def _multi_curve(cls, city_object_member):
|
|
raise NotImplementedError('multi curve')
|
|
|
|
@classmethod
|
|
def _multi_surface(cls, city_object_member):
|
|
return cls._solid(city_object_member)
|