Merge remote-tracking branch 'origin/master' into shared_surfaces_method

# Conflicts:
#	hub/helpers/geometry_helper.py
This commit is contained in:
Guille Gutierrez 2023-02-24 07:21:14 -05:00
commit 2af1bf2e40
7 changed files with 625 additions and 726 deletions

View File

@ -125,6 +125,7 @@ AUTOMOTIVE_FACILITY = 'automotive facility'
PARKING_GARAGE = 'parking garage' PARKING_GARAGE = 'parking garage'
RELIGIOUS = 'religious' RELIGIOUS = 'religious'
NON_HEATED = 'non-heated' NON_HEATED = 'non-heated'
DATACENTER = 'datacenter'
LIGHTING = 'Lights' LIGHTING = 'Lights'
OCCUPANCY = 'Occupancy' OCCUPANCY = 'Occupancy'

File diff suppressed because it is too large Load Diff

View File

@ -14,15 +14,36 @@ from hub.city_model_structure.attributes.polygon import Polygon
from hub.city_model_structure.attributes.polyhedron import Polyhedron from hub.city_model_structure.attributes.polyhedron import Polyhedron
from hub.helpers.location import Location from hub.helpers.location import Location
from PIL import Image
class MapPoint: class MapPoint:
def __init__(self, x, y): def __init__(self, x, y):
self.x = int(x) self._x = int(x)
self.y = int(y) self._y = int(y)
@property
def x(self):
return self._x
@property
def y(self):
return self._y
def __str__(self): def __str__(self):
return f'({self.x}, {self.y})' 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: class GeometryHelper:
""" """
@ -39,23 +60,17 @@ class GeometryHelper:
@staticmethod @staticmethod
def coordinate_to_map_point(coordinate, city): def coordinate_to_map_point(coordinate, city):
return MapPoint((city.upper_corner[0] - coordinate[0])/2, (city.upper_corner[1] - coordinate[1])/2) return MapPoint(((city.upper_corner[0] - coordinate[0]) * 0.5), ((city.upper_corner[1] - coordinate[1]) * 0.5))
@staticmethod @staticmethod
def point_between_point(point_1, point_2, x): def city_mapping(city, building_names=None, plot=False):
m = (point_1.y - point_2.y)/(point_1.x - point_2.x)
c = point_2.y - (m*point_2.x)
y = (m*x)+c
return MapPoint(x, y)
@staticmethod
def city_mapping(city, building_names=None):
if building_names is None: if building_names is None:
building_names = [b.name for b in city.buildings] building_names = [b.name for b in city.buildings]
x = int((city.upper_corner[0] - city.lower_corner[0]) / 2) x = int((city.upper_corner[0] - city.lower_corner[0]) * 0.5) + 1
y = int((city.upper_corner[1] - city.lower_corner[1]) / 2) 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)] city_map = [['' for _ in range(y + 1)] for _ in range(x + 1)]
city_image = [[0 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: for building_name in building_names:
building = city.city_object(building_name) building = city.city_object(building_name)
for ground in building.grounds: for ground in building.grounds:
@ -65,13 +80,18 @@ class GeometryHelper:
if i == length: if i == length:
j = 0 j = 0
next_coordinate = ground.perimeter_polygon.coordinates[j] next_coordinate = ground.perimeter_polygon.coordinates[j]
point_1 = GeometryHelper.coordinate_to_map_point(coordinate, city) point = GeometryHelper.coordinate_to_map_point(coordinate, city)
point_2 = GeometryHelper.coordinate_to_map_point(next_coordinate, city) distance = GeometryHelper.distance_between_points(coordinate, next_coordinate)
for x in range(point_1.x, point_2.x): if distance == 0:
y = GeometryHelper.point_between_point(point_1, point_2, x).y 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] == '': if city_map[x][y] == '':
city_map[x][y] = building.name city_map[x][y] = building.name
city_image[x][y] = 1 city_image[x, y] = (100, 0, 0)
elif city_map[x][y] != building.name: elif city_map[x][y] != building.name:
neighbour = city.city_object(city_map[x][y]) neighbour = city.city_object(city_map[x][y])
if building.neighbours is None: if building.neighbours is None:
@ -82,32 +102,8 @@ class GeometryHelper:
neighbour.neighbours = [building] neighbour.neighbours = [building]
elif building not in neighbour.neighbours: elif building not in neighbour.neighbours:
neighbour.neighbours.append(building) neighbour.neighbours.append(building)
if plot:
img.show()
"""
x = int((city.upper_corner[0] - coordinate[0]) / 2)
y = int((city.upper_corner[1] - coordinate[1]) / 2)
if city_map[x][y] == '':
city_map[x][y] = building.name
city_image[x][y] = 1
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)
"""
@staticmethod @staticmethod
def segment_list_to_trimesh(lines) -> Trimesh: def segment_list_to_trimesh(lines) -> Trimesh:

View File

@ -87,7 +87,7 @@ class NrcanPhysicsParameters:
for thermal_zone in thermal_zones: for thermal_zone in thermal_zones:
thermal_zone.additional_thermal_bridge_u_value = archetype.extra_loses_due_to_thermal_bridges thermal_zone.additional_thermal_bridge_u_value = archetype.extra_loses_due_to_thermal_bridges
thermal_zone.effective_thermal_capacity = archetype.thermal_capacity thermal_zone.effective_thermal_capacity = archetype.thermal_capacity
thermal_zone.indirectly_heated_area_ratio = archetype.indirect_heated_ratio thermal_zone.indirectly_heated_area_ratio = 0
thermal_zone.infiltration_rate_system_on = archetype.infiltration_rate_for_ventilation_system_on thermal_zone.infiltration_rate_system_on = archetype.infiltration_rate_for_ventilation_system_on
thermal_zone.infiltration_rate_system_off = archetype.infiltration_rate_for_ventilation_system_off thermal_zone.infiltration_rate_system_off = archetype.infiltration_rate_for_ventilation_system_off
for thermal_boundary in thermal_zone.thermal_boundaries: for thermal_boundary in thermal_zone.thermal_boundaries:

View File

@ -19,11 +19,12 @@ class CityGml:
""" """
CityGml class CityGml class
""" """
def __init__(self, def __init__(self,
path, path,
extrusion_height_field=None, extrusion_height_field=None,
year_of_construction_field='yearOfConstruction', year_of_construction_field=None,
function_field='function', function_field=None,
function_to_hub=None): function_to_hub=None):
self._city = None self._city = None
self._lod = None self._lod = None
@ -31,9 +32,11 @@ class CityGml:
self._lod2_tags = ['lod2Solid', 'lod2MultiSurface', 'lod2MultiCurve'] self._lod2_tags = ['lod2Solid', 'lod2MultiSurface', 'lod2MultiCurve']
self._extrusion_height_field = extrusion_height_field self._extrusion_height_field = extrusion_height_field
self._function_to_hub = function_to_hub self._function_to_hub = function_to_hub
self._year_of_construction_field = year_of_construction_field
if function_field is None: if function_field is None:
function_field = 'function' function_field = 'function'
if year_of_construction_field is None:
year_of_construction_field = 'yearOfConstruction'
self._year_of_construction_field = year_of_construction_field
self._function_field = function_field self._function_field = function_field
self._lower_corner = None self._lower_corner = None

View File

@ -64,7 +64,7 @@ class Geojson:
for zone, surface_coordinates in enumerate(surfaces_coordinates): for zone, surface_coordinates in enumerate(surfaces_coordinates):
points = GeometryHelper.points_from_string(GeometryHelper.remove_last_point_from_string(surface_coordinates)) points = GeometryHelper.points_from_string(GeometryHelper.remove_last_point_from_string(surface_coordinates))
polygon = Polygon(points) 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)) buildings.append(Building(f'{name}_zone_{zone}', surfaces, year_of_construction, function))
return buildings return buildings

