hub/imports/geometry/citygml_classes/citygml_lod2.py

78 lines
3.0 KiB
Python
Raw Normal View History

2021-06-03 11:27:48 -04:00
"""
2021-08-27 12:51:30 -04:00
CityGmlLod1 module parses citygml_classes files with level of detail 1 and import the geometry into the city model
structure
2021-06-03 11:27:48 -04:00
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
2021-06-03 11:27:48 -04:00
"""
2021-06-04 09:22:06 -04:00
from imports.geometry.citygml_classes.citygml_base import CityGmlBase
2021-08-27 12:51:30 -04:00
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
2021-06-03 11:16:21 -04:00
class CityGmlLod2(CityGmlBase):
2021-06-03 11:27:48 -04:00
"""
CityGmlLod1 class to parse level of detail 1 city gml files
"""
def __init__(self, city_object_member):
2021-06-03 10:12:06 -04:00
super().__init__()
self._city_object_member = city_object_member
self._surfaces = self._identify(self._city_object_member)
2021-06-03 10:12:06 -04:00
@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
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, city_object_member):
2021-06-03 10:12:06 -04:00
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 'CompositeSurface' in member:
for composite_members in member['CompositeSurface']['surfaceMember']:
for composite_member in composite_members['CompositeSurface']['surfaceMember']:
surfaces.append(cls._add_member_surface(composite_member, surface_type))
2021-06-03 12:42:00 -04:00
else:
surfaces.append(cls._add_member_surface(member, surface_type))
2021-06-03 10:12:06 -04:00
return surfaces
@classmethod
def _add_member_surface(cls, member, surface_type):
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)
return Surface(polygon, polygon, surface_type=GeometryHelper.gml_surface_to_libs(surface_type))
2021-06-03 10:12:06 -04:00
@classmethod
def _multi_curve(cls, city_object_member):
2021-06-03 12:42:00 -04:00
raise NotImplementedError('multi curve')
2021-06-03 10:12:06 -04:00
@classmethod
def _multi_surface(cls, city_object_member):
return cls._solid(city_object_member)