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 committed Jul 20, 2017
1 parent bcc8e90 commit aa65af5
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
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,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 parseMode( 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 @@ -538,14 +539,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( QStringLiteral( "srsDimension" ), attr );
bool ok;
int dimension = srsDimension.toInt( &ok );
if ( ok )
{
mDimension = dimension;
elDimension = dimension;
}
}
}
Expand Down Expand Up @@ -803,7 +804,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 @@ -812,10 +813,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 @@ -842,6 +849,8 @@ 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.top() ;

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

if ( parseMode == Coordinate && isGMLNS && LOCALNAME_EQUALS( "coordinates" ) )
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsgml.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,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 aa65af5

Please sign in to comment.