Partial correction citygml read

This commit is contained in:
Guille Gutierrez 2021-06-03 10:12:06 -04:00
parent f5e32e16ea
commit 81324c945e
8 changed files with 167 additions and 53 deletions

View File

@ -160,15 +160,6 @@ class GeometryHelper:
return [trimesh_1, trimesh_2] return [trimesh_1, trimesh_2]
@staticmethod
def gml_surface_to_libs(surface):
if surface == 'WallSurface':
return 'Wall'
elif surface == 'GroundSurface':
return 'Ground'
else:
return 'Roof'
@staticmethod @staticmethod
def get_location(latitude, longitude): def get_location(latitude, longitude):
url = 'https://nominatim.openstreetmap.org/reverse?lat={latitude}&lon={longitude}&format=json' url = 'https://nominatim.openstreetmap.org/reverse?lat={latitude}&lon={longitude}&format=json'

View File

@ -20,6 +20,8 @@ class CityGml:
""" """
def __init__(self, path): def __init__(self, path):
self._city = None self._city = None
self._lod1_tags = ['lod1Solid', 'lod1MultiSurface']
self._lod2_tags = ['lod2Solid', 'lod2MultiSurface', 'lod2MultiCurve']
with open(path) as gml: with open(path) as gml:
# Clean the namespaces is an important task to prevent wrong ns:field due poor citygml implementations # Clean the namespaces is an important task to prevent wrong ns:field due poor citygml implementations
@ -64,6 +66,9 @@ class CityGml:
""" """
return self._gml return self._gml
def _create_building(self):
raise NotImplementedError
@property @property
def city(self) -> City: def city(self) -> City:
""" """
@ -71,19 +76,28 @@ class CityGml:
:return: City :return: City
""" """
if self._city is None: if self._city is None:
# todo: refactor this method to clearly choose the gml type
self._city = City(self._lower_corner, self._upper_corner, self._srs_name) self._city = City(self._lower_corner, self._upper_corner, self._srs_name)
i = 0
for o in self._gml['CityModel']['cityObjectMember']: for o in self._gml['CityModel']['cityObjectMember']:
i += 1
lod = 0 lod = 0
surfaces = [] surfaces = []
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")
'''
if 'lod1Solid' in o['Building']: if 'lod1Solid' in o['Building']:
lod += 1 lod += 1
surfaces = CityGmlLod1.lod1_solid(o) surfaces = CityGmlLod1.lod1_solid(o)
elif 'lod1MultiSurface' in o['Building']: elif 'lod1MultiSurface' in o['Building']:
lod += 1 lod += 1
surfaces = CityGmlLod1.lod1_multi_surface(o) surfaces = CityGmlLod1.lod1_multi_surface(o)
elif 'lod2Solid' in o['Building'] : elif 'lod2Solid' in o['Building'] :
lod += 1 lod += 1
surfaces = CityGmlLod2.lod2_solid(o) surfaces = CityGmlLod2.lod2_solid(o)
@ -101,7 +115,7 @@ class CityGml:
lod += 4 lod += 4
if 'lod4Solid' in o['Building']: if 'lod4Solid' in o['Building']:
lod += 8 lod += 8
'''
lod_terrain_str = 'lod' + str(lod) + 'TerrainIntersection' lod_terrain_str = 'lod' + str(lod) + 'TerrainIntersection'
terrains = [] terrains = []
if lod_terrain_str in o['Building']: if lod_terrain_str in o['Building']:
@ -116,6 +130,7 @@ class CityGml:
function = o['Building']['function'] function = o['Building']['function']
self._city.add_city_object(Building(name, lod, surfaces, year_of_construction, function, self._lower_corner, self._city.add_city_object(Building(name, lod, surfaces, year_of_construction, function, self._lower_corner,
terrains)) terrains))
return self._city return self._city
def _terrains(self, city_object, lod_terrain_str): def _terrains(self, city_object, lod_terrain_str):

View File

@ -1,8 +1,15 @@
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 CityGmlTools: class CityGmlBase(ABC):
def __init__(self):
self._surfaces = []
@property
def surfaces(self):
return self._surfaces
@staticmethod @staticmethod
def _remove_last_point(points): def _remove_last_point(points):
@ -20,3 +27,19 @@ class CityGmlTools:
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
@classmethod
def _solid(cls, o):
raise NotImplementedError
@classmethod
def _multi_surface(cls, o):
raise NotImplementedError
@classmethod
def _multi_curve(cls, o):
raise NotImplementedError
@classmethod
def _building_parts(cls, o):
raise NotImplementedError

View File

