added clusters to the city

This commit is contained in:
Pilar 2021-06-03 11:45:17 -04:00
parent f725ec9d4c
commit 311342e17e
4 changed files with 51 additions and 103 deletions

View File

@ -13,6 +13,9 @@ from pyproj import Transformer
from city_model_structure.building import Building from city_model_structure.building import Building
from city_model_structure.city_object import CityObject from city_model_structure.city_object import CityObject
from city_model_structure.city_objects_cluster import CityObjectsCluster
from city_model_structure.buildings_cluster import BuildingsCluster
from city_model_structure.parts_consisting_building import PartsConsistingBuilding
from helpers.geometry_helper import GeometryHelper from helpers.geometry_helper import GeometryHelper
from helpers.location import Location from helpers.location import Location
import math import math
@ -23,11 +26,11 @@ class City:
City class City class
""" """
def __init__(self, lower_corner, upper_corner, srs_name, buildings=None): def __init__(self, lower_corner, upper_corner, srs_name):
self._name = None self._name = None
self._lower_corner = lower_corner self._lower_corner = lower_corner
self._upper_corner = upper_corner self._upper_corner = upper_corner
self._buildings = buildings self._buildings = None
self._srs_name = srs_name self._srs_name = srs_name
self._geometry = GeometryHelper() self._geometry = GeometryHelper()
# todo: right now extracted at city level, in the future should be extracted also at building level if exist # todo: right now extracted at city level, in the future should be extracted also at building level if exist
@ -38,7 +41,9 @@ class City:
self._latitude = None self._latitude = None
self._longitude = None self._longitude = None
self._time_zone = None self._time_zone = None
self._generic_city_object = None self._buildings_clusters = None
self._parts_consisting_buildings = None
self._city_objects_clusters = None
def _get_location(self) -> Location: def _get_location(self) -> Location:
if self._location is None: if self._location is None:
@ -164,9 +169,7 @@ class City:
self._buildings = [] self._buildings = []
self._buildings.append(new_city_object) self._buildings.append(new_city_object)
else: else:
if self._generic_city_object is None: raise NotImplementedError
self._generic_city_object = []
self._generic_city_object.append(new_city_object)
def remove_city_object(self, city_object): def remove_city_object(self, city_object):
""" """
@ -286,3 +289,44 @@ class City:
:parameter value: real :parameter value: real
""" """
self._time_zone = value self._time_zone = value
@property
def buildings_clusters(self) -> Union[List[BuildingsCluster], None]:
"""
buildings clusters belonging to the city
:return: None or [BuildingsCluster]
"""
return self._buildings_clusters
@property
def parts_consisting_buildings(self) -> Union[List[PartsConsistingBuilding], None]:
"""
Parts consisting buildings belonging to the city
:return: None or [PartsConsistingBuilding]
"""
return self._parts_consisting_buildings
@property
def city_objects_clusters(self) -> Union[List[CityObjectsCluster], None]:
"""
City objects clusters belonging to the city
:return: None or [CityObjectsCluster]
"""
return self._city_objects_clusters
def add_city_objects_cluster(self, new_city_objects_cluster):
"""
Add a CityObject to the city
:param new_city_objects_cluster:CityObjectsCluster
:return: None
"""
if new_city_objects_cluster.type == 'buildings':
if self._buildings_clusters is None:
self._buildings_clusters = []
self._buildings_clusters.append(new_city_objects_cluster)
elif new_city_objects_cluster.type == 'building_parts':
if self._parts_consisting_buildings is None:
self._parts_consisting_buildings = []
self._parts_consisting_buildings.append(new_city_objects_cluster)
else:
raise NotImplementedError

View File

