Partial correction citygml read
This commit is contained in:
parent
f5e32e16ea
commit
81324c945e
|
@ -160,15 +160,6 @@ class GeometryHelper:
|
|||
|
||||
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
|
||||
def get_location(latitude, longitude):
|
||||
url = 'https://nominatim.openstreetmap.org/reverse?lat={latitude}&lon={longitude}&format=json'
|
||||
|
|
|
@ -20,6 +20,8 @@ class CityGml:
|
|||
"""
|
||||
def __init__(self, path):
|
||||
self._city = None
|
||||
self._lod1_tags = ['lod1Solid', 'lod1MultiSurface']
|
||||
self._lod2_tags = ['lod2Solid', 'lod2MultiSurface', 'lod2MultiCurve']
|
||||
with open(path) as gml:
|
||||
# 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
|
||||
|
||||
def _create_building(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def city(self) -> City:
|
||||
"""
|
||||
|
@ -71,19 +76,28 @@ class CityGml:
|
|||
:return: City
|
||||
"""
|
||||
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)
|
||||
i = 0
|
||||
|
||||
for o in self._gml['CityModel']['cityObjectMember']:
|
||||
i += 1
|
||||
lod = 0
|
||||
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']:
|
||||
lod += 1
|
||||
surfaces = CityGmlLod1.lod1_solid(o)
|
||||
elif 'lod1MultiSurface' in o['Building']:
|
||||
lod += 1
|
||||
surfaces = CityGmlLod1.lod1_multi_surface(o)
|
||||
|
||||
elif 'lod2Solid' in o['Building'] :
|
||||
lod += 1
|
||||
surfaces = CityGmlLod2.lod2_solid(o)
|
||||
|
@ -101,7 +115,7 @@ class CityGml:
|
|||
lod += 4
|
||||
if 'lod4Solid' in o['Building']:
|
||||
lod += 8
|
||||
|
||||
'''
|
||||
lod_terrain_str = 'lod' + str(lod) + 'TerrainIntersection'
|
||||
terrains = []
|
||||
if lod_terrain_str in o['Building']:
|
||||
|
@ -116,6 +130,7 @@ class CityGml:
|
|||
function = o['Building']['function']
|
||||
self._city.add_city_object(Building(name, lod, surfaces, year_of_construction, function, self._lower_corner,
|
||||
terrains))
|
||||
|
||||
return self._city
|
||||
|
||||
def _terrains(self, city_object, lod_terrain_str):
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
from abc import ABC
|
||||
import numpy as np
|
||||
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
|
||||
def _remove_last_point(points):
|
||||
|
@ -20,3 +27,19 @@ class CityGmlTools:
|
|||
solid_points = np.fromstring(coordinates, dtype=float, sep=' ')
|
||||
solid_points = GeometryHelper.to_points_matrix(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
|
|
@ -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.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
|
||||
def lod1_solid(o):
|
||||
try:
|
||||
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']]
|
||||
except TypeError:
|
||||
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']]
|
||||
|
||||
return [Surface(Polygon(sp), Polygon(sp)) for sp in solid_points]
|
||||
|
||||
@staticmethod
|
||||
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']]
|
||||
return [Surface(Polygon(sp), Polygon(sp)) for sp in solid_points]
|
|
@ -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.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
|
||||
def _lod2_composite_surface(s):
|
||||
solid_points = [
|
||||
CityGmlTools._solid_points((CityGmlTools._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]
|
||||
def _surface_encoding(surfaces):
|
||||
if 'lod2MultiSurface' in surfaces:
|
||||
return 'lod2MultiSurface', 'MultiSurface'
|
||||
return 'unknown'
|
||||
|
||||
@staticmethod
|
||||
def _lod2_multi_surface(s, surface_type):
|
||||
# todo: this need to be changed into surface bounded?
|
||||
try:
|
||||
solid_points = [CityGmlTools._solid_points(CityGmlTools._remove_last_point(
|
||||
s['Polygon']['exterior']['LinearRing']['posList']['#text']))]
|
||||
except TypeError:
|
||||
solid_points = [CityGmlTools._solid_points(CityGmlTools._remove_last_point(s['Polygon']['exterior']['LinearRing']
|
||||
['posList']))]
|
||||
return [Surface(Polygon(sp), Polygon(sp), surface_type=surface_type) for sp in solid_points]
|
||||
@classmethod
|
||||
def _solid(cls, o):
|
||||
surfaces = []
|
||||
for b in o["Building"]["boundedBy"]:
|
||||
surface_type = next(iter(b))
|
||||
surface_encoding, surface_subtype = cls._surface_encoding(b[surface_type])
|
||||
for member in b[surface_type][surface_encoding][surface_subtype]['surfaceMember']:
|
||||
sp = cls._solid_points(cls._remove_last_point(member['Polygon']['exterior']['LinearRing']['posList']))
|
||||
p = Polygon(sp)
|
||||
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 = []
|
||||
for surface_type in iter(bound):
|
||||
for s in bound[surface_type]['lod2MultiSurface']['MultiSurface']['surfaceMember']:
|
||||
if 'CompositeSurface' in s:
|
||||
surfaces = surfaces + CityGmlLod2._lod2_composite_surface(s)
|
||||
surfaces = surfaces + cls._lod2_composite_surface(s)
|
||||
else:
|
||||
surfaces = surfaces + CityGmlLod2._lod2_multi_surface(s, surface_type)
|
||||
surfaces = surfaces + cls._lod2_multi_surface(s, surface_type)
|
||||
return surfaces
|
||||
|
||||
@staticmethod
|
||||
def lod2_solid_multi_surface(o):
|
||||
@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(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']
|
||||
['lod2MultiSurface']['MultiSurface']['surfaceMember']]
|
||||
|
||||
elif 'WallSurface' in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']:
|
||||
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']]
|
||||
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']]
|
||||
return [Surface(p,p) for p in polygons]
|
||||
|
||||
|
||||
@staticmethod
|
||||
def lod2_solid(o):
|
||||
@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 = [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']]
|
||||
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']]
|
||||
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]
|
|
@ -315,3 +315,12 @@ class GeometryHelper:
|
|||
"""
|
||||
delta = self.distance_between_points(v1, v2)
|
||||
return delta <= delta_max
|
||||
|
||||
@staticmethod
|
||||
def gml_surface_to_libs(surface):
|
||||
if surface == 'WallSurface':
|
||||
return 'Wall'
|
||||
elif surface == 'GroundSurface':
|
||||
return 'Ground'
|
||||
else:
|
||||
return 'Roof'
|
|
@ -52,7 +52,9 @@ class TestGeometryFactory(TestCase):
|
|||
file = '20190815_mitte_out_MC_FloursurfaceADD.gml'
|
||||
city = self._get_citygml(file)
|
||||
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):
|
||||
"""
|
||||
|
@ -61,6 +63,7 @@ class TestGeometryFactory(TestCase):
|
|||
"""
|
||||
file = 'one_building_in_kelowna.gml'
|
||||
city = self._get_citygml(file)
|
||||
self.assertTrue(len(city.buildings) == 1)
|
||||
for building in city.buildings:
|
||||
self.assertIsNotNone(building.name, 'building name is none')
|
||||
self.assertIsNotNone(building.lod, 'building lod is none')
|
||||
|
|
|
@ -53,6 +53,7 @@ class TestSensorsFactory(TestCase):
|
|||
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'})
|
||||
sensor.add_period(update)
|
||||
|
||||
row = sensor.measures.loc[sensor.measures["Date time"] == '2020-01-19 23:55:00']['Energy consumption'].iloc[0]
|
||||
self.assertTrue(f'{row}' == '12345.0')
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user