diff --git a/autotest/ogr/ogr_geojson.py b/autotest/ogr/ogr_geojson.py index 5cc7b962ffb5..af1f55a5b640 100755 --- a/autotest/ogr/ogr_geojson.py +++ b/autotest/ogr/ogr_geojson.py @@ -2659,15 +2659,32 @@ def test_ogr_geojson_57(tmp_vsimem): got = read_file(tmp_vsimem / "out.json") gdal.Unlink(tmp_vsimem / "out.json") - expected = """{ -"type": "FeatureCollection", -"bbox": [ 45.0000000, 64.3861643, 135.0000000, 90.0000000 ], -"features": [ -{ "type": "Feature", "properties": { }, "bbox": [ 45.0, 64.3861643, 135.0, 90.0 ], "geometry": { "type": "Polygon", "coordinates": [ [ [ 135.0, 64.3861643 ], [ 135.0, 90.0 ], [ 45.0, 90.0 ], [ 45.0, 64.3861643 ], [ 135.0, 64.3861643 ] ] ] } } -] -} -""" - assert json.loads(got) == json.loads(expected) + expected = { + "type": "FeatureCollection", + "bbox": [45.0, 64.3861643, 135.0, 90.0], + "features": [ + { + "type": "Feature", + "properties": {}, + "bbox": [45.0, 64.3861643, 135.0, 90.0], + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [135.0, 64.3861643], + [135.0, 90.0], + [45.0, 90.0], + [45.0, 64.3861643], + [135.0, 64.3861643], + ] + ] + ], + }, + } + ], + } + assert json.loads(got) == expected # Polar case: slice of spherical cap crossing the antimeridian src_ds = gdal.GetDriverByName("Memory").Create("", 0, 0, 0) diff --git a/ogr/ogrgeometryfactory.cpp b/ogr/ogrgeometryfactory.cpp index 4b552e2b1921..b918af4086e5 100644 --- a/ogr/ogrgeometryfactory.cpp +++ b/ogr/ogrgeometryfactory.cpp @@ -3985,7 +3985,8 @@ OGRGeometry *OGRGeometryFactory::transformWithOptions( { // do nothing } - else if (poMulti->getNumGeometries() == 1) + else if (poMulti->getNumGeometries() == 1 && + (eType == wkbPolygon || eType == wkbLineString)) { poDstGeom = poMulti->stealGeometry(0); }