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
|
2022-04-08 09:35:33 -04:00
|
|
|
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
|
2021-08-06 12:28:20 -04:00
|
|
|
from city_model_structure.building_demand.surface import Surface
|
2021-06-02 11:16:00 -04:00
|
|
|
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
|
|
|
|
"""
|
2021-08-30 11:38:28 -04:00
|
|
|
def __init__(self, city_object_member):
|
2021-06-03 10:12:06 -04:00
|
|
|
super().__init__()
|
2021-08-30 11:38:28 -04:00
|
|
|
self._city_object_member = city_object_member
|
|
|
|
self._surfaces = self._identify(self._city_object_member)
|
2021-06-03 10:12:06 -04:00
|
|
|
|
|
|
|
@classmethod
|
2021-08-30 11:38:28 -04:00
|
|
|
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)
|
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 11:16:21 -04:00
|
|
|
raise NotImplementedError('unknown surface type')
|
2021-06-03 10:12:06 -04:00
|
|
|
|
|
|
|
@classmethod
|
2021-08-30 11:38:28 -04:00
|
|
|
def _solid(cls, city_object_member):
|
2021-06-03 10:12:06 -04:00
|
|
|
surfaces = []
|
2021-08-30 11:38:28 -04:00
|
|
|
for bounded in city_object_member["boundedBy"]:
|
2021-06-03 16:26:00 -04:00
|
|
|
try:
|
2021-08-30 11:38:28 -04:00
|
|
|
surface_type = next(iter(bounded))
|
2021-06-03 16:26:00 -04:00
|
|
|
except TypeError:
|
|
|
|
continue
|
|
|
|
try:
|
2021-08-30 11:38:28 -04:00
|
|
|
surface_encoding, surface_subtype = cls._surface_encoding(bounded[surface_type])
|
2021-06-03 16:26:00 -04:00
|
|
|
except NotImplementedError:
|
|
|
|
continue
|
2021-08-30 11:38:28 -04:00
|
|
|
for member in bounded[surface_type][surface_encoding][surface_subtype]['surfaceMember']:
|
2022-06-07 13:31:35 -04:00
|
|
|
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:
|
2022-06-07 13:31:35 -04:00
|
|
|
surfaces.append(cls._add_member_surface(member, surface_type))
|
2021-06-03 10:12:06 -04:00
|
|
|
return surfaces
|
|
|
|
|
2022-06-07 13:31:35 -04:00
|
|
|
@classmethod
|
|
|
|
def _add_member_surface(cls, member, surface_type):
|
2022-11-24 17:58:45 -05:00
|
|
|
pos_name = 'posList'
|
|
|
|
if pos_name not in member['Polygon']['exterior']['LinearRing']:
|
|
|
|
pos_name = 'pos'
|
|
|
|
if '@srsDimension' in member['Polygon']['exterior']['LinearRing'][pos_name]:
|
2022-06-07 13:31:35 -04:00
|
|
|
gml_points = member['Polygon']['exterior']['LinearRing']['posList']["#text"]
|
|
|
|
else:
|
2022-11-24 17:58:45 -05:00
|
|
|
gml_points = member['Polygon']['exterior']['LinearRing'][pos_name]
|
|
|
|
if pos_name == 'pos':
|
|
|
|
gml_points_string = ''
|
|
|
|
for gml_point in gml_points:
|
|
|
|
gml_points_string = f'{gml_points_string} {gml_point}'
|
|
|
|
gml_points = gml_points_string.lstrip(' ')
|
|
|
|
solid_points = GeometryHelper.points_from_string(GeometryHelper.remove_last_point_from_string(gml_points))
|
2022-06-07 13:31:35 -04:00
|
|
|
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
|
2021-08-30 11:38:28 -04:00
|
|
|
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
|
2021-08-30 11:38:28 -04:00
|
|
|
def _multi_surface(cls, city_object_member):
|
|
|
|
return cls._solid(city_object_member)
|