complete geojson correction

This commit is contained in:
Guille Gutierrez 2023-05-04 11:28:16 -04:00
parent 742b6eb1be
commit b6aa6fb86a
3 changed files with 23308 additions and 81 deletions

View File

@ -60,53 +60,6 @@ class Geojson:
if y < self._min_y:
self._min_y = y
@staticmethod
def _create_building_lod0(name, year_of_construction, function, surface_coordinates):
points = igh.points_from_string(igh.remove_last_point_from_string(surface_coordinates))
points = igh.invert_points(points)
polygon = Polygon(points)
polygon.area = igh.ground_area(points)
surface = Surface(polygon, polygon, name=f'{name}_ground')
return Building(f'{name}', [surface], year_of_construction, function)
@staticmethod
def _create_building_lod1(name, year_of_construction, function, height, surface_coordinates):
building = Geojson._create_building_lod0(name, year_of_construction, function, surface_coordinates)
surfaces = []
volume = 0
for ground in building.grounds:
volume += ground.solid_polygon.area * height
surfaces.append(ground)
roof_coordinates = []
# adding a roof means invert the polygon coordinates and change the Z value
for coordinate in ground.solid_polygon.coordinates:
roof_coordinate = np.array([coordinate[0], coordinate[1], height])
# insert the roof rotated already
roof_coordinates.insert(0, roof_coordinate)
roof_polygon = Polygon(roof_coordinates)
roof_polygon.area = ground.solid_polygon.area
roof = Surface(roof_polygon, roof_polygon)
surfaces.append(roof)
# adding a wall means add the point coordinates and the next point coordinates with Z's height and 0
coordinates_length = len(roof.solid_polygon.coordinates)
for i, coordinate in enumerate(roof.solid_polygon.coordinates):
j = i + 1
if j == coordinates_length:
j = 0
next_coordinate = roof.solid_polygon.coordinates[j]
wall_coordinates = [
np.array([coordinate[0], coordinate[1], 0.0]),
np.array([next_coordinate[0], next_coordinate[1], 0.0]),
np.array([next_coordinate[0], next_coordinate[1], next_coordinate[2]]),
np.array([coordinate[0], coordinate[1], coordinate[2]])
]
polygon = Polygon(wall_coordinates)
wall = Surface(polygon, polygon)
surfaces.append(wall)
building = Building(f'{name}', surfaces, year_of_construction, function)
building.volume = volume
return building
def _get_polygons(self, polygons, coordinates):
if type(coordinates[0][self.X]) != float:
polygons = []
@ -241,7 +194,6 @@ class Geojson:
polygon = Polygon(points)
polygon.area = igh.ground_area(points)
surface = Surface(polygon, polygon)
print(surface.type, polygon.area)
if surface.type == cte.GROUND:
surfaces.append(surface)
else:
@ -255,17 +207,17 @@ class Geojson:
distance = current_distance
hole_connect = hole_index
surface_connect = surface_index
hole = polygon.coordinates[hole_connect:] + polygon.coordinates[:hole_connect]
prefix_coordinates = surfaces[-1].solid_polygon.coordinates[:surface_connect]
hole = polygon.coordinates[hole_connect:] + polygon.coordinates[:hole_connect] + [polygon.coordinates[hole_connect]]
prefix_coordinates = surfaces[-1].solid_polygon.coordinates[:surface_connect+1]
trail_coordinates = surfaces[-1].solid_polygon.coordinates[surface_connect:]
coordinates = prefix_coordinates + hole + [hole[0], surfaces[-1].solid_polygon.coordinates[surface_connect-1]] + trail_coordinates
coordinates = prefix_coordinates + hole + trail_coordinates
polygon = Polygon(coordinates)
polygon.area = igh.ground_area(coordinates)
surfaces[-1] = Surface(polygon, polygon)
if len(surfaces) > 1:
raise ValueError('too many surfaces!!!!')
building = Building(building_name, surfaces, year_of_construction, function)
print(extrusion_height)
if extrusion_height == 0:
return building
else:
@ -303,25 +255,6 @@ class Geojson:
building.volume = volume
return building
"""
coordinates_3d = self._polygon_coordinates_to_3d(polygon_coordinates)
if extrusion_height == 0:
building = Geojson._create_building_lod0(f'{building_name}',
year_of_construction,
function,
coordinates_3d)
else:
if self._max_z < extrusion_height:
self._max_z = extrusion_height
print(building_name)
building = Geojson._create_building_lod1(f'{building_name}',
year_of_construction,
function,
extrusion_height,
coordinates_3d)
return building
"""
def _parse_multi_polygon(self, polygons_coordinates, building_name, function, year_of_construction, extrusion_height):
surfaces = []
for coordinates in polygons_coordinates:

View File

@ -137,21 +137,16 @@ class TestGeometryFactory(TestCase):
"""
Test geojson import
"""
file = '72.geojson'
file = Path(self._example_path / '2000_buildings.geojson').resolve()
city = GeometryFactory('geojson',
path=(self._example_path / file).resolve(),
height_field='citygml_me',
path=file,
height_field='building_height',
year_of_construction_field='ANNEE_CONS',
name_field='ID_UEV',
function_field='CODE_UTILI',
function_to_hub=MontrealFunctionToHubFunction().dictionary).city
for building in city.buildings:
volume = building.volume
print(volume)
if f'{volume}' == 'inf':
print(building.name, 'is not closed')
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
self.assertEqual(1964, len(city.buildings), 'wrong number of buildings')
self.assertEqual(1974, len(city.buildings), 'wrong number of buildings')
def test_map_neighbours(self):
"""

File diff suppressed because it is too large Load Diff