Skip to content
Permalink
Browse files

Convert WMS GetFeatureInfo GML to UTF-8 supported by Expat, fixes #9082

  • Loading branch information
blazek committed Dec 3, 2013
1 parent a4c365c commit 9d17f25521d675d356ecde4a383d82ae28070df9
Showing with 20 additions and 4 deletions.
  1. +4 −1 src/core/qgsgml.h
  2. +1 −0 src/core/qgsgmlschema.h
  3. +15 −3 src/providers/wms/qgswmsprovider.cpp
@@ -50,14 +50,17 @@ class CORE_EXPORT QgsGml : public QObject
~QgsGml();

/** Does the Http GET request to the wfs server
* Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
* @param uri GML URL
* @param wkbType wkbType to retrieve
* @param extent retrieved extents
* @return 0 in case of success
*/
int getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );

/** Read from GML data. Constructor uri param is ignored */
/** Read from GML data. Constructor uri param is ignored
* Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
*/
int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );

/** Get parsed features for given type name */
@@ -85,6 +85,7 @@ class CORE_EXPORT QgsGmlSchema: public QObject

/** Guess GML schema from data if XSD does not exist.
* Currently only recognizes UMN Mapserver GetFeatureInfo GML response.
* Supports only UTF-8, UTF-16, ISO-8859-1, US-ASCII XML encodings.
* @param data GML data
* @return true in case of success */
bool guessSchema( const QByteArray &data );
@@ -61,6 +61,7 @@
#include <QSettings>
#include <QEventLoop>
#include <QCoreApplication>
#include <QTextCodec>
#include <QTime>

#ifdef QGISDEBUG
@@ -4376,7 +4377,18 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
}
}

QgsDebugMsg( "GML (first 2000 bytes):\n" + QString::fromUtf8( mIdentifyResultBodies.value( gmlPart ).left( 2000 ) ) );
QByteArray gmlByteArray = mIdentifyResultBodies.value( gmlPart );
QgsDebugMsg( "GML (first 2000 bytes):\n" + gmlByteArray.left( 2000 ) );

// QgsGmlSchema.guessSchema() and QgsGml::getFeatures() are using Expat
// which only accepts UTF-8, UTF-16, ISO-8859-1
// http://sourceforge.net/p/expat/bugs/498/
QDomDocument dom;
dom.setContent( gmlByteArray ); // gets XML encoding
QTextStream stream( &gmlByteArray );
stream.setCodec( QTextCodec::codecForName( "UTF-8" ) );
dom.save( stream, 4, QDomNode::EncodingFromTextStream );

QGis::WkbType wkbType;
QgsGmlSchema gmlSchema;

@@ -4418,7 +4430,7 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
else
{
// guess from GML
bool ok = gmlSchema.guessSchema( mIdentifyResultBodies.value( gmlPart ) );
bool ok = gmlSchema.guessSchema( gmlByteArray );
if ( ! ok )
{
QgsError err = gmlSchema.error();
@@ -4454,7 +4466,7 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
}
QgsGml gml( featureTypeName, geometryAttribute, fields );
// TODO: avoid converting to string and back
int ret = gml.getFeatures( mIdentifyResultBodies.value( gmlPart ), &wkbType );
int ret = gml.getFeatures( gmlByteArray, &wkbType );
#ifdef QGISDEBUG
QgsDebugMsg( QString( "parsing result = %1" ).arg( ret ) );
#else

0 comments on commit 9d17f25

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