Merge remote-tracking branch 'origin/mapping'
# Conflicts: # hub/imports/geometry/citygml.py
This commit is contained in:
commit
e070ee5779
|
@ -458,3 +458,5 @@ class City:
|
|||
:return: LevelOfDetail
|
||||
"""
|
||||
return self._level_of_detail
|
||||
|
||||
|
||||
|
|
|
@ -5,11 +5,13 @@ Copyright © 2022 Concordia CERC group
|
|||
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
from typing import List, Union
|
||||
|
||||
from hub.city_model_structure.iot.sensor import Sensor
|
||||
from hub.city_model_structure.building_demand.surface import Surface
|
||||
from hub.city_model_structure.attributes.polyhedron import Polyhedron
|
||||
|
||||
from hub.helpers.configuration_helper import ConfigurationHelper
|
||||
|
||||
|
||||
|
@ -33,6 +35,7 @@ class CityObject:
|
|||
self._diffuse = dict()
|
||||
self._beam = dict()
|
||||
self._sensors = []
|
||||
self._neighbours = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -224,3 +227,17 @@ class CityObject:
|
|||
:param value: [Sensor]
|
||||
"""
|
||||
self._sensors = value
|
||||
|
||||
@property
|
||||
def neighbours(self) -> Union[None, List[CityObject]]:
|
||||
"""
|
||||
Get the list of neighbour_objects and their properties associated to the current city_object
|
||||
"""
|
||||
return self._neighbours
|
||||
|
||||
@neighbours.setter
|
||||
def neighbours(self, value):
|
||||
"""
|
||||
Set the list of neighbour_objects and their properties associated to the current city_object
|
||||
"""
|
||||
self._neighbours = value
|
||||
|
|
|
@ -125,6 +125,7 @@ AUTOMOTIVE_FACILITY = 'automotive facility'
|
|||
PARKING_GARAGE = 'parking garage'
|
||||
RELIGIOUS = 'religious'
|
||||
NON_HEATED = 'non-heated'
|
||||
DATACENTER = 'datacenter'
|
||||
|
||||
LIGHTING = 'Lights'
|
||||
OCCUPANCY = 'Occupancy'
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,7 +13,36 @@ from trimesh import intersections
|
|||
from hub.city_model_structure.attributes.polygon import Polygon
|
||||
from hub.city_model_structure.attributes.polyhedron import Polyhedron
|
||||
from hub.helpers.location import Location
|
||||
from hub.helpers.configuration_helper import ConfigurationHelper
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
class MapPoint:
|
||||
def __init__(self, x, y):
|
||||
self._x = int(x)
|
||||
self._y = int(y)
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
return self._x
|
||||
|
||||
@property
|
||||
def y(self):
|
||||
return self._y
|
||||
|
||||
def __str__(self):
|
||||
return f'({self.x}, {self.y})'
|
||||
|
||||
def __len__(self):
|
||||
return 1
|
||||
|
||||
def __getitem__(self, index):
|
||||
if index == 0:
|
||||
return self._x
|
||||
elif index == 1:
|
||||
return self._y
|
||||
else:
|
||||
raise IndexError('Index error')
|
||||
|
||||
|
||||
class GeometryHelper:
|
||||
|
@ -29,15 +58,50 @@ class GeometryHelper:
|
|||
self._area_delta = area_delta
|
||||
|
||||
@staticmethod
|
||||
def adjacent_locations(location1, location2):
|
||||
"""
|
||||
Determine when two attributes may be adjacent or not based in the dis
|
||||
:param location1:
|
||||
:param location2:
|
||||
:return: Boolean
|
||||
"""
|
||||
max_distance = ConfigurationHelper().max_location_distance_for_shared_walls
|
||||
return GeometryHelper.distance_between_points(location1, location2) < max_distance
|
||||
def coordinate_to_map_point(coordinate, city):
|
||||
return MapPoint(((city.upper_corner[0] - coordinate[0]) * 0.5), ((city.upper_corner[1] - coordinate[1]) * 0.5))
|
||||
|
||||
@staticmethod
|
||||
def city_mapping(city, building_names=None):
|
||||
if building_names is None:
|
||||
building_names = [b.name for b in city.buildings]
|
||||
x = int((city.upper_corner[0] - city.lower_corner[0]) * 0.5) + 1
|
||||
y = int((city.upper_corner[1] - city.lower_corner[1]) * 0.5) + 1
|
||||
city_map = [['' for _ in range(y + 1)] for _ in range(x + 1)]
|
||||
img = Image.new('RGB', (x + 1, y + 1), "black") # create a new black image
|
||||
city_image = img.load() # create the pixel map
|
||||
for building_name in building_names:
|
||||
building = city.city_object(building_name)
|
||||
for ground in building.grounds:
|
||||
length = len(ground.perimeter_polygon.coordinates) - 1
|
||||
for i, coordinate in enumerate(ground.perimeter_polygon.coordinates):
|
||||
j = i + 1
|
||||
if i == length:
|
||||
j = 0
|
||||
next_coordinate = ground.perimeter_polygon.coordinates[j]
|
||||
point = GeometryHelper.coordinate_to_map_point(coordinate, city)
|
||||
distance = GeometryHelper.distance_between_points(coordinate, next_coordinate)
|
||||
if distance == 0:
|
||||
continue
|
||||
delta_x = (coordinate[0] - next_coordinate[0]) / (distance / 0.5)
|
||||
delta_y = (coordinate[1] - next_coordinate[1]) / (distance / 0.5)
|
||||
for k in range(0, int(distance)):
|
||||
x = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).x
|
||||
y = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).y
|
||||
if city_map[x][y] == '':
|
||||
city_map[x][y] = building.name
|
||||
city_image[x, y] = (100, 0, 0)
|
||||
elif city_map[x][y] != building.name:
|
||||
neighbour = city.city_object(city_map[x][y])
|
||||
if building.neighbours is None:
|
||||
building.neighbours = [neighbour]
|
||||
elif neighbour not in building.neighbours:
|
||||
building.neighbours.append(neighbour)
|
||||
if neighbour.neighbours is None:
|
||||
neighbour.neighbours = [building]
|
||||
elif building not in neighbour.neighbours:
|
||||
neighbour.neighbours.append(building)
|
||||
img.show()
|
||||
|
||||
@staticmethod
|
||||
def segment_list_to_trimesh(lines) -> Trimesh:
|
||||
|
@ -148,6 +212,6 @@ class GeometryHelper:
|
|||
"""
|
||||
power = 0
|
||||
for dimension in range(0, len(vertex1)):
|
||||
power += math.pow(vertex2[dimension]-vertex1[dimension], 2)
|
||||
power += math.pow(vertex2[dimension] - vertex1[dimension], 2)
|
||||
distance = math.sqrt(power)
|
||||
return distance
|
||||
|
|
|
@ -19,6 +19,7 @@ class CityGml:
|
|||
"""
|
||||
CityGml class
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
path,
|
||||
extrusion_height_field=None,
|
||||
|
@ -31,11 +32,11 @@ class CityGml:
|
|||
self._lod2_tags = ['lod2Solid', 'lod2MultiSurface', 'lod2MultiCurve']
|
||||
self._extrusion_height_field = extrusion_height_field
|
||||
self._function_to_hub = function_to_hub
|
||||
if function_field is None:
|
||||
function_field = 'function'
|
||||
if year_of_construction_field is None:
|
||||
year_of_construction_field = 'yearOfConstruction'
|
||||
self._year_of_construction_field = year_of_construction_field
|
||||
if function_field is None:
|
||||
function_field = 'function'
|
||||
self._function_field = function_field
|
||||
|
||||
self._lower_corner = None
|
||||
|
|
|
@ -64,7 +64,7 @@ class Geojson:
|
|||
for zone, surface_coordinates in enumerate(surfaces_coordinates):
|
||||
points = GeometryHelper.points_from_string(GeometryHelper.remove_last_point_from_string(surface_coordinates))
|
||||
polygon = Polygon(points)
|
||||
surfaces.append(Surface(polygon, polygon))
|
||||
surfaces.append(Surface(polygon, polygon, surface_type=cte.GROUND))
|
||||
buildings.append(Building(f'{name}_zone_{zone}', surfaces, year_of_construction, function))
|
||||
return buildings
|
||||
|
||||
|
|
|
@ -4,8 +4,10 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|||
Copyright © 2022 Concordia CERC group
|
||||
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
"""
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
from hub.helpers.geometry_helper import GeometryHelper
|
||||
|
||||
from numpy import inf
|
||||
|
||||
|
@ -101,12 +103,11 @@ class TestGeometryFactory(TestCase):
|
|||
:return: None
|
||||
"""
|
||||
file = 'FZK_Haus_LoD_2.gml'
|
||||
city = self._get_city(file, 'citygml', year_of_construction_field='yearOfConstruction')
|
||||
city = self._get_city(file, 'citygml')
|
||||
self.assertTrue(len(city.buildings) == 1)
|
||||
self._check_buildings(city)
|
||||
for building in city.buildings:
|
||||
self._check_surfaces(building)
|
||||
building.year_of_construction = 2006
|
||||
city = ConstructionFactory('nrel', city).enrich()
|
||||
|
||||
def test_import_rhino(self):
|
||||
|
@ -141,8 +142,30 @@ class TestGeometryFactory(TestCase):
|
|||
city = self._get_city(file, 'geojson',
|
||||
height_field='citygml_me',
|
||||
year_of_construction_field='ANNEE_CONS',
|
||||
function_field='LIBELLE_UT')
|
||||
function_field='CODE_UTILI')
|
||||
|
||||
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
|
||||
self.assertEqual(207, len(city.buildings), 'wrong number of buildings')
|
||||
self._check_buildings(city)
|
||||
|
||||
def test_map_neighbours(self):
|
||||
"""
|
||||
Test neighbours map creation
|
||||
"""
|
||||
start = datetime.datetime.now()
|
||||
file = 'concordia.geojson'
|
||||
city = self._get_city(file, 'geojson',
|
||||
year_of_construction_field='ANNEE_CONS',
|
||||
function_field='LIBELLE_UT')
|
||||
city_end = datetime.datetime.now()
|
||||
print(f'city load {city_end-start}')
|
||||
GeometryHelper.city_mapping(city)
|
||||
end = datetime.datetime.now()
|
||||
print(f'city map {end-city_end}')
|
||||
|
||||
for building in city.buildings:
|
||||
if building.neighbours is not None:
|
||||
print(f'{building.name} [{[b.name for b in building.neighbours]}]')
|
||||
else:
|
||||
print(f'{building.name} has no neighbours')
|
||||
self.assertTrue(False)
|
||||
|
|
Loading…
Reference in New Issue
Block a user