diff --git a/hub/helpers/geometry_helper.py b/hub/helpers/geometry_helper.py index 6806a84b..2eac1826 100644 --- a/hub/helpers/geometry_helper.py +++ b/hub/helpers/geometry_helper.py @@ -56,13 +56,18 @@ class GeometryHelper: 'urn:adv:crs:ETRS89_UTM32*DE_DHHN92_NH': 'epsg:25832' } + @staticmethod + def factor(): + return 2.0 + def __init__(self, delta=0, area_delta=0): self._delta = delta self._area_delta = area_delta @staticmethod - 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)) + def coordinate_to_map_point( coordinate, city): + factor = GeometryHelper.factor() + return MapPoint(((city.upper_corner[0] - coordinate[0]) * factor), ((city.upper_corner[1] - coordinate[1]) * factor)) @staticmethod def city_mapping(city, building_names=None, plot=False): @@ -76,8 +81,9 @@ class GeometryHelper: lines_information = {} 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 + factor = GeometryHelper.factor() + x = int((city.upper_corner[0] - city.lower_corner[0]) * factor) + 1 + y = int((city.upper_corner[1] - city.lower_corner[1]) * factor) + 1 city_map = [['' for _ in range(y + 1)] for _ in range(x + 1)] map_info = [[{} for _ in range(y + 1)] for _ in range(x + 1)] img = Image.new('RGB', (x + 1, y + 1), "black") # create a new black image @@ -97,8 +103,8 @@ class GeometryHelper: distance = int(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) + delta_x = (coordinate[0] - next_coordinate[0]) / (distance / factor) + delta_y = (coordinate[1] - next_coordinate[1]) / (distance / factor) for k in range(0, 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 @@ -176,10 +182,11 @@ class GeometryHelper: @staticmethod def fast_city_mapping(city, building_names=None): lines_information = {} + factor = GeometryHelper.factor() 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 + x = int((city.upper_corner[0] - city.lower_corner[0]) * factor) + 1 + y = int((city.upper_corner[1] - city.lower_corner[1]) * factor) + 1 city_map = [['' for _ in range(y + 1)] for _ in range(x + 1)] for building_name in building_names: building = city.city_object(building_name) @@ -195,8 +202,8 @@ class GeometryHelper: distance = int(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) + delta_x = (coordinate[0] - next_coordinate[0]) / (distance / factor) + delta_y = (coordinate[1] - next_coordinate[1]) / (distance / factor) for k in range(0, 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 diff --git a/hub/unittests/test_geometry_factory.py b/hub/unittests/test_geometry_factory.py index 28504d06..fdbc43cf 100644 --- a/hub/unittests/test_geometry_factory.py +++ b/hub/unittests/test_geometry_factory.py @@ -181,11 +181,10 @@ class TestGeometryFactory(TestCase): """ Test neighbours map creation """ - file = 'extractedFINAL2.geojson' - file_path = (self._example_path / file).resolve() + file_path = (self._example_path / 'Citylayers_neighbours.geojson').resolve() city = GeometryFactory('geojson', path=file_path, - height_field='citygml_me', + height_field='heightmax', year_of_construction_field='ANNEE_CONS', name_field='OBJECTID_12', function_field='CODE_UTILI', @@ -194,7 +193,14 @@ class TestGeometryFactory(TestCase): UsageFactory('nrcan', city).enrich() info_lod1 = GeometryHelper.city_mapping(city, plot=True) print('info', info_lod1) - - EnergyBuildingsExportsFactory('idf', city, self._output_path).export() + for building in city.buildings: + print(building.name) + ns = '' + for n in building.neighbours: + ns = f'{ns} {n.name}' + for surface in n.surfaces: + print('shared', surface.percentage_shared) + print('\t', ns) + # EnergyBuildingsExportsFactory('idf', city, self._output_path).export()