diff --git a/autotest/ogr/data/gmlas/coordinates_with_leading_space.gml b/autotest/ogr/data/gmlas/coordinates_with_leading_space.gml new file mode 100644 index 000000000000..4c96055a5f30 --- /dev/null +++ b/autotest/ogr/data/gmlas/coordinates_with_leading_space.gml @@ -0,0 +1,20 @@ + + + + + + + 1372074.8935456767,6205942.497461504,40.425811736193694 + 1372074.5535202357,6205942.435638697,40.425811736193694 + 1372074.5071531301,6205942.690657778,40.425811736193694 + 1372074.8471785712,6205942.752480585,40.425811736193694 + 1372074.8935456767,6205942.497461504,40.425811736193694 + + + + + diff --git a/autotest/ogr/data/gmlas/coordinates_with_leading_space.xsd b/autotest/ogr/data/gmlas/coordinates_with_leading_space.xsd new file mode 100644 index 000000000000..26291c7d1fcc --- /dev/null +++ b/autotest/ogr/data/gmlas/coordinates_with_leading_space.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/autotest/ogr/ogr_gmlas.py b/autotest/ogr/ogr_gmlas.py index 3f120d0b1fd9..721c53cf743a 100755 --- a/autotest/ogr/ogr_gmlas.py +++ b/autotest/ogr/ogr_gmlas.py @@ -2536,6 +2536,18 @@ def test_ogr_gmlas_geometry_as_substitutiongroup(): ds = None ############################################################################### +# Test importing a GML geometry whose coordinates elements has leading spaces + + +def test_ogr_gmlas_coordinates_with_leading_space(): + + ds = gdal.OpenEx('GMLAS:data/gmlas/coordinates_with_leading_space.gml') + lyr = ds.GetLayer(0) + f = lyr.GetNextFeature() + assert f.GetGeometryRef().ExportToIsoWkt() == "POLYGON Z ((1372074.89354568 6205942.4974615 40.4258117361937,1372074.55352024 6205942.4356387 40.4258117361937,1372074.50715313 6205942.69065778 40.4258117361937,1372074.84717857 6205942.75248059 40.4258117361937,1372074.89354568 6205942.4974615 40.4258117361937))" + ds = None + +############################################################################### @pytest.mark.require_run_on_demand diff --git a/ogr/gml2ogrgeometry.cpp b/ogr/gml2ogrgeometry.cpp index 89d2328d2ff8..5eaa0607c7a4 100644 --- a/ogr/gml2ogrgeometry.cpp +++ b/ogr/gml2ogrgeometry.cpp @@ -328,6 +328,13 @@ static bool ParseGMLCoordinates( const CPLXMLNode *psGeomNode, return true; } + // Skip leading whitespace. See https://github.com/OSGeo/gdal/issues/5494 + while( *pszCoordString != '\0' && + isspace(static_cast(*pszCoordString)) ) + { + pszCoordString++; + } + int iCoord = 0; const OGRwkbGeometryType eType = wkbFlatten(poGeometry->getGeometryType()); OGRSimpleCurve *poCurve =