2021-06-03 11:27:48 -04:00
|
|
|
"""
|
2021-06-04 09:22:06 -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 © 2021 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
|
|
"""
|
|
|
|
|
2021-06-04 09:22:06 -04:00
|
|
|
from imports.geometry.citygml_classes.citygml_base import CityGmlBase
|
2021-06-02 11:16:00 -04:00
|
|
|
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-02 11:16:00 -04:00
|
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
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)
|
2021-06-02 11:16:00 -04:00
|
|
|
|
|
|
|
@staticmethod
|
2021-06-03 10:12:06 -04:00
|
|
|
def _surface_encoding(surfaces):
|
|
|
|
if 'lod2MultiSurface' in surfaces:
|
|
|
|
return 'lod2MultiSurface', 'MultiSurface'
|
2021-06-03 16:26:00 -04:00
|
|
|
print(surfaces)
|
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 16:26:00 -04:00
|
|
|
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
|
2021-06-03 10:12:06 -04:00
|
|
|
for member in b[surface_type][surface_encoding][surface_subtype]['surfaceMember']:
|
2021-06-03 12:42:00 -04:00
|
|
|
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))
|
2021-06-03 10:12:06 -04:00
|
|
|
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):
|
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, o):
|
2021-06-03 16:26:00 -04:00
|
|
|
return cls._solid(o)
|