Neighbours mapping completed.

This commit is contained in:
Guille Gutierrez 2023-02-24 07:10:13 -05:00
parent a8d0d0e6ba
commit 48fbeb488f
3 changed files with 10 additions and 11 deletions

View File

@ -59,14 +59,14 @@ 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] / 1), (city.upper_corner[1] - coordinate[1] / 1)) return MapPoint(((city.upper_corner[0] - coordinate[0]) * 0.5), ((city.upper_corner[1] - coordinate[1]) * 0.5))
@staticmethod @staticmethod
def city_mapping(city, building_names=None): 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]) / 1) x = int((city.upper_corner[0] - city.lower_corner[0]) * 0.5) + 1
y = int((city.upper_corner[1] - city.lower_corner[1]) / 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_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 img = Image.new('RGB', (x + 1, y + 1), "black") # create a new black image
city_image = img.load() # create the pixel map city_image = img.load() # create the pixel map
@ -83,11 +83,11 @@ class GeometryHelper:
distance = GeometryHelper.distance_between_points(coordinate, next_coordinate) distance = GeometryHelper.distance_between_points(coordinate, next_coordinate)
if distance == 0: if distance == 0:
continue continue
delta_x = (coordinate[0] - next_coordinate[0]) / distance delta_x = (coordinate[0] - next_coordinate[0]) / (distance / 0.5)
delta_y = (coordinate[1] - next_coordinate[1]) / distance delta_y = (coordinate[1] - next_coordinate[1]) / (distance / 0.5)
for i in range(0, int(distance)): for k in range(0, int(distance)):
x = MapPoint(point.x + (delta_x * i), point.y + (delta_y * i)).x x = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).x
y = MapPoint(point.x + (delta_x * i), point.y + (delta_y * i)).y 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] = (100, 0, 0) city_image[x, y] = (100, 0, 0)

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

@ -142,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')
@ -155,7 +155,6 @@ class TestGeometryFactory(TestCase):
start = datetime.datetime.now() 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',
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() city_end = datetime.datetime.now()