Skip to content

Commit

Permalink
Merge pull request OSGeo#11492 from rouault/fix_11491
Browse files Browse the repository at this point in the history
GML: honour SWAP_COORDINATES=YES even when the geometry has no SRS
  • Loading branch information
rouault authored Dec 18, 2024
2 parents c9955a9 + a7994b8 commit 42ca02c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
49 changes: 49 additions & 0 deletions autotest/ogr/ogr_gml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"""<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<ogr:featureMember>
<ogr:point gml:id="point.0">
<ogr:geometryProperty><gml:Point><gml:pos>2 49</gml:pos></gml:Point></ogr:geometryProperty>
<ogr:id>1</ogr:id>
</ogr:point>
</ogr:featureMember>
</ogr:FeatureCollection>
""",
)

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

Expand Down
4 changes: 4 additions & 0 deletions ogr/ogrsf_frmts/gmlutils/gmlutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ OGRGeometry *GML_BuildOGRGeometryFromList(
poGeom->swapXY();
}
}
else if (eSwapCoordinates == GML_SWAP_YES)
{
poGeom->swapXY();
}

return poGeom;
}
Expand Down

0 comments on commit 42ca02c

Please sign in to comment.