Skip to content

Commit aa65af5

Browse files
committedJul 20, 2017
Fix srsDimension parsing in GML
1 parent bcc8e90 commit aa65af5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed
 

‎src/core/qgsgml.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char *el, const XML_Char **a
480480
const int nsLen = ( pszSep ) ? ( int )( pszSep - el ) : 0;
481481
const int localNameLen = ( pszSep ) ? ( int )( elLen - nsLen ) - 1 : elLen;
482482
ParseMode parseMode( mParseModeStack.isEmpty() ? None : mParseModeStack.top() );
483+
int elDimension = 0;
483484

484485
// Figure out if the GML namespace is GML_NAMESPACE or GML32_NAMESPACE
485486
if ( !mGMLNameSpaceURIPtr && pszSep )
@@ -538,14 +539,14 @@ void QgsGmlStreamingParser::startElement( const XML_Char *el, const XML_Char **a
538539
mParseModeStack.push( QgsGmlStreamingParser::PosList );
539540
mCoorMode = QgsGmlStreamingParser::PosList;
540541
mStringCash.clear();
541-
if ( mDimension == 0 )
542+
if ( elDimension == 0 )
542543
{
543544
QString srsDimension = readAttribute( QStringLiteral( "srsDimension" ), attr );
544545
bool ok;
545546
int dimension = srsDimension.toInt( &ok );
546547
if ( ok )
547548
{
548-
mDimension = dimension;
549+
elDimension = dimension;
549550
}
550551
}
551552
}
@@ -803,7 +804,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char *el, const XML_Char **a
803804
if ( !mGeometryString.empty() )
804805
isGeom = true;
805806

806-
if ( mDimension == 0 && isGeom )
807+
if ( elDimension == 0 && isGeom )
807808
{
808809
// srsDimension can also be set on the top geometry element
809810
// e.g. https://data.linz.govt.nz/services;key=XXXXXXXX/wfs?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=data.linz.govt.nz:layer-524
@@ -812,10 +813,16 @@ void QgsGmlStreamingParser::startElement( const XML_Char *el, const XML_Char **a
812813
int dimension = srsDimension.toInt( &ok );
813814
if ( ok )
814815
{
815-
mDimension = dimension;
816+
elDimension = dimension;
816817
}
817818
}
818819

820+
if ( elDimension != 0 )
821+
{
822+
mDimension = elDimension;
823+
}
824+
mDimensionStack.push( mDimension );
825+
819826
if ( mEpsg == 0 && isGeom )
820827
{
821828
if ( readEpsgFromAttribute( mEpsg, attr ) != 0 )
@@ -842,6 +849,8 @@ void QgsGmlStreamingParser::endElement( const XML_Char *el )
842849
const int localNameLen = ( pszSep ) ? ( int )( elLen - nsLen ) - 1 : elLen;
843850
ParseMode parseMode( mParseModeStack.isEmpty() ? None : mParseModeStack.top() );
844851

852+
mDimension = mDimensionStack.isEmpty() ? 0 : mDimensionStack.top() ;
853+
845854
const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.size() && mGMLNameSpaceURIPtr && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );
846855

847856
if ( parseMode == Coordinate && isGMLNS && LOCALNAME_EQUALS( "coordinates" ) )

‎src/core/qgsgml.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ class CORE_EXPORT QgsGmlStreamingParser
298298
QString mCoordinateSeparator;
299299
//! Tuple separator for coordinate strings. Usually " "
300300
QString mTupleSeparator;
301-
//! Number of dimensions in pos or posList
301+
//! Keep track about number of dimensions in pos or posList
302+
QStack<int> mDimensionStack;
303+
//! Number of dimensions in pos or posList for the current geometry
302304
int mDimension;
303305
//! Coordinates mode, coordinate or posList
304306
ParseMode mCoorMode;

0 commit comments

Comments
 (0)
Please sign in to comment.