Skip to content

Commit

Permalink
Convert WMS GetFeatureInfo GML to UTF-8 supported by Expat, fixes #9082
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Dec 3, 2013
1 parent a4c365c commit 9d17f25
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/core/qgsgml.h
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsgmlschema.h
Expand Up @@ -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 );
Expand Down
18 changes: 15 additions & 3 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -61,6 +61,7 @@
#include <QSettings>
#include <QEventLoop>
#include <QCoreApplication>
#include <QTextCodec>
#include <QTime>

#ifdef QGISDEBUG
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9d17f25

Please sign in to comment.