Skip to content

Commit 21e3e83

Browse files
tcoupinrldhont
authored andcommittedJul 28, 2017
Fix srsDimension parsing in GML
1 parent 23c2be8 commit 21e3e83

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
@@ -485,6 +485,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
485485
const int nsLen = ( pszSep ) ? ( int )( pszSep - el ) : 0;
486486
const int localNameLen = ( pszSep ) ? ( int )( elLen - nsLen ) - 1 : elLen;
487487
ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.top() );
488+
int elDimension = 0;
488489

489490
// Figure out if the GML namespace is GML_NAMESPACE or GML32_NAMESPACE
490491
if ( !mGMLNameSpaceURIPtr && pszSep )
@@ -543,14 +544,14 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
543544
mParseModeStack.push( QgsGmlStreamingParser::posList );
544545
mCoorMode = QgsGmlStreamingParser::posList;
545546
mStringCash.clear();
546-
if ( mDimension == 0 )
547+
if ( elDimension == 0 )
547548
{
548549
QString srsDimension = readAttribute( "srsDimension", attr );
549550
bool ok;
550551
int dimension = srsDimension.toInt( &ok );
551552
if ( ok )
552553
{
553-
mDimension = dimension;
554+
elDimension = dimension;
554555
}
555556
}
556557
}
@@ -808,7 +809,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
808809
if ( !mGeometryString.empty() )
809810
isGeom = true;
810811

811-
if ( mDimension == 0 && isGeom )
812+
if ( elDimension == 0 && isGeom )
812813
{
813814
// srsDimension can also be set on the top geometry element
814815
// 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
@@ -817,10 +818,16 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
817818
int dimension = srsDimension.toInt( &ok );
818819
if ( ok )
819820
{
820-
mDimension = dimension;
821+
elDimension = dimension;
821822
}
822823
}
823824

825+
if ( elDimension != 0 )
826+
{
827+
mDimension = elDimension;
828+
}
829+
mDimensionStack.push( mDimension );
830+
824831
if ( mEpsg == 0 && isGeom )
825832
{
826833
if ( readEpsgFromAttribute( mEpsg, attr ) != 0 )
@@ -847,6 +854,8 @@ void QgsGmlStreamingParser::endElement( const XML_Char* el )
847854
const int localNameLen = ( pszSep ) ? ( int )( elLen - nsLen ) - 1 : elLen;
848855
ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.top() );
849856

857+
mDimension = mDimensionStack.isEmpty() ? 0 : mDimensionStack.top() ;
858+
850859
const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.size() && mGMLNameSpaceURIPtr && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );
851860

852861
if ( theParseMode == coordinate && isGMLNS && LOCALNAME_EQUALS( "coordinates" ) )

‎src/core/qgsgml.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ class CORE_EXPORT QgsGmlStreamingParser
289289
QString mCoordinateSeparator;
290290
/** Tuple separator for coordinate strings. Usually " " */
291291
QString mTupleSeparator;
292-
/** Number of dimensions in pos or posList */
292+
/** Keep track about number of dimensions in pos or posList */
293+
QStack<int> mDimensionStack;
294+
/** Number of dimensions in pos or posList for the current geometry */
293295
int mDimension;
294296
/** Coordinates mode, coordinate or posList */
295297
ParseMode mCoorMode;

0 commit comments

Comments
 (0)
Please sign in to comment.