Skip to content
Permalink
Browse files

[server] Add support for OGC FE version 2 in GetMap request

  • Loading branch information
pblottiere committed Sep 13, 2018
1 parent f99b2db commit 186a5eb5071d0d4f31a22a29a63cac2633f85af8
@@ -1248,16 +1248,32 @@ namespace QgsWms
return style << styles;
}

QMultiMap<QString, QString> QgsWmsParameters::getLayerFilters( const QStringList &layers ) const
QMultiMap<QString, QgsWmsParametersFilter> QgsWmsParameters::layerFilters( const QStringList &layers ) const
{
const QString nsWfs2 = QStringLiteral( "http://www.opengis.net/fes/2.0" );
const QString prefixWfs2 = QStringLiteral( "<fes:" );

const QStringList rawFilters = filters();
QMultiMap<QString, QString> layerFilters;
QMultiMap<QString, QgsWmsParametersFilter> filters;
for ( int i = 0; i < rawFilters.size(); i++ )
{
const QString f = rawFilters[i];
if ( f.startsWith( QLatin1String( "<" ) ) && f.endsWith( QLatin1String( "Filter>" ) ) && i < layers.size() )
if ( f.startsWith( QLatin1String( "<" ) ) \
&& f.endsWith( QLatin1String( "Filter>" ) ) \
&& i < layers.size() )
{
layerFilters.insert( layers[i], f );
QgsWmsParametersFilter filter;
filter.mFilter = f;
filter.mType = QgsWmsParametersFilter::OGC_FE;
filter.mVersion = QgsOgcUtils::FILTER_OGC_1_0;

if ( filter.mFilter.contains( nsWfs2 ) \
|| filter.mFilter.contains( prefixWfs2 ) )
{
filter.mVersion = QgsOgcUtils::FILTER_FES_2_0;
}

filters.insert( layers[i], filter );
}
else if ( !f.isEmpty() )
{
@@ -1266,7 +1282,10 @@ namespace QgsWms
const QStringList splits = f.split( ':' );
if ( splits.size() == 2 )
{
layerFilters.insert( splits[0], splits[1] );
QgsWmsParametersFilter filter;
filter.mFilter = splits[1];
filter.mType = QgsWmsParametersFilter::SQL;
filters.insert( splits[0], filter );
}
else
{
@@ -1275,7 +1294,7 @@ namespace QgsWms
}
}
}
return layerFilters;
return filters;
}

QList<QgsWmsParametersLayer> QgsWmsParameters::layersParameters() const
@@ -1284,7 +1303,7 @@ namespace QgsWms
const QStringList styles = allStyles();
const QStringList selection = selections();
const QList<int> opacities = opacitiesAsInt();
const QMultiMap<QString, QString> layerFilters = getLayerFilters( layers );
const QMultiMap<QString, QgsWmsParametersFilter> filters = layerFilters( layers );

// selection format: "LayerName:id0,id1;LayerName2:id0,id1;..."
// several filters can be defined for one layer
@@ -1316,11 +1335,10 @@ namespace QgsWms
if ( i < opacities.count() )
param.mOpacity = opacities[i];

