From a7994b8da1a78bdf2588267c03ca1a70012ebcac Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 14 Dec 2024 01:30:53 +0100 Subject: [PATCH] GML: honour SWAP_COORDINATES=YES even when the geometry has no SRS Fixes #11491 --- autotest/ogr/ogr_gml.py | 49 +++++++++++++++++++++++++++ ogr/ogrsf_frmts/gmlutils/gmlutils.cpp | 4 +++ 2 files changed, 53 insertions(+) diff --git a/autotest/ogr/ogr_gml.py b/autotest/ogr/ogr_gml.py index a67f58951d51..09fefa69fa25 100755 --- a/autotest/ogr/ogr_gml.py +++ b/autotest/ogr/ogr_gml.py @@ -3559,6 +3559,55 @@ def test_ogr_gml_78(tmp_vsimem): ds = None +############################################################################### +# Test effect of SWAP_COORDINATES when there is no SRS +# (https://github.com/OSGeo/gdal/issues/11491) + + +def test_ogr_gml_SWAP_COORDINATES_no_srs(tmp_vsimem): + + gdal.FileFromMemBuffer( + tmp_vsimem / "test_ogr_gml_SWAP_COORDINATES_no_srs.xml", + """ + + + + 2 49 + 1 + + + +""", + ) + + ds = ogr.Open(tmp_vsimem / "test_ogr_gml_SWAP_COORDINATES_no_srs.xml") + lyr = ds.GetLayer(0) + f = lyr.GetNextFeature() + assert f.GetGeometryRef().ExportToWkt() == "POINT (2 49)" + ds = None + + ds = gdal.OpenEx( + tmp_vsimem / "test_ogr_gml_SWAP_COORDINATES_no_srs.xml", + open_options=["SWAP_COORDINATES=YES"], + ) + lyr = ds.GetLayer(0) + f = lyr.GetNextFeature() + assert f.GetGeometryRef().ExportToWkt() == "POINT (49 2)" + ds = None + + ds = gdal.OpenEx( + tmp_vsimem / "test_ogr_gml_SWAP_COORDINATES_no_srs.xml", + open_options=["SWAP_COORDINATES=NO"], + ) + lyr = ds.GetLayer(0) + f = lyr.GetNextFeature() + assert f.GetGeometryRef().ExportToWkt() == "POINT (2 49)" + ds = None + + ############################################################################### # Test SRSNAME_FORMAT diff --git a/ogr/ogrsf_frmts/gmlutils/gmlutils.cpp b/ogr/ogrsf_frmts/gmlutils/gmlutils.cpp index 609104534cef..00825a1e8a85 100644 --- a/ogr/ogrsf_frmts/gmlutils/gmlutils.cpp +++ b/ogr/ogrsf_frmts/gmlutils/gmlutils.cpp @@ -317,6 +317,10 @@ OGRGeometry *GML_BuildOGRGeometryFromList( poGeom->swapXY(); } } + else if (eSwapCoordinates == GML_SWAP_YES) + { + poGeom->swapXY(); + } return poGeom; }