Merge branch 'undefined' into 'master'

Updated code by Behnam

See merge request Guille/libs!2
This commit is contained in:
Guillermo Gutierrez Morote 2021-04-12 09:55:13 -04:00
commit dcf23c239b

View File

@ -5,13 +5,13 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc
""" """
import numpy as np import numpy as np
import xmltodict import xmltodict
import time
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 city_model_structure.attributes.surface import Surface from city_model_structure.attributes.surface import Surface
from helpers.geometry_helper import GeometryHelper from helpers.geometry_helper import GeometryHelper
from city_model_structure.attributes.polygon import Polygon from city_model_structure.attributes.polygon import Polygon
from city_model_structure.attributes.thermal_zone import ThermalZone
class CityGml: class CityGml:
@ -70,48 +70,51 @@ class CityGml:
City model structure enriched with the geometry information City model structure enriched with the geometry information
:return: City :return: City
""" """
init = time.process_time_ns()
if self._city is None: if self._city is None:
# todo: refactor this method to clearly choose the gml type # 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 i = 0
for o in self._gml['CityModel']['cityObjectMember']: for o in self._gml['CityModel']['cityObjectMember']:
i += 1 gmlbuilding = o['Building']
lod = 0 for build in gmlbuilding['consistsOfBuildingPart']:
surfaces = [] buildingpart = build['BuildingPart']
if 'lod1Solid' in o['Building']: i += 1
lod += 1 lod = 0
surfaces = CityGml._lod1_solid(o) surfaces = []
elif 'lod1MultiSurface' in o['Building']: if 'lod1Solid' in buildingpart:
lod += 1 lod += 1
surfaces = CityGml._lod1_multi_surface(o) surfaces = CityGml._lod1_solid(o)
elif 'lod2MultiSurface' in o['Building']: elif 'lod1MultiSurface' in buildingpart:
# todo: check if this is a real case or a miss-formed citygml lod += 1
lod = 2 surfaces = CityGml._lod1_multi_surface(o)
surfaces = surfaces + CityGml._lod2_solid_multi_surface(o) elif 'lod2MultiSurface' in buildingpart:
else: # todo: check if this is a real case or a miss-formed citygml
for bound in o['Building']['boundedBy']: lod = 2
surface_type = next(iter(bound)) surfaces = surfaces + CityGml._lod2_solid_multi_surface(o)
if 'lod2MultiSurface' in bound[surface_type]: else:
lod = 2 for bound in buildingpart['boundedBy']:
surfaces = surfaces + CityGml._lod2(bound) surface_type = next(iter(bound))
if 'lod3Solid' in o['Building']: if 'lod2MultiSurface' in bound[surface_type]:
lod += 4 lod = 2
if 'lod4Solid' in o['Building']: surfaces = surfaces + CityGml._lod2(bound)
lod += 8 if 'lod3Solid' in o['Building']:
name = o['Building']['@id'] lod += 4
lod_terrain_str = 'lod' + str(lod) + 'TerrainIntersection' if 'lod4Solid' in o['Building']:
terrains = [] lod += 8
if lod_terrain_str in o['Building']: name = o['Building']['@id']
terrains = self._terrains(o, lod_terrain_str) lod_terrain_str = 'lod' + str(lod) + 'TerrainIntersection'
year_of_construction = None terrains = []
function = None if lod_terrain_str in o['Building']:
if 'yearOfConstruction' in o['Building']: terrains = self._terrains(o, lod_terrain_str)
year_of_construction = o['Building']['yearOfConstruction'] year_of_construction = None
if 'function' in o['Building']: function = None
function = o['Building']['function'] if 'yearOfConstruction' in buildingpart:
building = Building(name, lod, surfaces, year_of_construction, function, self._lower_corner, terrains) year_of_construction = buildingpart['yearOfConstruction']
self._city.add_city_object(building) 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 return self._city
def _terrains(self, city_object, lod_terrain_str): def _terrains(self, city_object, lod_terrain_str):
@ -147,8 +150,10 @@ class CityGml:
@staticmethod @staticmethod
def _lod2_solid_multi_surface(o): def _lod2_solid_multi_surface(o):
for i in buildingpart['boundedBy']:
surfacedata = i
polygons = [Polygon(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList'])) polygons = [Polygon(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod2MultiSurface']['MultiSurface']['surfaceMember']] for s in surfacedata['OuterCeilingSurface']['lod2MultiSurface']['MultiSurface']['surfaceMember']]
return [Surface(p,p) for p in polygons] return [Surface(p,p) for p in polygons]
@staticmethod @staticmethod
@ -176,7 +181,7 @@ class CityGml:
if 'CompositeSurface' in s: if 'CompositeSurface' in s:
surfaces = surfaces + CityGml._lod2_composite_surface(s) surfaces = surfaces + CityGml._lod2_composite_surface(s)
else: 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 return surfaces
@staticmethod @staticmethod