Skip to content
Permalink
Browse files

GML streaming parser / WFS: correctly deal with gml:id attributes bef…

…ore passing geometry to OGR (fixes #39081)
  • Loading branch information
rouault authored and nyalldawson committed Oct 1, 2020
1 parent ebeb016 commit 80f00f84c0dbe39fa6c40df87f1444cee2a120d0
Showing with 25 additions and 4 deletions.
  1. +22 −1 src/core/qgsgml.cpp
  2. +3 −3 tests/src/core/testqgsgml.cpp
@@ -506,7 +506,27 @@ void QgsGmlStreamingParser::startElement( const XML_Char *el, const XML_Char **a
mGeometryString.append( " ", 1 );
for ( const XML_Char **attrIter = attr; attrIter && *attrIter; attrIter += 2 )
{
mGeometryString.append( attrIter[0] );
const size_t nAttrLen = strlen( attrIter[0] );
const size_t GML32_NAMESPACE_LEN = strlen( GML32_NAMESPACE );
const size_t GML_NAMESPACE_LEN = strlen( GML_NAMESPACE );
if ( nAttrLen > GML32_NAMESPACE_LEN &&
attrIter[0][GML32_NAMESPACE_LEN] == '?' &&
memcmp( attrIter[0], GML32_NAMESPACE, GML32_NAMESPACE_LEN ) == 0 )
{
mGeometryString.append( "gml:" );
mGeometryString.append( attrIter[0] + GML32_NAMESPACE_LEN + 1 );
}
else if ( nAttrLen > GML_NAMESPACE_LEN &&
attrIter[0][GML_NAMESPACE_LEN] == '?' &&
memcmp( attrIter[0], GML_NAMESPACE, GML_NAMESPACE_LEN ) == 0 )
{
mGeometryString.append( "gml:" );
mGeometryString.append( attrIter[0] + GML_NAMESPACE_LEN + 1 );
}
else
{
mGeometryString.append( attrIter[0] );
}
mGeometryString.append( "=\"", 2 );
mGeometryString.append( attrIter[1] );
mGeometryString.append( "\" ", 2 );
@@ -887,6 +907,7 @@ void QgsGmlStreamingParser::endElement( const XML_Char *el )
if ( mFoundUnhandledGeometryElement )
{
gdal::ogr_geometry_unique_ptr hGeom( OGR_G_CreateFromGML( mGeometryString.c_str() ) );
//QgsDebugMsg( QStringLiteral("for OGR: %1 -> %2").arg(mGeometryString.c_str()).arg(hGeom != nullptr));
if ( hGeom )
{
const int wkbSize = OGR_G_WkbSize( hGeom.get() );
@@ -1115,7 +1115,7 @@ void TestQgsGML::testThroughOGRGeometry()
"<myns:mytypename fid='mytypename.1'>"
"<myns:mygeom>"
"<gml:CompositeSurface srsName='EPSG:27700'><gml:surfaceMember>"
"<gml:Polygon srsName='EPSG:27700'>"
"<gml:Polygon gml:id='foo' srsName='EPSG:27700'>"
"<gml:exterior>"
"<gml:LinearRing>"
"<gml:posList>0 0 0 10 10 10 10 0 0 0</gml:posList>"
@@ -1146,12 +1146,12 @@ void TestQgsGML::testThroughOGRGeometry_urn_EPSG_4326()
QgsGmlStreamingParser gmlParser( QStringLiteral( "mytypename" ), QStringLiteral( "mygeom" ), fields );
QCOMPARE( gmlParser.processData( QByteArray( "<myns:FeatureCollection "
"xmlns:myns='http://myns' "
"xmlns:gml='http://www.opengis.net/gml'>"
"xmlns:gml='http://www.opengis.net/gml/3.2'>"
"<gml:featureMember>"
"<myns:mytypename fid='mytypename.1'>"
"<myns:mygeom>"
"<gml:CompositeSurface srsName='urn:ogc:def:crs:EPSG::4326'><gml:surfaceMember>"
"<gml:Polygon srsName='urn:ogc:def:crs:EPSG::4326'>"
"<gml:Polygon gml:id='foo' srsName='urn:ogc:def:crs:EPSG::4326'>"
"<gml:exterior>"
"<gml:LinearRing>"
"<gml:posList>49 2 49 3 59 3 49 2</gml:posList>"

0 comments on commit 80f00f8

Please sign in to comment.
You can’t perform that action at this time.