Skip to content

Commit

Permalink
OGRGeometryFactory::transformWithOptions(): in WRAPDATELINE=YES mode,…
Browse files Browse the repository at this point in the history
… return a multi polygon if a input multi polygon has been provided

Fixes OSGeo#10686
  • Loading branch information
rouault committed Aug 30, 2024
1 parent 9343e24 commit 4f4373e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
35 changes: 26 additions & 9 deletions autotest/ogr/ogr_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion ogr/ogrgeometryfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4f4373e

Please sign in to comment.