Skip to content
Permalink
Browse files

Fix srsDimension parsing in GML

  • Loading branch information
tcoupin authored and rldhont committed Jul 20, 2017
1 parent 23c2be8 commit 21e3e8357abdb3ffa3db487feb7f44b4d9f8a00d
Showing with 16 additions and 5 deletions.
  1. +13 −4 src/core/qgsgml.cpp
  2. +3 −1 src/core/qgsgml.h
@@ -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 )
@@ -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;
}
}
}
@@ -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
@@ -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 )
@@ -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" ) )
@@ -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;

0 comments on commit 21e3e83

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