Commit 14b6ba00 authored by Cecilia Nievas's avatar Cecilia Nievas
Browse files

Fixed issue of compatibility of geometry types to append to GPKG

parent 125100bc
Pipeline #47138 passed with stage
in 2 minutes and 31 seconds
......@@ -19,6 +19,8 @@
import logging
import numpy
import pandas
from shapely.wkt import loads
from shapely.geometry import MultiPolygon
from gdeimporter.tools.database import Database
......@@ -1053,7 +1055,11 @@ class DatabaseQueries:
obm_geometries[osm_id] = {}
obm_geometries[osm_id]["centroid_lon"] = raw_centroids_x[i]
obm_geometries[osm_id]["centroid_lat"] = raw_centroids_y[i]
obm_geometries[osm_id]["footprint"] = raw_footprints[i]
raw_footprint_i = raw_footprints[i]
# Ensure MultiPolygon so as to be able to append to GPKG format
if "MULTIPOLYGON" not in raw_footprint_i.upper():
raw_footprint_i = MultiPolygon([loads(raw_footprint_i)]).wkt
obm_geometries[osm_id]["footprint"] = raw_footprint_i
number_building_classes = len(raw_building_class_names[i])
osm_ids = numpy.hstack(
(osm_ids, numpy.array([osm_id for j in range(number_building_classes)]))
......
......@@ -229,6 +229,8 @@ def export_to_OpenQuake_CSV(
geometry=obm_geometries,
)
obm_footprints.crs = pyproj.CRS("epsg:4326")
# Consistency of all geometries being MultiPolygons guaranteed beforehand by
# DatabaseQueries.get_GDE_buildings (if mixed Polygons+MultiPols cannot append)
if os.path.exists(os.path.join(output_path, filename_footprints)): # append
obm_footprints.to_file(
os.path.join(output_path, filename_footprints), driver="GPKG", mode="a"
......
......@@ -463,6 +463,7 @@ def test_get_GDE_buildings(test_db):
assert round(expected_obm_geometries[osm_id]["centroid_lat"], 4) == round(
returned_obm_geometries[osm_id]["centroid_lat"], 4
)
assert "MULTIPOLYGON" in returned_obm_geometries[osm_id]["footprint"].upper()
for i in range(4):
assert round(
shapely.wkt.loads(expected_obm_geometries[osm_id]["footprint"]).bounds[0], 4
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment