partial correction geojson
This commit is contained in:
parent
f060197729
commit
742b6eb1be
|
@ -230,38 +230,134 @@ class Geojson:
|
||||||
return transformed_coordinates.lstrip(' ')
|
return transformed_coordinates.lstrip(' ')
|
||||||
|
|
||||||
def _parse_polygon(self, coordinates, building_name, function, year_of_construction, extrusion_height):
|
def _parse_polygon(self, coordinates, building_name, function, year_of_construction, extrusion_height):
|
||||||
print('poly')
|
|
||||||
for polygon_coordinates in coordinates:
|
|
||||||
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
|
|
||||||
building = Geojson._create_building_lod1(f'{building_name}',
|
|
||||||
year_of_construction,
|
|
||||||
function,
|
|
||||||
extrusion_height,
|
|
||||||
coordinates_3d)
|
|
||||||
return building
|
|
||||||
|
|
||||||
def _parse_multi_polygon(self, coordinates, building_name, function, year_of_construction, extrusion_height):
|
|
||||||
print('multi')
|
|
||||||
surfaces = []
|
surfaces = []
|
||||||
for polygon_coordinate in coordinates:
|
for polygon_coordinates in coordinates:
|
||||||
building = self._parse_polygon(polygon_coordinate, building_name, function, year_of_construction, 0)
|
points = igh.points_from_string(
|
||||||
for surface in building.surfaces:
|
igh.remove_last_point_from_string(
|
||||||
|
self._polygon_coordinates_to_3d(polygon_coordinates)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
points = igh.invert_points(points)
|
||||||
|
polygon = Polygon(points)
|
||||||
|
polygon.area = igh.ground_area(points)
|
||||||
|
surface = Surface(polygon, polygon)
|
||||||
|
print(surface.type, polygon.area)
|
||||||
if surface.type == cte.GROUND:
|
if surface.type == cte.GROUND:
|
||||||
surfaces.append(surface)
|
surfaces.append(surface)
|
||||||
else:
|
else:
|
||||||
# overwrite last surface by adding the "hole" in the polygon
|
distance = cte.MAX_FLOAT
|
||||||
polygon = Polygon(surfaces[-1].solid_polygon.coordinates + surface.solid_polygon.coordinates)
|
hole_connect = 0
|
||||||
|
surface_connect = 0
|
||||||
|
for hole_index, hole_coordinate in enumerate(polygon.coordinates):
|
||||||
|
for surface_index, ground_coordinate in enumerate(surfaces[-1].solid_polygon.coordinates):
|
||||||
|
current_distance = GeometryHelper.distance_between_points(hole_coordinate, ground_coordinate)
|
||||||
|
if current_distance < distance:
|
||||||
|
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]
|
||||||
|
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
|
||||||
|
polygon = Polygon(coordinates)
|
||||||
|
polygon.area = igh.ground_area(coordinates)
|
||||||
surfaces[-1] = Surface(polygon, polygon)
|
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:
|
if extrusion_height == 0:
|
||||||
return Building(building_name, surfaces, year_of_construction, function)
|
return building
|
||||||
|
else:
|
||||||
|
volume = 0
|
||||||
|
for ground in building.grounds:
|
||||||
|
volume += ground.solid_polygon.area * extrusion_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], extrusion_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'{building_name}', surfaces, year_of_construction, function)
|
||||||
|
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:
|
||||||
|
for polygon_coordinates in coordinates:
|
||||||
|
points = igh.points_from_string(
|
||||||
|
igh.remove_last_point_from_string(
|
||||||
|
self._polygon_coordinates_to_3d(polygon_coordinates)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
points = igh.invert_points(points)
|
||||||
|
polygon = Polygon(points)
|
||||||
|
polygon.area = igh.ground_area(points)
|
||||||
|
surface = Surface(polygon, polygon)
|
||||||
|
if surface.type == cte.GROUND:
|
||||||
|
surfaces.append(surface)
|
||||||
|
else:
|
||||||
|
distance = cte.MAX_FLOAT
|
||||||
|
hole_connect = 0
|
||||||
|
surface_connect = 0
|
||||||
|
for hole_index, hole_coordinate in enumerate(polygon.coordinates):
|
||||||
|
for surface_index, ground_coordinate in enumerate(surfaces[-1].solid_polygon.coordinates):
|
||||||
|
current_distance = GeometryHelper.distance_between_points(hole_coordinate, ground_coordinate)
|
||||||
|
if current_distance < distance:
|
||||||
|
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]
|
||||||
|
trail_coordinates = surfaces[-1].solid_polygon.coordinates[surface_connect:]
|
||||||
|
coordinates = prefix_coordinates + hole + [hole[0]] + trail_coordinates
|
||||||
|
polygon = Polygon(coordinates)
|
||||||
|
polygon.area = igh.ground_area(coordinates)
|
||||||
|
surfaces[-1] = Surface(polygon, polygon)
|
||||||
|
building = Building(building_name, surfaces, year_of_construction, function)
|
||||||
|
if extrusion_height == 0:
|
||||||
|
return building
|
||||||
else:
|
else:
|
||||||
volume = 0
|
volume = 0
|
||||||
for ground in building.grounds:
|
for ground in building.grounds:
|
||||||
|
|
|
@ -137,7 +137,7 @@ class TestGeometryFactory(TestCase):
|
||||||
"""
|
"""
|
||||||
Test geojson import
|
Test geojson import
|
||||||
"""
|
"""
|
||||||
file = 'hole_building.geojson'
|
file = '72.geojson'
|
||||||
city = GeometryFactory('geojson',
|
city = GeometryFactory('geojson',
|
||||||
path=(self._example_path / file).resolve(),
|
path=(self._example_path / file).resolve(),
|
||||||
height_field='citygml_me',
|
height_field='citygml_me',
|
||||||
|
@ -145,7 +145,12 @@ class TestGeometryFactory(TestCase):
|
||||||
name_field='ID_UEV',
|
name_field='ID_UEV',
|
||||||
function_field='CODE_UTILI',
|
function_field='CODE_UTILI',
|
||||||
function_to_hub=MontrealFunctionToHubFunction().dictionary).city
|
function_to_hub=MontrealFunctionToHubFunction().dictionary).city
|
||||||
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export_debug()
|
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(1964, len(city.buildings), 'wrong number of buildings')
|
||||||
|
|
||||||
def test_map_neighbours(self):
|
def test_map_neighbours(self):
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user