@ -95,106 +95,10 @@ class CityGml:
if self._city is None: if self._city is None:
self._city = City(self._lower_corner, self._upper_corner, self._srs_name) self._city = City(self._lower_corner, self._upper_corner, self._srs_name)
for o in self._gml['CityModel']['cityObjectMember']: for o in self._gml['CityModel']['cityObjectMember']:
city_object = o['Building'] city_object = o['Building']
if 'consistsOfBuildingPart' in city_object: if 'consistsOfBuildingPart' in city_object:
raise NotImplementedError("Building cluster") raise NotImplementedError("Building cluster")
'''
if 'lod1Solid' in o['Building']:
lod += 1
surfaces = CityGmlLod1.lod1_solid(o)
elif 'lod1MultiSurface' in o['Building']:
lod += 1
surfaces = CityGmlLod1.lod1_multi_surface(o)
elif 'lod2Solid' in o['Building'] :
lod += 1
surfaces = CityGmlLod2.lod2_solid(o)
elif 'lod2MultiSurface' in o['Building']:
# todo: check if this is a real case or a miss-formed citygml
lod = 2
surfaces = surfaces + CityGmlLod2.lod2_solid_multi_surface(o)
else: else:
self._city.add_city_object(self._create_building(city_object)) self._city.add_city_object(self._create_building(city_object))
return self._city return self._city
def _terrains(self, city_object, lod_terrain_str):
try:
curves = [c['LineString']['posList']['#text']
for c in city_object['Building'][lod_terrain_str]['MultiCurve']['curveMember']]
except TypeError:
curves = [c['LineString']['posList']
for c in city_object['Building'][lod_terrain_str]['MultiCurve']['curveMember']]
terrains = []
for curve in curves:
curve_points = np.fromstring(curve, dtype=float, sep=' ')
curve_points = self._geometry.to_points_matrix(curve_points)
terrains.append(curve_points)
return terrains
@staticmethod
def _holes_points(holes_coordinates) -> [np.ndarray]:
"""
Holes surfaces point matrices [[[x, y, z],[x, y, z],...]]
:parameter holes_coordinates: strings from file
:return: [np.ndarray]
"""
holes_points = []
for hole_coordinates in holes_coordinates:
hole_points = np.fromstring(hole_coordinates, dtype=float, sep=' ')
hole_points = GeometryHelper.to_points_matrix(hole_points)
holes_points.append(hole_points)
return holes_points
@staticmethod
def _perimeter_points(coordinates, solid_points, holes_points) -> np.ndarray:
"""
Matrix of points of the perimeter in the same order as in coordinates [[x, y, z],[x, y, z],...]
:parameter coordinates: string from file
:parameter solid_points: np.ndarray points that define the solid part of a surface
:parameter holes_points: [np.ndarray] points that define each the holes in a surface
:return: np.ndarray
"""
if holes_points is None:
perimeter_points = solid_points
else:
_perimeter_coordinates = coordinates
for hole_points in holes_points:
_hole = np.append(hole_points, hole_points[0])
_closed_hole = ' '.join(str(e) for e in [*_hole[:]])
# add a mark 'M' to ensure that the recombination of points does not provoke errors in finding holes
_perimeter_coordinates = _perimeter_coordinates.replace(_closed_hole, 'M')
_perimeter_coordinates = _perimeter_coordinates.replace('M', '')
perimeter_points = np.fromstring(_perimeter_coordinates, dtype=float, sep=' ')
perimeter_points = GeometryHelper.to_points_matrix(perimeter_points)
# remove duplicated points
pv = np.array([perimeter_points[0]])
for point in perimeter_points:
duplicated_point = False
for p in pv:
if GeometryHelper().almost_equal(0.0, p, point):
duplicated_point = True
if not duplicated_point:
pv = np.append(pv, [point], axis=0)
perimeter_points = pv
return perimeter_points
@staticmethod
def _holes_polygons(holes_points) -> [Polygon]:
"""
hole surfaces, a list of hole polygons found in a surface
:parameter holes_points: [np.ndarray] that define each of the holes
:return: None, [] or [Polygon]
None -> not known whether holes exist in reality or not due to low level of detail of input data
[] -> no holes in the surface
[Polygon] -> one or more holes in the surface
"""
if holes_points is None:
holes_polygons = None
else:
holes_polygons = []
for hole_points in holes_points:
holes_polygons.append(Polygon(hole_points))
return holes_polygons

View File

@ -38,7 +38,7 @@ class TestSensorsFactory(TestCase):
function = "office" function = "office"
buildings.append(Building("EV", lod, surfaces, year_of_construction, function, lower_corner)) buildings.append(Building("EV", lod, surfaces, year_of_construction, function, lower_corner))
buildings.append(Building("GM", lod, surfaces, year_of_construction, function, lower_corner)) buildings.append(Building("GM", lod, surfaces, year_of_construction, function, lower_corner))
city = City(lower_corner, upper_corner, srs_name, buildings) city = City(lower_corner, upper_corner, srs_name)
city.add_city_object(CityObject("GM_MB_EV", lod, surfaces, lower_corner)) city.add_city_object(CityObject("GM_MB_EV", lod, surfaces, lower_corner))
return city return city