city_retrofit/city_model_structure/city_object.py

68 lines
1.5 KiB
Python

"""
CityObject module
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from typing import List, Union
from city_model_structure.surface import Surface
from helpers.geometry_helper import GeometryHelper
from city_model_structure.polyhedron import Polyhedron
class CityObject:
"""
class CityObject
"""
def __init__(self, lod, surfaces):
self._lod = lod
self._surfaces = surfaces
self._polyhedron = None
self._geometry = GeometryHelper()
@property
def lod(self):
"""
City object level of detail 1, 2, 3 or 4
:return: int
"""
return self._lod
@property
def volume(self):
"""
City object volume in cubic meters
:return: float
"""
if self._polyhedron is None:
self._polyhedron = Polyhedron(self.surfaces)
return self._polyhedron.volume
@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]
"""
if self._polyhedron is None:
self._polyhedron = Polyhedron(self.surfaces)
return self._polyhedron.centroid