From f831ed5d3c0aa34b716b05a03b079844d67e3265 Mon Sep 17 00:00:00 2001 From: Behnam Farsi Balouch Date: Fri, 30 Apr 2021 16:53:36 +0000 Subject: [PATCH 1/3] Behnam Contribution --- imports/geometry_feeders/citygml.py | 51 +++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/imports/geometry_feeders/citygml.py b/imports/geometry_feeders/citygml.py index 29f34a63..e088a26f 100644 --- a/imports/geometry_feeders/citygml.py +++ b/imports/geometry_feeders/citygml.py @@ -5,13 +5,13 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc """ import numpy as np import xmltodict +import time from city_model_structure.city import City from city_model_structure.building import Building from city_model_structure.attributes.surface import Surface from helpers.geometry_helper import GeometryHelper from city_model_structure.attributes.polygon import Polygon -from city_model_structure.attributes.thermal_zone import ThermalZone class CityGml: @@ -70,10 +70,12 @@ class CityGml: City model structure enriched with the geometry information :return: City """ + init = time.process_time_ns() 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 + building_part = None for o in self._gml['CityModel']['cityObjectMember']: i += 1 lod = 0 @@ -98,20 +100,30 @@ class CityGml: lod += 4 if 'lod4Solid' in o['Building']: lod += 8 - name = o['Building']['@id'] + lod_terrain_str = 'lod' + str(lod) + 'TerrainIntersection' terrains = [] if lod_terrain_str in o['Building']: terrains = self._terrains(o, lod_terrain_str) - year_of_construction = None - function = None - if 'yearOfConstruction' in o['Building']: - year_of_construction = o['Building']['yearOfConstruction'] - if 'function' in o['Building']: - function = o['Building']['function'] - building = Building(name, lod, surfaces, year_of_construction, function, self._lower_corner, terrains) - self._city.add_city_object(building) + function = None + year_of_construction = None + if 'consistsOfBuildingPart' in o['Building']: + if 'BuildingPart' in o['Building']['consistsOfBuildingPart']: + name = o['Building']['consistsOfBuildingPart']['BuildingPart']['name'] + if 'yearOfConstruction' in o['Building']['consistsOfBuildingPart']['BuildingPart']: + year_of_construction = o['Building']['consistsOfBuildingPart']['BuildingPart']['yearOfConstruction'] + if 'function' in o['Building']['consistsOfBuildingPart']['BuildingPart']: + function = o['Building']['consistsOfBuildingPart']['BuildingPart']['function'] + + else: + 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, terrains, year_of_construction, function, + self._lower_corner)) return self._city def _terrains(self, city_object, lod_terrain_str): @@ -146,9 +158,20 @@ class CityGml: return [Surface(Polygon(sp),Polygon(sp)) for sp in solid_points] @staticmethod - def _lod2_solid_multi_surface(o): - polygons = [Polygon(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) - for s in o['Building']['lod2MultiSurface']['MultiSurface']['surfaceMember']] + def _lod2_solid_multi_surface(o,): + 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(CityGml._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(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) + for s in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['WallSurface']['lod2MultiSurface']['MultiSurface']['surfaceMember']] + else: + polygons = [Polygon(CityGml._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 @@ -176,7 +199,7 @@ class CityGml: if 'CompositeSurface' in s: surfaces = surfaces + CityGml._lod2_composite_surface(s) else: - surfaces = surfaces + CityGml._lod2_multi_surface(s, GeometryHelper.gml_surface_to_libs(surface_type)) + surfaces = surfaces + CityGml._lod2_multi_surface(s, surface_type) return surfaces @staticmethod From 6e360251fbb1f3d40166ba6cc3e3d7aa177b2cb0 Mon Sep 17 00:00:00 2001 From: Behnam Farsi Balouch Date: Fri, 30 Apr 2021 16:59:04 +0000 Subject: [PATCH 2/3] Update citygml.py --- imports/geometry_feeders/citygml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imports/geometry_feeders/citygml.py b/imports/geometry_feeders/citygml.py index e088a26f..dbbfd8cb 100644 --- a/imports/geometry_feeders/citygml.py +++ b/imports/geometry_feeders/citygml.py @@ -158,7 +158,7 @@ class CityGml: return [Surface(Polygon(sp),Polygon(sp)) for sp in solid_points] @staticmethod - def _lod2_solid_multi_surface(o,): + def _lod2_solid_multi_surface(o): if 'boundedBy' in o['Building']['consistsOfBuildingPart']['BuildingPart']: if 'RoofSurface' in o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']: if o['Building']['consistsOfBuildingPart']['BuildingPart']['boundedBy']['RoofSurface']['lod2MultiSurface'] != 'None':