Skip to content
Permalink
Browse files

QgsGmlStreamingParser: fix parsing of GML geometries with srsDimensio…

…n='3' set on posList element (fixes #21335)
  • Loading branch information
rouault committed Feb 21, 2019
1 parent 377040a commit 466dc359d74f4650c417001c80e95107da19efed
Showing with 41 additions and 4 deletions.
  1. +8 −4 src/core/qgsgml.cpp
  2. +33 −0 tests/src/core/testqgsgml.cpp
@@ -815,11 +815,14 @@ void QgsGmlStreamingParser::startElement( const XML_Char *el, const XML_Char **a
}
}

if ( elDimension != 0 )
if ( elDimension != 0 || mDimensionStack.isEmpty() )
{
mDimension = elDimension;
mDimensionStack.push( elDimension );
}
else
{
mDimensionStack.push( mDimensionStack.back() );
}
mDimensionStack.push( mDimension );

if ( mEpsg == 0 && isGeom )
{
@@ -847,7 +850,7 @@ void QgsGmlStreamingParser::endElement( const XML_Char *el )
const int localNameLen = ( pszSep ) ? ( int )( elLen - nsLen ) - 1 : elLen;
ParseMode parseMode( mParseModeStack.isEmpty() ? None : mParseModeStack.top() );

mDimension = mDimensionStack.isEmpty() ? 0 : mDimensionStack.pop();
int lastDimension = mDimensionStack.isEmpty() ? 0 : mDimensionStack.pop();

const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.size() && mGMLNameSpaceURIPtr && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );

@@ -858,6 +861,7 @@ void QgsGmlStreamingParser::endElement( const XML_Char *el )
else if ( parseMode == PosList && isGMLNS &&
( LOCALNAME_EQUALS( "pos" ) || LOCALNAME_EQUALS( "posList" ) ) )
{
mDimension = lastDimension;
mParseModeStack.pop();
}
else if ( parseMode == AttributeTuple &&
@@ -64,6 +64,7 @@ class TestQgsGML : public QObject
void testLineStringGML3_LineStringSegment();
void testPolygonGML3();
void testPolygonGML3_srsDimension_on_Polygon();
void testPolygonGML3_srsDimension_on_posList();
void testMultiLineStringGML3();
void testMultiPolygonGML3();
void testPointGML3_2();
@@ -660,6 +661,38 @@ void TestQgsGML::testPolygonGML3_srsDimension_on_Polygon()
delete features[0].first;
}

void TestQgsGML::testPolygonGML3_srsDimension_on_posList()
{
QgsFields fields;
QgsGmlStreamingParser gmlParser( QStringLiteral( "mytypename" ), QStringLiteral( "mygeom" ), fields );
QCOMPARE( gmlParser.processData( QByteArray( "<myns:FeatureCollection "
"xmlns:myns='http://myns' "
"xmlns:gml='http://www.opengis.net/gml'>"
"<gml:featureMember>"
"<myns:mytypename fid='mytypename.1'>"
"<myns:mygeom>"
"<gml:Polygon srsName='EPSG:27700'>"
"<gml:exterior>"
"<gml:LinearRing>"
"<gml:posList srsDimension='3'>0 0 -100 0 10 -100 10 10 -100 10 0 -100 0 0 -100</gml:posList>"
"</gml:LinearRing>"
"</gml:exterior>"
"</gml:Polygon>"
"</myns:mygeom>"
"</myns:mytypename>"
"</gml:featureMember>"
"</myns:FeatureCollection>" ), true ), true );
QCOMPARE( gmlParser.wkbType(), QgsWkbTypes::Polygon );
QVector<QgsGmlStreamingParser::QgsGmlFeaturePtrGmlIdPair> features = gmlParser.getAndStealReadyFeatures();
QCOMPARE( features.size(), 1 );
QVERIFY( features[0].first->hasGeometry() );
QCOMPARE( features[0].first->geometry().wkbType(), QgsWkbTypes::Polygon );
QgsPolygonXY poly = features[0].first->geometry().asPolygon();
QCOMPARE( poly.size(), 1 );
QCOMPARE( poly[0].size(), 5 );
delete features[0].first;
}

void TestQgsGML::testMultiLineStringGML3()
{
QgsFields fields;

0 comments on commit 466dc35

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