Skip to content

Commit

Permalink
Fix srsDimension parsing in GML
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoupin authored and rldhont committed Jul 28, 2017
1 parent 23c2be8 commit 21e3e83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/core/qgsgml.cpp
Expand Up @@ -485,6 +485,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
const int nsLen = ( pszSep ) ? ( int )( pszSep - el ) : 0;
const int localNameLen = ( pszSep ) ? ( int )( elLen - nsLen ) - 1 : elLen;
ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.top() );
int elDimension = 0;

// Figure out if the GML namespace is GML_NAMESPACE or GML32_NAMESPACE
if ( !mGMLNameSpaceURIPtr && pszSep )
Expand Down Expand Up @@ -543,14 +544,14 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
mParseModeStack.push( QgsGmlStreamingParser::posList );
mCoorMode = QgsGmlStreamingParser::posList;
mStringCash.clear();
if ( mDimension == 0 )
if ( elDimension == 0 )
{
QString srsDimension = readAttribute( "srsDimension", attr );
bool ok;
int dimension = srsDimension.toInt( &ok );
if ( ok )
{
mDimension = dimension;
elDimension = dimension;
}
}
}
Expand Down Expand Up @@ -808,7 +809,7 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
if ( !mGeometryString.empty() )
isGeom = true;

if ( mDimension == 0 && isGeom )
if ( elDimension == 0 && isGeom )
{
// srsDimension can also be set on the top geometry element
// 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
Expand All @@ -817,10 +818,16 @@ void QgsGmlStreamingParser::startElement( const XML_Char* el, const XML_Char** a
int dimension = srsDimension.toInt( &ok );
if ( ok )
{
mDimension = dimension;
elDimension = dimension;
}
}

if ( elDimension != 0 )
{
mDimension = elDimension;
}
mDimensionStack.push( mDimension );

if ( mEpsg == 0 && isGeom )
{
if ( readEpsgFromAttribute( mEpsg, attr ) != 0 )
Expand All @@ -847,6 +854,8 @@ void QgsGmlStreamingParser::endElement( const XML_Char* el )
const int localNameLen = ( pszSep ) ? ( int )( elLen - nsLen ) - 1 : elLen;
ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.top() );

mDimension = mDimensionStack.isEmpty() ? 0 : mDimensionStack.top() ;

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

if ( theParseMode == coordinate && isGMLNS && LOCALNAME_EQUALS( "coordinates" ) )
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsgml.h
Expand Up @@ -289,7 +289,9 @@ class CORE_EXPORT QgsGmlStreamingParser
QString mCoordinateSeparator;
/** Tuple separator for coordinate strings. Usually " " */
QString mTupleSeparator;
/** Number of dimensions in pos or posList */
/** Keep track about number of dimensions in pos or posList */
QStack<int> mDimensionStack;
/** Number of dimensions in pos or posList for the current geometry */
int mDimension;
/** Coordinates mode, coordinate or posList */
ParseMode mCoorMode;
Expand Down

0 comments on commit 21e3e83

Please sign in to comment.