Skip to content

Commit

Permalink
Merge pull request #5526 from rouault/fix_5494
Browse files Browse the repository at this point in the history
GML geometry importer / GMLAS: be robust to leading spaces in <gml:coordinates> element (fixes #5494)
  • Loading branch information
rouault committed Mar 28, 2022
2 parents 91392e9 + 9819da9 commit e48ab87
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
20 changes: 20 additions & 0 deletions autotest/ogr/data/gmlas/coordinates_with_leading_space.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ coordinates_with_leading_space.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://fake_gml32">
<ogr:featureMember>
<ogr:AffleurantEnveloppePCRS gml:id="AffleurantEnveloppePCRS.0">
<ogr:geometrie><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing>
<gml:coordinates>
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
</gml:coordinates>
</gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometrie>
</ogr:AffleurantEnveloppePCRS>
</ogr:featureMember>
</ogr:FeatureCollection>
36 changes: 36 additions & 0 deletions autotest/ogr/data/gmlas/coordinates_with_leading_space.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://fake_gml32" elementFormDefault="qualified" version="1.0">

<xs:import namespace="http://fake_gml32" schemaLocation="gmlas_fake_gml32.xsd"/>

<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:AbstractFeature"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="featureMember">
<xs:complexType>
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureMemberType">
<xs:sequence>
<xs:element ref="gml:AbstractFeature"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="AffleurantEnveloppePCRS" type="ogr:AffleurantEnveloppePCRS_Type" substitutionGroup="gml:AbstractFeature"/>
<xs:complexType name="AffleurantEnveloppePCRS_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometrie" type="gml:SurfacePropertyType" nillable="true" minOccurs="0" maxOccurs="1"/> <!-- restricted to Polygon -->
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
12 changes: 12 additions & 0 deletions autotest/ogr/ogr_gmlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions ogr/gml2ogrgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char>(*pszCoordString)) )
{
pszCoordString++;
}

int iCoord = 0;
const OGRwkbGeometryType eType = wkbFlatten(poGeometry->getGeometryType());
OGRSimpleCurve *poCurve =
Expand Down

0 comments on commit e48ab87

Please sign in to comment.