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; }