""" CityObject module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ from pathlib import Path from typing import List, Union from city_model_structure.attributes.surface import Surface from helpers.geometry_helper import GeometryHelper from city_model_structure.attributes.polyhedron import Polyhedron import math class CityObject: """ class CityObject """ def __init__(self, lod, surfaces, name): self._name = name self._lod = lod self._surfaces = surfaces self._detailed_polyhedron = None self._simplified_polyhedron = None self._geometry = GeometryHelper() @property def lod(self): """ City object level of detail 1, 2, 3 or 4 :return: int """ lod = math.log(self._lod, 2) + 1 return lod @property def volume(self): """ City object volume in cubic meters :return: float """ return self.detailed_polyhedron.volume @property def detailed_polyhedron(self): """ City object polyhedron including details such as holes :return: Polyhedron """ if self._detailed_polyhedron is None: polygons = [] for surface in self.surfaces: polygons.append(surface.solid_polygon) if surface.hole_polygons is not None: for hole_polygon in surface.hole_polygons: 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 @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 def location(self): """ City object location :return: [x,y,z] """ return self.simplified_polyhedron.center @property def max_height(self): """ City object maximal height in meters :return: float """ return self.simplified_polyhedron.max_z