From d37f8bc68c12707986d69f33ceed144375a841cb Mon Sep 17 00:00:00 2001 From: guille Date: Thu, 3 Jun 2021 13:35:16 -0400 Subject: [PATCH] Fixt test and implement lod2 with multiparts --- imports/geometry/citygml_lod2.py | 18 +++++++++- .../sensors/concordia_energy_consumption.py | 34 +++++++++++-------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/imports/geometry/citygml_lod2.py b/imports/geometry/citygml_lod2.py index 7bd3a703..d1d7e2b3 100644 --- a/imports/geometry/citygml_lod2.py +++ b/imports/geometry/citygml_lod2.py @@ -57,4 +57,20 @@ class CityGmlLod2(CityGmlBase): @classmethod def _multi_surface(cls, o): - raise NotImplementedError('multi surface') + surfaces = [] + for b in o["boundedBy"]: + try: + surface_type = next(iter(b)) + except TypeError: + continue + surface_encoding, surface_subtype = cls._surface_encoding(b[surface_type]) + for member in b[surface_type][surface_encoding][surface_subtype]['surfaceMember']: + if '@srsDimension' in member['Polygon']['exterior']['LinearRing']['posList']: + gml_points = member['Polygon']['exterior']['LinearRing']['posList']["#text"] + else: + gml_points = member['Polygon']['exterior']['LinearRing']['posList'] + sp = cls._solid_points(cls._remove_last_point(gml_points)) + p = Polygon(sp) + surface = Surface(p, p, surface_type=GeometryHelper.gml_surface_to_libs(surface_type)) + surfaces.append(surface) + return surfaces diff --git a/imports/sensors/concordia_energy_consumption.py b/imports/sensors/concordia_energy_consumption.py index e82cddff..f60289f6 100644 --- a/imports/sensors/concordia_energy_consumption.py +++ b/imports/sensors/concordia_energy_consumption.py @@ -13,19 +13,23 @@ class ConcordiaEnergyConsumption(ConcordiaFileReport): def __init__(self, city, end_point, base_path): super().__init__(city, end_point, base_path, 'concordia_energy_db.json') for city_object in city.city_objects: - for i in range(len(self._city_object)): - if self._city_object[i] == city_object.name and self._sensors[i] in self._sensor_point: - building_measures = [self._measures["Date time"], self._measures[self._sensor_point[self._sensors[i]]]] - building_headers = ["Date time", "Energy consumption"] - building_energy_consumption = pd.concat(building_measures, keys=building_headers, axis=1) - sensor = ConcordiaEnergySensor(self._sensors[i]) - sensor_exist = False - for j in range(len(city_object.sensors)): - if city_object.sensors[j].name is sensor.name: - city_object.sensors[j].add_period(building_energy_consumption) - sensor_exist = True - break - if not sensor_exist: - sensor.add_period(building_energy_consumption) - city_object.sensors.append(sensor) + self._assign_sensor_to_object(city_object) + for city_object_cluster in city.city_objects_cluster: + self._assign_sensor_to_object(city_object_cluster) + def _assign_sensor_to_object(self, obj): + for i in range(len(self._city_object)): + if self._city_object[i] == obj.name and self._sensors[i] in self._sensor_point: + building_measures = [self._measures["Date time"], self._measures[self._sensor_point[self._sensors[i]]]] + building_headers = ["Date time", "Energy consumption"] + building_energy_consumption = pd.concat(building_measures, keys=building_headers, axis=1) + sensor = ConcordiaEnergySensor(self._sensors[i]) + sensor_exist = False + for j in range(len(object.sensors)): + if obj.sensors[j].name is sensor.name: + obj.sensors[j].add_period(building_energy_consumption) + sensor_exist = True + break + if not sensor_exist: + sensor.add_period(building_energy_consumption) + obj.sensors.append(sensor)