if ( layerFilters.contains( layer ) )
if ( filters.contains( layer ) )
{
QMultiMap<QString, QString>::const_iterator it;
it = layerFilters.find( layer );
while ( it != layerFilters.end() && it.key() == layer )
auto it = filters.find( layer );
while ( it != filters.end() && it.key() == layer )
{
param.mFilter.append( it.value() );
++it;
@@ -28,15 +28,31 @@
#include "qgsserverrequest.h"
#include "qgslegendsettings.h"
#include "qgsprojectversion.h"
#include "qgsogcutils.h"
#include "qgsserverparameters.h"

namespace QgsWms
{
struct QgsWmsParametersFilter
{
//! Filter type
enum Type
{
UNKNOWN,
SQL,
OGC_FE
};

QString mFilter;
QgsWmsParametersFilter::Type mType = QgsWmsParametersFilter::UNKNOWN;
QgsOgcUtils::FilterVersion mVersion = QgsOgcUtils::FILTER_OGC_1_0; // only if FE
};

struct QgsWmsParametersLayer
{
QString mNickname; // name, id or short name
int mOpacity = -1;
QStringList mFilter; // list of filter
QList<QgsWmsParametersFilter> mFilter; // list of filter
QStringList mSelection; // list of string fid
QString mStyle;
};
@@ -1125,7 +1141,7 @@ namespace QgsWms
void raiseError( const QString &msg ) const;
void log( const QString &msg ) const;

QMultiMap<QString, QString> getLayerFilters( const QStringList &layers ) const;
QMultiMap<QString, QgsWmsParametersFilter> layerFilters( const QStringList &layers ) const;

QMap<QgsWmsParameter::Name, QgsWmsParameter> mWmsParameters;
QMap<QString, QMap<QString, QString> > mExternalWMSParameters;
@@ -2795,35 +2795,35 @@ namespace QgsWms
}
}

void QgsRenderer::setLayerFilter( QgsMapLayer *layer, const QStringList &filters )
void QgsRenderer::setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters )
{
if ( layer->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer *filteredLayer = qobject_cast<QgsVectorLayer *>( layer );
for ( const QString &filter : filters )
for ( const QgsWmsParametersFilter &filter : filters )
{
if ( filter.startsWith( QLatin1String( "<" ) ) && filter.endsWith( QLatin1String( "Filter>" ) ) )
if ( filter.mType == QgsWmsParametersFilter::OGC_FE )
{
// OGC filter
QDomDocument filterXml;
QString errorMsg;
if ( !filterXml.setContent( filter, true, &errorMsg ) )
if ( !filterXml.setContent( filter.mFilter, true, &errorMsg ) )
{
throw QgsBadRequestException( QStringLiteral( "Filter string rejected" ),
QStringLiteral( "error message: %1. The XML string was: %2" ).arg( errorMsg, filter ) );
QStringLiteral( "error message: %1. The XML string was: %2" ).arg( errorMsg, filter.mFilter ) );
}
QDomElement filterElem = filterXml.firstChildElement();
std::unique_ptr<QgsExpression> expression( QgsOgcUtils::expressionFromOgcFilter( filterElem, filteredLayer ) );
std::unique_ptr<QgsExpression> expression( QgsOgcUtils::expressionFromOgcFilter( filterElem, filter.mVersion, filteredLayer ) );

if ( expression )
{
mFeatureFilter.setFilter( filteredLayer, *expression );
}
}
else
else if ( filter.mType == QgsWmsParametersFilter::SQL )
{
// QGIS (SQL) filter
if ( !testFilterStringSafety( filter ) )
if ( !testFilterStringSafety( filter.mFilter ) )
{
throw QgsBadRequestException( QStringLiteral( "Filter string rejected" ),
QStringLiteral( "The filter string %1"
@@ -2833,10 +2833,10 @@ namespace QgsWms
" Allowed Keywords and special characters are "
" AND,OR,IN,<,>=,>,>=,!=,',',(,),DMETAPHONE,SOUNDEX."
" Not allowed are semicolons in the filter expression." ).arg(
filter ) );
filter.mFilter ) );
}

QString newSubsetString = filter;
QString newSubsetString = filter.mFilter;
if ( !filteredLayer->subsetString().isEmpty() )
{
newSubsetString.prepend( ") AND (" );
@@ -162,7 +162,7 @@ namespace QgsWms
void setLayerOpacity( QgsMapLayer *layer, int opacity ) const;

// Set layer filter
void setLayerFilter( QgsMapLayer *layer, const QStringList &filter );
void setLayerFilter( QgsMapLayer *layer, const QList<QgsWmsParametersFilter> &filters );

// Set layer python filter
void setLayerAccessControlFilter( QgsMapLayer *layer ) const;

0 comments on commit 186a5eb

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