Skip to content

Commit

Permalink
GML GetFeatureInfo XSD validation, disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Feb 7, 2013
1 parent 28e594b commit 0f7b405
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/gui/qgsmaptoolidentify.cpp
Expand Up @@ -439,6 +439,25 @@ bool QgsMapToolIdentify::identifyRasterLayer( QList<IdentifyResult> *results, Qg
{
foreach ( int i, values.keys() )
{
QVariant value = values.value( i );
if ( value.type() == QVariant::Bool && !value.toBool() )
{
// sublayer not visible or not queryable
continue;
}

if ( value.type() == QVariant::String )
{
// error
// TODO: better error reporting
QString label = layer->subLayers().value( i );
attributes.clear();
attributes.insert( tr( "Error" ), value.toString() );

results->append( IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
continue;
}

// list of feature stores for a single sublayer
QgsFeatureStoreList featureStoreList = values.value( i ).value<QgsFeatureStoreList>();

Expand Down
50 changes: 48 additions & 2 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -48,6 +48,11 @@
#include <QNetworkDiskCache>
#endif

#if QT_VERSION >= 0x40600
#include <QtXmlPatterns/QXmlSchema>
#include <QtXmlPatterns/QXmlSchemaValidator>
#endif

#include <QUrl>
#include <QIcon>
#include <QImage>
Expand Down Expand Up @@ -3919,21 +3924,31 @@ QMap<int, QVariant> QgsWmsProvider::identify( const QgsPoint & thePoint, Identif

//QgsFeatureList featureList;

int count = 0;
int count = -1;
// Test for which layers are suitable for querying with
for ( QStringList::const_iterator
layers = mActiveSubLayers.begin(),
styles = mActiveSubStyles.begin();
layers != mActiveSubLayers.end();
++layers, ++styles )
{
count++;

// Is sublayer visible?
if ( !mActiveSubLayerVisibility.find( *layers ).value() )
{
// TODO: something better?
// we need to keep all sublayers so that we can get their names in identify tool
results.insert( count, false );
continue;
}

// Is sublayer queryable?
if ( !mQueryableForLayer.find( *layers ).value() )
{
results.insert( count, false );
continue;
}

QgsDebugMsg( "Layer '" + *layers + "' is queryable." );

Expand Down Expand Up @@ -4047,6 +4062,38 @@ QMap<int, QVariant> QgsWmsProvider::identify( const QgsPoint & thePoint, Identif

if ( xsdPart >= 0 ) // XSD available
{
#if QT_VERSION >= 0x40600
#if 0
// Validate GML by schema
// Loading schema takes ages! It needs to load all XSD referenced in the schema,
// for example:
// http://schemas.opengis.net/gml/2.1.2/feature.xsd
// http://schemas.opengis.net/gml/2.1.2/gml.xsd
// http://schemas.opengis.net/gml/2.1.2/geometry.xsd
// http://www.w3.org/1999/xlink.xsd
// http://www.w3.org/2001/xml.xsd <- this takes 30s to download (2/2013)

QXmlSchema schema;
schema.load( mIdentifyResultBodies.value( xsdPart ) );
// Unfortunately the schema cannot be successfully loaded, it reports error
// "Element {http://www.opengis.net/gml}_Feature already defined"
// there is probably a bug in QXmlSchema:
// https://bugreports.qt-project.org/browse/QTBUG-8394
// xmlpatternsvalidator gives the same error on XSD generated by OGR
if ( !schema.isValid() )
{
// TODO: return QgsError
results.insert( count, tr( "GML schema is not valid" ) );
continue;
}
QXmlSchemaValidator validator( schema );
if ( !validator.validate( mIdentifyResultBodies.value( gmlPart ) ) )
{
results.insert( count, tr( "GML is not valid" ) );
continue;
}
#endif
#endif
gmlSchema.parseXSD( mIdentifyResultBodies.value( xsdPart ) );
}
else
Expand Down Expand Up @@ -4101,7 +4148,6 @@ QMap<int, QVariant> QgsWmsProvider::identify( const QgsPoint & thePoint, Identif
}
results.insert( count, qVariantFromValue( featureStoreList ) );
}
count++;
}

QString str;
Expand Down

0 comments on commit 0f7b405

Please sign in to comment.