View File

@ -103,12 +103,11 @@ class TestGeometryFactory(TestCase):
:return: None :return: None
""" """
file = 'FZK_Haus_LoD_2.gml' 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.assertTrue(len(city.buildings) == 1)
self._check_buildings(city) self._check_buildings(city)
for building in city.buildings: for building in city.buildings:
self._check_surfaces(building) self._check_surfaces(building)
building.year_of_construction = 2006
city = ConstructionFactory('nrel', city).enrich() city = ConstructionFactory('nrel', city).enrich()
def test_import_rhino(self): def test_import_rhino(self):
@ -143,7 +142,7 @@ class TestGeometryFactory(TestCase):
city = self._get_city(file, 'geojson', city = self._get_city(file, 'geojson',
height_field='citygml_me', height_field='citygml_me',
year_of_construction_field='ANNEE_CONS', 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() hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
self.assertEqual(207, len(city.buildings), 'wrong number of buildings') self.assertEqual(207, len(city.buildings), 'wrong number of buildings')
@ -153,21 +152,10 @@ class TestGeometryFactory(TestCase):
""" """
Test neighbours map creation Test neighbours map creation
""" """
start = datetime.datetime.now()
file = 'concordia.geojson' file = 'concordia.geojson'
city = self._get_city(file, 'geojson', city = self._get_city(file, 'geojson',
height_field='citygml_me', height_field='citygml_me',
year_of_construction_field='ANNEE_CONS', year_of_construction_field='ANNEE_CONS',
function_field='LIBELLE_UT') function_field='LIBELLE_UT')
city_end = datetime.datetime.now() GeometryHelper.city_mapping(city, plot=False)
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) self.assertTrue(False)