@ -1,25 +1,41 @@
from imports.geometry.citygml_tools import CityGmlTools 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(CityGmlTools): class CityGmlLod1(CityGmlBase):
@classmethod
def _multi_curve(cls, o):
pass
@classmethod
def _multi_surface(cls, o):
pass
@classmethod
def _solid(cls, o):
pass
def __init__(self, o):
super().__init__()
self._o = o
@staticmethod @staticmethod
def lod1_solid(o): def lod1_solid(o):
try: try:
solid_points = [ solid_points = [
CityGmlTools._solid_points(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']['#text'])) CityGmlBase._solid_points(CityGmlBase._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']['#text']))
for s in o['Building']['lod1Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']] for s in o['Building']['lod1Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']]
except TypeError: except TypeError:
solid_points = [ solid_points = [
CityGmlTools._solid_points(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) CityGmlBase._solid_points(CityGmlBase._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod1Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']] for s in o['Building']['lod1Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']]
return [Surface(Polygon(sp), Polygon(sp)) for sp in solid_points] return [Surface(Polygon(sp), Polygon(sp)) for sp in solid_points]
@staticmethod @staticmethod
def lod1_multi_surface(o): def lod1_multi_surface(o):
solid_points = [CityGmlTools._solid_points(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) solid_points = [CityGmlBase._solid_points(CityGmlBase._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod1MultiSurface']['MultiSurface']['surfaceMember']] for s in o['Building']['lod1MultiSurface']['MultiSurface']['surfaceMember']]
return [Surface(Polygon(sp), Polygon(sp)) for sp in solid_points] return [Surface(Polygon(sp), Polygon(sp)) for sp in solid_points]

View File

@ -1,65 +1,121 @@
from imports.geometry.citygml_tools import CityGmlTools
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
class CityGmlLod2(CityGmlBase):
class CityGmlLod2(CityGmlTools): def __init__(self, o):
super().__init__()
self._o = o
self._surfaces = self._identify(self._o)
@classmethod
def _identify(cls, o):
if 'lod2Solid' in o['Building']:
return cls._solid(o)
elif 'lod2MultiSurface' in o['Building']:
print('multi_surface')
return cls._multi_surface(o)
elif 'lod2MultiCurve' in o['Building']:
print('multi_curve')
return cls._multi_curve(o)
elif 'consistsOfBuildingPart' in o['Building']:
raise NotImplementedError
@staticmethod @staticmethod
def _lod2_composite_surface(s): def _surface_encoding(surfaces):
solid_points = [ if 'lod2MultiSurface' in surfaces:
CityGmlTools._solid_points((CityGmlTools._remove_last_point(sm['Polygon']['exterior']['LinearRing']['posList']))) return 'lod2MultiSurface', 'MultiSurface'
for sm in s['CompositeSurface']['surfaceMember']] return 'unknown'
return [Surface(Polygon(sp), Polygon(sp)) for sp in solid_points]
@staticmethod @classmethod
def _lod2_multi_surface(s, surface_type): def _solid(cls, o):
# todo: this need to be changed into surface bounded? surfaces = []
try: for b in o["Building"]["boundedBy"]:
solid_points = [CityGmlTools._solid_points(CityGmlTools._remove_last_point( surface_type = next(iter(b))
s['Polygon']['exterior']['LinearRing']['posList']['#text']))] surface_encoding, surface_subtype = cls._surface_encoding(b[surface_type])
except TypeError: for member in b[surface_type][surface_encoding][surface_subtype]['surfaceMember']:
solid_points = [CityGmlTools._solid_points(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing'] sp = cls._solid_points(cls._remove_last_point(member['Polygon']['exterior']['LinearRing']['posList']))
['posList']))] p = Polygon(sp)
return [Surface(Polygon(sp), Polygon(sp), surface_type=surface_type) for sp in solid_points] surface = Surface(p,p, surface_type=GeometryHelper.gml_surface_to_libs(surface_type))
surfaces.append(surface)
for p in o["Building"]["consistsOfBuildingPart"]:
raise NotImplementedError
return surfaces
@staticmethod
def lod2(bound): @classmethod
def _multi_curve(cls, o):
raise NotImplementedError
@classmethod
def _multi_surface(cls, o):
raise NotImplementedError
@classmethod
def _lod2(cls, bound):
surfaces = [] surfaces = []
for surface_type in iter(bound): for surface_type in iter(bound):
for s in bound[surface_type]['lod2MultiSurface']['MultiSurface']['surfaceMember']: for s in bound[surface_type]['lod2MultiSurface']['MultiSurface']['surfaceMember']:
if 'CompositeSurface' in s: if 'CompositeSurface' in s:
surfaces = surfaces + CityGmlLod2._lod2_composite_surface(s) surfaces = surfaces + cls._lod2_composite_surface(s)
else: else:
surfaces = surfaces + CityGmlLod2._lod2_multi_surface(s, surface_type) surfaces = surfaces + cls._lod2_multi_surface(s, surface_type)
return surfaces return surfaces
@staticmethod @classmethod
def lod2_solid_multi_surface(o): def _lod2_solid_multi_surface(cls, o):
polygons = None polygons = None
if 'boundedBy' in o['Building']['consistsOfBuildingPart']['BuildingPart']: if 'boundedBy' in o['Building']['consistsOfBuildingPart']['BuildingPart']:
if 'RoofSurface' in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']: if 'RoofSurface' in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']:
if o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['RoofSurface']['lod2MultiSurface'] != 'None': if o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['RoofSurface']['lod2MultiSurface'] != 'None':
polygons = [Polygon(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) polygons = [Polygon(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['RoofSurface'] for s in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['RoofSurface']
['lod2MultiSurface']['MultiSurface']['surfaceMember']] ['lod2MultiSurface']['MultiSurface']['surfaceMember']]
elif 'WallSurface' in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']: elif 'WallSurface' in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']:
if o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['WallSurface']['lod2MultiSurface'] != 'None': if o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['WallSurface']['lod2MultiSurface'] != 'None':
polygons = [Polygon(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) polygons = [Polygon(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['WallSurface']['lod2MultiSurface']['MultiSurface']['surfaceMember']] for s in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['WallSurface']['lod2MultiSurface']['MultiSurface']['surfaceMember']]
else: else:
polygons = [Polygon(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) polygons = [Polygon(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod2MultiSurface']['MultiSurface']['surfaceMember']] for s in o['Building']['lod2MultiSurface']['MultiSurface']['surfaceMember']]
return [Surface(p,p) for p in polygons] return [Surface(p,p) for p in polygons]
@staticmethod @classmethod
def lod2_solid(o): def _lod2_solid(cls, o):
for walls in o['Building']['boundedBy']['wallSurface']:
print(f'solid')
@classmethod
def _lod2_solid_composite_surface(cls, o):
try: try:
solid_points = [CityGmlTools._solid_points(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']['#text'])) 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']] for s in o['Building']['lod2Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']]
except TypeError: except TypeError:
solid_points = [CityGmlTools._solid_points(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) solid_points = [cls._solid_points(cls._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod2Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']] for s in o['Building']['lod2Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']]
return [Surface(Polygon(sp),Polygon(sp)) for sp in solid_points] 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]

View File

@ -315,3 +315,12 @@ class GeometryHelper:
""" """
delta = self.distance_between_points(v1, v2) delta = self.distance_between_points(v1, v2)
return delta <= delta_max return delta <= delta_max
@staticmethod
def gml_surface_to_libs(surface):
if surface == 'WallSurface':
return 'Wall'
elif surface == 'GroundSurface':
return 'Ground'
else:
return 'Roof'

View File

@ -52,7 +52,9 @@ class TestGeometryFactory(TestCase):
file = '20190815_mitte_out_MC_FloursurfaceADD.gml' file = '20190815_mitte_out_MC_FloursurfaceADD.gml'
city = self._get_citygml(file) city = self._get_citygml(file)
for building in city.buildings: for building in city.buildings:
self.assertIsNotNone(building.volume, 'building volume is none') print(f'building {building.name} has {len(building.surfaces)} surfaces {building.volume}')
self.assertFalse(building.volume is 'inf', 'building volume is inf')
print(f'Found {len(city.buildings)} buildings' )
def test_citygml_buildings(self): def test_citygml_buildings(self):
""" """
@ -61,6 +63,7 @@ class TestGeometryFactory(TestCase):
""" """
file = 'one_building_in_kelowna.gml' file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file) city = self._get_citygml(file)
self.assertTrue(len(city.buildings) == 1)
for building in city.buildings: for building in city.buildings:
self.assertIsNotNone(building.name, 'building name is none') self.assertIsNotNone(building.name, 'building name is none')
self.assertIsNotNone(building.lod, 'building lod is none') self.assertIsNotNone(building.lod, 'building lod is none')

View File

@ -53,6 +53,7 @@ class TestSensorsFactory(TestCase):
update = pd.DataFrame([['2020-01-19 23:55:00', '12345.0']], columns=["Date time", "Energy consumption"]) update = pd.DataFrame([['2020-01-19 23:55:00', '12345.0']], columns=["Date time", "Energy consumption"])
update = update.astype({"Date time": 'datetime64', "Energy consumption": 'float64'}) update = update.astype({"Date time": 'datetime64', "Energy consumption": 'float64'})
sensor.add_period(update) sensor.add_period(update)
row = sensor.measures.loc[sensor.measures["Date time"] == '2020-01-19 23:55:00']['Energy consumption'].iloc[0] row = sensor.measures.loc[sensor.measures["Date time"] == '2020-01-19 23:55:00']['Energy consumption'].iloc[0]
self.assertTrue(f'{row}' == '12345.0') self.assertTrue(f'{row}' == '12345.0')