Merge remote-tracking branch 'origin/master' into shared_surfaces_method
# Conflicts: # hub/helpers/geometry_helper.py
This commit is contained in:
commit
2af1bf2e40
|
@ -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
|
@ -14,15 +14,36 @@ 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 PIL import Image
|
||||
|
||||
|
||||
class MapPoint:
|
||||
def __init__(self, x, y):
|
||||
self.x = int(x)
|
||||
self.y = int(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:
|
||||
"""
|
||||
|
@ -39,23 +60,17 @@ class GeometryHelper:
|
|||
|
||||
@staticmethod
|
||||
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
|
||||
def point_between_point(point_1, point_2, x):
|
||||
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):
|
||||
def city_mapping(city, building_names=None, plot=False):
|
||||
if building_names is None:
|
||||
building_names = [b.name for b in city.buildings]
|
||||
x = int((city.upper_corner[0] - city.lower_corner[0]) / 2)
|
||||
y = int((city.upper_corner[1] - city.lower_corner[1]) / 2)
|
||||
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)]
|
||||
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:
|
||||
building = city.city_object(building_name)
|
||||
for ground in building.grounds:
|
||||
|
@ -65,13 +80,18 @@ class GeometryHelper:
|
|||
if i == length:
|
||||
j = 0
|
||||
next_coordinate = ground.perimeter_polygon.coordinates[j]
|
||||
point_1 = GeometryHelper.coordinate_to_map_point(coordinate, city)
|
||||
point_2 = GeometryHelper.coordinate_to_map_point(next_coordinate, city)
|
||||
for x in range(point_1.x, point_2.x):
|
||||
y = GeometryHelper.point_between_point(point_1, point_2, x).y
|
||||
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] = 1
|
||||
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:
|
||||
|
@ -82,32 +102,8 @@ class GeometryHelper:
|
|||
neighbour.neighbours = [building]
|
||||
elif building not in neighbour.neighbours:
|
||||
neighbour.neighbours.append(building)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
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)
|
||||
"""
|
||||
if plot:
|
||||
img.show()
|
||||
|
||||
@staticmethod
|
||||
def segment_list_to_trimesh(lines) -> Trimesh:
|
||||
|
|
|
@ -87,7 +87,7 @@ class NrcanPhysicsParameters:
|
|||
for thermal_zone in thermal_zones:
|
||||
thermal_zone.additional_thermal_bridge_u_value = archetype.extra_loses_due_to_thermal_bridges
|
||||
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_off = archetype.infiltration_rate_for_ventilation_system_off
|
||||
for thermal_boundary in thermal_zone.thermal_boundaries:
|
||||
|
|
|
@ -19,11 +19,12 @@ class CityGml:
|
|||
"""
|
||||
CityGml class
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
path,
|
||||
extrusion_height_field=None,
|
||||
year_of_construction_field='yearOfConstruction',
|
||||
function_field='function',
|
||||
year_of_construction_field=None,
|
||||
function_field=None,
|
||||
function_to_hub=None):
|
||||
self._city = None
|
||||
self._lod = None
|
||||
|
@ -31,9 +32,11 @@ class CityGml:
|
|||
self._lod2_tags = ['lod2Solid', 'lod2MultiSurface', 'lod2MultiCurve']
|
||||
self._extrusion_height_field = extrusion_height_field
|
||||
self._function_to_hub = function_to_hub
|
||||
self._year_of_construction_field = year_of_construction_field
|
||||
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
|
||||
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
|
||||
|
||||
|
|
|
@ -103,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):
|
||||
|
@ -143,7 +142,7 @@ 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')
|
||||
|
@ -153,21 +152,10 @@ class TestGeometryFactory(TestCase):
|
|||
"""
|
||||
Test neighbours map creation
|
||||
"""
|
||||
start = datetime.datetime.now()
|
||||
file = 'concordia.geojson'
|
||||
city = self._get_city(file, 'geojson',
|
||||
height_field='citygml_me',
|
||||
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')
|
||||
GeometryHelper.city_mapping(city, plot=False)
|
||||
self.assertTrue(False)
|
||||
|
|
Loading…
Reference in New Issue
Block a user