2020-06-16 15:34:35 -04:00
|
|
|
"""
|
|
|
|
CityObject module
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
|
|
"""
|
2020-06-16 16:06:33 -04:00
|
|
|
from typing import List, Union
|
2020-10-28 13:14:05 -04:00
|
|
|
from city_model_structure.attributes.surface import Surface
|
|
|
|
from city_model_structure.attributes.polyhedron import Polyhedron
|
2021-04-01 10:36:07 -04:00
|
|
|
from helpers.configuration_helper import ConfigurationHelper
|
2021-03-01 16:42:03 -05:00
|
|
|
import math
|
2020-06-09 15:14:47 -04:00
|
|
|
|
2020-05-18 13:25:08 -04:00
|
|
|
|
|
|
|
class CityObject:
|
2020-06-16 15:34:35 -04:00
|
|
|
"""
|
|
|
|
class CityObject
|
|
|
|
"""
|
2021-04-01 10:36:07 -04:00
|
|
|
def __init__(self, lod, surfaces, name, city_lower_corner):
|
2020-06-16 16:19:14 -04:00
|
|
|
self._name = name
|
2020-05-18 13:25:08 -04:00
|
|
|
self._lod = lod
|
2020-06-16 16:06:33 -04:00
|
|
|
self._surfaces = surfaces
|
2021-04-01 10:36:07 -04:00
|
|
|
self._city_lower_corner = city_lower_corner
|
|
|
|
self._type = None
|
|
|
|
self._city_object_lower_corner = None
|
2021-03-08 18:27:14 -05:00
|
|
|
self._detailed_polyhedron = None
|
|
|
|
self._simplified_polyhedron = None
|
2021-04-01 10:36:07 -04:00
|
|
|
self._min_x = ConfigurationHelper().max_coordinate
|
|
|
|
self._min_y = ConfigurationHelper().max_coordinate
|
|
|
|
self._min_z = ConfigurationHelper().max_coordinate
|
|
|
|
self._centroid = None
|
|
|
|
self._external_temperature = dict()
|
|
|
|
self._global_horizontal = dict()
|
|
|
|
self._diffuse = dict()
|
|
|
|
self._beam = dict()
|
2020-06-16 15:34:35 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def lod(self):
|
|
|
|
"""
|
|
|
|
City object level of detail 1, 2, 3 or 4
|
|
|
|
:return: int
|
|
|
|
"""
|
2021-03-01 16:42:03 -05:00
|
|
|
lod = math.log(self._lod, 2) + 1
|
|
|
|
return lod
|
2020-06-16 16:06:33 -04:00
|
|
|
|
2021-04-01 10:36:07 -04:00
|
|
|
@property
|
|
|
|
def type(self):
|
|
|
|
"""
|
|
|
|
city object type
|
|
|
|
:return: str
|
|
|
|
"""
|
|
|
|
return self._type
|
|
|
|
|
2020-06-16 16:06:33 -04:00
|
|
|
@property
|
|
|
|
def volume(self):
|
|
|
|
"""
|
|
|
|
City object volume in cubic meters
|
|
|
|
:return: float
|
|
|
|
"""
|
2021-03-08 18:27:14 -05:00
|
|
|
return self.detailed_polyhedron.volume
|
2021-03-01 16:42:03 -05:00
|
|
|
|
|
|
|
@property
|
2021-03-08 18:27:14 -05:00
|
|
|
def detailed_polyhedron(self):
|
2021-03-01 16:42:03 -05:00
|
|
|
"""
|
2021-03-08 18:27:14 -05:00
|
|
|
City object polyhedron including details such as holes
|
2021-03-01 16:42:03 -05:00
|
|
|
:return: Polyhedron
|
|
|
|
"""
|
2021-03-08 18:27:14 -05:00
|
|
|
if self._detailed_polyhedron is None:
|
|
|
|
polygons = []
|
|
|
|
for surface in self.surfaces:
|
|
|
|
polygons.append(surface.solid_polygon)
|
2021-04-01 15:51:09 -04:00
|
|
|
if surface.holes_polygons is not None:
|
|
|
|
for hole_polygon in surface.holes_polygons:
|
2021-03-08 18:27:14 -05:00
|
|
|
polygons.append(hole_polygon)
|
|
|
|
self._detailed_polyhedron = Polyhedron(polygons)
|
|
|
|
return self._detailed_polyhedron
|
|
|
|
|
|
|
|
@property
|
|
|
|
def simplified_polyhedron(self):
|
|
|
|
"""
|
|
|
|
City object polyhedron, just the simple lod2 representation
|
|
|
|
:return: Polyhedron
|
|
|
|
"""
|
|
|
|
if self._simplified_polyhedron is None:
|
|
|
|
polygons = []
|
|
|
|
for surface in self.surfaces:
|
|
|
|
polygons.append(surface.perimeter_polygon)
|
|
|
|
self._simplified_polyhedron = Polyhedron(polygons)
|
|
|
|
return self._simplified_polyhedron
|
2020-06-16 16:06:33 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def surfaces(self) -> List[Surface]:
|
|
|
|
"""
|
|
|
|
City object surfaces
|
|
|
|
:return: [Surface]
|
|
|
|
"""
|
|
|
|
return self._surfaces
|
|
|
|
|
|
|
|
def surface(self, name) -> Union[Surface, None]:
|
|
|
|
"""
|
|
|
|
Get the city object surface with a given name
|
|
|
|
:param name: str
|
|
|
|
:return: None or Surface
|
|
|
|
"""
|
|
|
|
for s in self.surfaces:
|
|
|
|
if s.name == name:
|
|
|
|
return s
|
|
|
|
return None
|
|
|
|
|
|
|
|
@property
|
2021-03-25 09:11:42 -04:00
|
|
|
def centroid(self):
|
2020-06-16 16:06:33 -04:00
|
|
|
"""
|
2021-04-13 19:00:28 -04:00
|
|
|
City object centroid
|
2020-06-16 16:06:33 -04:00
|
|
|
:return: [x,y,z]
|
|
|
|
"""
|
2021-04-01 10:36:07 -04:00
|
|
|
if self._centroid is None:
|
|
|
|
self._centroid = self.simplified_polyhedron.centroid
|
|
|
|
return self._centroid
|
2020-11-04 08:54:10 -05:00
|
|
|
|
2020-06-16 16:19:14 -04:00
|
|
|
@property
|
|
|
|
def max_height(self):
|
|
|
|
"""
|
|
|
|
City object maximal height in meters
|
|
|
|
:return: float
|
|
|
|
"""
|
2021-03-08 18:27:14 -05:00
|
|
|
return self.simplified_polyhedron.max_z
|
2021-04-01 10:36:07 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def external_temperature(self) -> dict:
|
|
|
|
"""
|
|
|
|
external temperature surrounding the city object in grads Celsius
|
|
|
|
:return: dict{DataFrame(float)}
|
|
|
|
"""
|
|
|
|
return self._external_temperature
|
|
|
|
|
|
|
|
@external_temperature.setter
|
|
|
|
def external_temperature(self, value):
|
|
|
|
"""
|
|
|
|
external temperature surrounding the city object in grads Celsius
|
|
|
|
:param value: dict{DataFrame(float)}
|
|
|
|
"""
|
|
|
|
self._external_temperature = value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def global_horizontal(self) -> dict:
|
|
|
|
"""
|
|
|
|
global horizontal radiation surrounding the city object in W/m2
|
|
|
|
:return: dict{DataFrame(float)}
|
|
|
|
"""
|
|
|
|
return self._global_horizontal
|
|
|
|
|
|
|
|
@global_horizontal.setter
|
|
|
|
def global_horizontal(self, value):
|
|
|
|
"""
|
|
|
|
global horizontal radiation surrounding the city object in W/m2
|
|
|
|
:param value: dict{DataFrame(float)}
|
|
|
|
"""
|
|
|
|
self._global_horizontal = value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def diffuse(self) -> dict:
|
|
|
|
"""
|
|
|
|
diffuse radiation surrounding the city object in W/m2
|
|
|
|
:return: dict{DataFrame(float)}
|
|
|
|
"""
|
|
|
|
return self._diffuse
|
|
|
|
|
|
|
|
@diffuse.setter
|
|
|
|
def diffuse(self, value):
|
|
|
|
"""
|
|
|
|
diffuse radiation surrounding the city object in W/m2
|
|
|
|
:param value: dict{DataFrame(float)}
|
|
|
|
"""
|
|
|
|
self._diffuse = value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def beam(self) -> dict:
|
|
|
|
"""
|
|
|
|
beam radiation surrounding the city object in W/m2
|
|
|
|
:return: dict{DataFrame(float)}
|
|
|
|
"""
|
|
|
|
return self._beam
|
|
|
|
|
|
|
|
@beam.setter
|
|
|
|
def beam(self, value):
|
|
|
|
"""
|
|
|
|
beam radiation surrounding the city object in W/m2
|
|
|
|
:param value: dict{DataFrame(float)}
|
|
|
|
"""
|
|
|
|
self._beam = value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def city_object_lower_corner(self):
|
|
|
|
if self._city_object_lower_corner is None:
|
|
|
|
self._city_object_lower_corner = [self._min_x, self._min_y, self._min_z]
|
|
|
|
return self._city_object_lower_corner
|