Merge remote-tracking branch 'origin/master'

# Conflicts:
#	imports/geometry/citygml.py
This commit is contained in:
Pilar 2021-06-03 11:38:05 -04:00
commit f725ec9d4c
4 changed files with 62 additions and 125 deletions

View File

@ -9,7 +9,6 @@ import xmltodict
from city_model_structure.city import City from city_model_structure.city import City
from city_model_structure.building import Building from city_model_structure.building import Building
from helpers.geometry_helper import GeometryHelper from helpers.geometry_helper import GeometryHelper
from city_model_structure.attributes.polygon import Polygon
from imports.geometry.citygml_lod2 import CityGmlLod2 from imports.geometry.citygml_lod2 import CityGmlLod2
from imports.geometry.citygml_lod1 import CityGmlLod1 from imports.geometry.citygml_lod1 import CityGmlLod1
@ -46,6 +45,7 @@ class CityGml:
'http://www.opengis.net/citygml/2.0': None 'http://www.opengis.net/citygml/2.0': None
}, force_list=('cityObjectMember', 'curveMember', 'boundedBy', 'surfaceMember')) }, force_list=('cityObjectMember', 'curveMember', 'boundedBy', 'surfaceMember'))
self._city_objects = None self._city_objects = None
self._geometry = GeometryHelper()
for bound in self._gml['CityModel']['boundedBy']: for bound in self._gml['CityModel']['boundedBy']:
envelope = bound['Envelope'] envelope = bound['Envelope']
if '#text' in envelope['lowerCorner']: if '#text' in envelope['lowerCorner']:
@ -65,7 +65,25 @@ class CityGml:
""" """
return self._gml return self._gml
def _create_building(self): def _create_building(self, city_object):
name = city_object['@id']
function = None
year_of_construction = None
if 'yearOfConstruction' in city_object:
year_of_construction = city_object['yearOfConstruction']
if 'function' in city_object:
function = city_object['function']
if any(key in city_object for key in self._lod1_tags):
lod = 1
surfaces = CityGmlLod1(city_object).surfaces
elif any(key in city_object for key in self._lod2_tags):
lod = 2
surfaces = CityGmlLod2(city_object).surfaces
else:
raise NotImplementedError("Not supported level of detail")
return Building(name, lod, surfaces, year_of_construction, function, self._lower_corner, [])
def _create_parts_consisting_building(self):
raise NotImplementedError raise NotImplementedError
@property @property
@ -74,19 +92,13 @@ class CityGml:
City model structure enriched with the geometry information City model structure enriched with the geometry information
:return: City :return: City
""" """
if self._city is None: if self._city is None:
self._city = City(self._lower_corner, self._upper_corner, self._srs_name) self._city = City(self._lower_corner, self._upper_corner, self._srs_name)
for o in self._gml['CityModel']['cityObjectMember']: for o in self._gml['CityModel']['cityObjectMember']:
lod = 0 city_object = o['Building']
surfaces = [] if 'consistsOfBuildingPart' in city_object:
if any(key in o['Building'] for key in self._lod1_tags):
lod = 1
surfaces = CityGmlLod1(o).surfaces
elif any(key in o['Building'] for key in self._lod2_tags):
lod = 2
surfaces = CityGmlLod2(o).surfaces
elif 'consistsOfBuildingPart' in o['Building']:
raise NotImplementedError("Building cluster") raise NotImplementedError("Building cluster")
''' '''
if 'lod1Solid' in o['Building']: if 'lod1Solid' in o['Building']:
@ -104,31 +116,7 @@ class CityGml:
lod = 2 lod = 2
surfaces = surfaces + CityGmlLod2.lod2_solid_multi_surface(o) surfaces = surfaces + CityGmlLod2.lod2_solid_multi_surface(o)
else: else:
for bound in o['Building']['boundedBy']: self._city.add_city_object(self._create_building(city_object))
surface_type = next(iter(bound))
if 'lod2MultiSurface' in bound[surface_type]:
lod = 2
surfaces = surfaces + CityGmlLod2.lod2(bound)
if 'lod3Solid' in o['Building']:
lod += 4
if 'lod4Solid' in o['Building']:
lod += 8
'''
lod_terrain_str = 'lod' + str(lod) + 'TerrainIntersection'
terrains = []
if lod_terrain_str in o['Building']:
terrains = self._terrains(o, lod_terrain_str)
function = None
year_of_construction = None
name = o['Building']['@id']
if 'yearOfConstruction' in o['Building']:
year_of_construction = o['Building']['yearOfConstruction']
if 'function' in o['Building']:
function = o['Building']['function']
self._city.add_city_object(Building(name, lod, surfaces, year_of_construction, function, self._lower_corner,
terrains))
return self._city return self._city
def _terrains(self, city_object, lod_terrain_str): def _terrains(self, city_object, lod_terrain_str):
@ -141,7 +129,7 @@ class CityGml:
terrains = [] terrains = []
for curve in curves: for curve in curves:
curve_points = np.fromstring(curve, dtype=float, sep=' ') curve_points = np.fromstring(curve, dtype=float, sep=' ')
curve_points = GeometryHelper.to_points_matrix(curve_points) curve_points = self._geometry.to_points_matrix(curve_points)
terrains.append(curve_points) terrains.append(curve_points)
return terrains return terrains
@ -186,7 +174,7 @@ class CityGml:
for point in perimeter_points: for point in perimeter_points:
duplicated_point = False duplicated_point = False
for p in pv: for p in pv:
if GeometryHelper.almost_equal(0.0, p, point): if GeometryHelper().almost_equal(0.0, p, point):
duplicated_point = True duplicated_point = True
if not duplicated_point: if not duplicated_point:
pv = np.append(pv, [point], axis=0) pv = np.append(pv, [point], axis=0)

View File

@ -1,14 +1,26 @@
"""
CityGmlBase module abstract class to template the different level of details
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2021 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from abc import ABC from abc import ABC
import numpy as np import numpy as np
from imports.geometry.helpers.geometry_helper import GeometryHelper from imports.geometry.helpers.geometry_helper import GeometryHelper
class CityGmlBase(ABC): class CityGmlBase(ABC):
"""
CityGmlBase class inherited by the specific level of detail classes.
"""
def __init__(self): def __init__(self):
self._surfaces = [] self._surfaces = []
@property @property
def surfaces(self): def surfaces(self):
"""
parsed surfaces
"""
return self._surfaces return self._surfaces
@staticmethod @staticmethod
@ -19,11 +31,6 @@ class CityGmlBase(ABC):
@staticmethod @staticmethod
def _solid_points(coordinates) -> np.ndarray: def _solid_points(coordinates) -> np.ndarray:
"""
Solid surface point matrix [[x, y, z],[x, y, z],...]
:parameter coordinates: string from file
:return: np.ndarray
"""
solid_points = np.fromstring(coordinates, dtype=float, sep=' ') solid_points = np.fromstring(coordinates, dtype=float, sep=' ')
solid_points = GeometryHelper.to_points_matrix(solid_points) solid_points = GeometryHelper.to_points_matrix(solid_points)
return solid_points return solid_points
@ -39,7 +46,3 @@ class CityGmlBase(ABC):
@classmethod @classmethod
def _multi_curve(cls, o): def _multi_curve(cls, o):
raise NotImplementedError raise NotImplementedError
@classmethod
def _building_parts(cls, o):
raise NotImplementedError

View File

@ -1,9 +1,18 @@
"""
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 imports.geometry.citygml_base import CityGmlBase
from city_model_structure.attributes.surface import Surface from city_model_structure.attributes.surface import Surface
from city_model_structure.attributes.polygon import Polygon from city_model_structure.attributes.polygon import Polygon
class CityGmlLod1(CityGmlBase): class CityGmlLod1(CityGmlBase):
"""
CityGmlLod1 class to parse level of detail 1 city gml files
"""
@classmethod @classmethod
def _multi_curve(cls, o): def _multi_curve(cls, o):

View File

@ -1,12 +1,19 @@
"""
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 imports.geometry.citygml_base import CityGmlBase
from city_model_structure.attributes.surface import Surface from city_model_structure.attributes.surface import Surface
from city_model_structure.attributes.polygon import Polygon from city_model_structure.attributes.polygon import Polygon
from imports.geometry.helpers.geometry_helper import GeometryHelper from imports.geometry.helpers.geometry_helper import GeometryHelper
class CityGmlLod2(CityGmlBase): class CityGmlLod2(CityGmlBase):
"""
CityGmlLod1 class to parse level of detail 1 city gml files
"""
def __init__(self, o): def __init__(self, o):
super().__init__() super().__init__()
self._o = o self._o = o
@ -14,38 +21,32 @@ class CityGmlLod2(CityGmlBase):
@classmethod @classmethod
def _identify(cls, o): def _identify(cls, o):
if 'lod2Solid' in o['Building']: if 'lod2Solid' in o:
return cls._solid(o) return cls._solid(o)
elif 'lod2MultiSurface' in o['Building']: elif 'lod2MultiSurface' in o:
print('multi_surface')
return cls._multi_surface(o) return cls._multi_surface(o)
elif 'lod2MultiCurve' in o['Building']: elif 'lod2MultiCurve' in o:
print('multi_curve')
return cls._multi_curve(o) return cls._multi_curve(o)
elif 'consistsOfBuildingPart' in o['Building']:
raise NotImplementedError
@staticmethod @staticmethod
def _surface_encoding(surfaces): def _surface_encoding(surfaces):
if 'lod2MultiSurface' in surfaces: if 'lod2MultiSurface' in surfaces:
return 'lod2MultiSurface', 'MultiSurface' return 'lod2MultiSurface', 'MultiSurface'
return 'unknown' raise NotImplementedError('unknown surface type')
@classmethod @classmethod
def _solid(cls, o): def _solid(cls, o):
surfaces = [] surfaces = []
for b in o["Building"]["boundedBy"]: for b in o["boundedBy"]:
surface_type = next(iter(b)) surface_type = next(iter(b))
surface_encoding, surface_subtype = cls._surface_encoding(b[surface_type]) surface_encoding, surface_subtype = cls._surface_encoding(b[surface_type])
for member in b[surface_type][surface_encoding][surface_subtype]['surfaceMember']: for member in b[surface_type][surface_encoding][surface_subtype]['surfaceMember']:
sp = cls._solid_points(cls._remove_last_point(member['Polygon']['exterior']['LinearRing']['posList'])) sp = cls._solid_points(cls._remove_last_point(member['Polygon']['exterior']['LinearRing']['posList']))
p = Polygon(sp) p = Polygon(sp)
surface = Surface(p,p, surface_type=GeometryHelper.gml_surface_to_libs(surface_type)) surface = Surface(p, p, surface_type=GeometryHelper.gml_surface_to_libs(surface_type))
surfaces.append(surface) surfaces.append(surface)
return surfaces return surfaces
@classmethod @classmethod
def _multi_curve(cls, o): def _multi_curve(cls, o):
raise NotImplementedError raise NotImplementedError
@ -53,67 +54,3 @@ class CityGmlLod2(CityGmlBase):
@classmethod @classmethod
def _multi_surface(cls, o): def _multi_surface(cls, o):
raise NotImplementedError raise NotImplementedError
@classmethod
def _lod2(cls, bound):
surfaces = []
for surface_type in iter(bound):
for s in bound[surface_type]['lod2MultiSurface']['MultiSurface']['surfaceMember']:
if 'CompositeSurface' in s:
surfaces = surfaces + cls._lod2_composite_surface(s)
else:
surfaces = surfaces + cls._lod2_multi_surface(s, surface_type)
return surfaces
@classmethod
def _lod2_solid_multi_surface(cls, o):
polygons = None
if 'boundedBy' in o['Building']['consistsOfBuildingPart']['BuildingPart']:
if 'RoofSurface' in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']:
if o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['RoofSurface']['lod2MultiSurface'] != 'None':
polygons = [Polygon(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['RoofSurface']
['lod2MultiSurface']['MultiSurface']['surfaceMember']]
elif 'WallSurface' in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']:
if o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['WallSurface']['lod2MultiSurface'] != 'None':
polygons = [Polygon(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['WallSurface']['lod2MultiSurface']['MultiSurface']['surfaceMember']]
else:
polygons = [Polygon(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod2MultiSurface']['MultiSurface']['surfaceMember']]
return [Surface(p,p) for p in polygons]
@classmethod
def _lod2_solid(cls, o):
for walls in o['Building']['boundedBy']['wallSurface']:
print(f'solid')
@classmethod
def _lod2_solid_composite_surface(cls, o):
try:
solid_points = [cls._solid_points(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']['#text']))
for s in o['Building']['lod2Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']]
except TypeError:
solid_points = [cls._solid_points(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod2Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']]
return [Surface(Polygon(sp),Polygon(sp)) for sp in solid_points]
@classmethod
def _lod2_composite_surface(cls, s):
solid_points = [
cls._solid_points((cls._remove_last_point(sm['Polygon']['exterior']['LinearRing']['posList'])))
for sm in s['CompositeSurface']['surfaceMember']]
return [Surface(Polygon(sp), Polygon(sp)) for sp in solid_points]
@classmethod
def _lod2_multi_surface(cls, s, surface_type):
# todo: this need to be changed into surface bounded?
try:
solid_points = [cls._solid_points(cls._remove_last_point(
s['Polygon']['exterior']['LinearRing']['posList']['#text']))]
except TypeError:
solid_points = [cls._solid_points(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))]
return [Surface(Polygon(sp), Polygon(sp), surface_type=surface_type) for sp in solid_points]