Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions geonode/upload/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ def test_geojson_task_is_called(self, patch_upload):

self.assertTrue(201, response.status_code)

@patch("geonode.upload.api.views.import_orchestrator")
def test_geojson_mixed_geometry_succed(self, patch_upload):
patch_upload.apply_async.side_effect = MagicMock()

self.client.force_login(get_user_model().objects.get(username="admin"))
payload = {
"base_file": SimpleUploadedFile(
name="test.geojson",
content=b'{"type": "FeatureCollection", "features": '
b'[{"type": "Feature", "properties": {}, "geometry": '
b'{"type": "Point", "coordinates": [1, 2]}}, '
b'{"type": "Feature", "properties": {}, "geometry": '
b'{"type": "Polygon", "coordinates": '
b"[[[1, 2], [1, 3], [2, 3], [2, 2], [1, 2]]]}}]}",
),
"store_spatial_files": True,
"action": "upload",
}

response = self.client.post(self.url, data=payload)

self.assertEqual(201, response.status_code)

@patch("geonode.upload.api.views.import_orchestrator")
def test_zip_file_is_unzip_and_the_handler_is_found(self, patch_upload):
patch_upload.apply_async.side_effect = MagicMock()
Expand Down
23 changes: 23 additions & 0 deletions geonode/upload/handlers/common/tests_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,29 @@ def test_has_incompatible_field_names(self):

self.assertFalse(has_incompatible_field_names(mock_layer_compatible))

def test_define_dynamic_layer_schema_with_unknown_type(self):
"""
Test that _define_dynamic_layer_schema correctly handles mixed geometry types.
"""
handler = BaseVectorFileHandler()
handler.identify_authority = MagicMock(return_value="EPSG:4326")

mock_layer = MagicMock(spec=ogr.Layer)
mock_layer.GetGeomType.return_value = ogr.wkbUnknown
mock_layer.GetGeometryColumn.return_value = "geom"
mock_layer.schema = []
mock_layer.GetName.return_value = "test_layer"
schema = handler._define_dynamic_layer_schema(mock_layer)
self.assertEqual(len(schema), 1)
geom_field = schema[0]
self.assertEqual(geom_field["name"], "geom")
self.assertEqual(
geom_field["class_name"],
"django.contrib.gis.db.models.fields.GeometryField",
)
self.assertEqual(geom_field["dim"], 2)
self.assertEqual(geom_field["authority"], "EPSG:4326")

def test_create_dynamic_model_fields(self):
try:
# Prepare the test
Expand Down
2 changes: 1 addition & 1 deletion geonode/upload/handlers/common/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def _define_dynamic_layer_schema(self, layer, **kwargs):
if (
layer.GetGeometryColumn()
or self.default_geometry_column_name
and ogr.GeometryTypeToName(layer.GetGeomType()) not in ["Geometry Collection", "Unknown (any)", "None"]
and ogr.GeometryTypeToName(layer.GetGeomType()) not in ["Geometry Collection", "None"]
):
# the geometry colum is not returned rom the layer.schema, so we need to extract it manually
layer_schema += [
Expand Down
2 changes: 1 addition & 1 deletion geonode/upload/handlers/gpkg/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def is_valid(files, user, **kwargs):

validator = validate(
gpkg_path=files.get("base_file"),
validations="RQ2, RQ13, RQ14, RQ15, RC18",
validations="RQ2, RQ13, RC18",
)
if not validator[-1]:
error_to_raise = []
Expand Down
1 change: 1 addition & 0 deletions geonode/upload/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"Multi Polygon": "django.contrib.gis.db.models.fields.MultiPolygonField",
"Multipolygon": "django.contrib.gis.db.models.fields.MultiPolygonField",
"3D Multi Polygon": "django.contrib.gis.db.models.fields.MultiPolygonField",
"Unknown (any)": "django.contrib.gis.db.models.fields.GeometryField",
}


Expand Down
Loading