@@ -715,6 +715,13 @@ namespace QgsWms
715
715
j = -1 ;
716
716
}
717
717
718
+ // read FILTER_GEOM
719
+ std::unique_ptr<QgsGeometry> filterGeom;
720
+ if ( mParameters .contains ( QStringLiteral ( " FILTER_GEOM" ) ) )
721
+ {
722
+ filterGeom.reset ( new QgsGeometry ( QgsGeometry::fromWkt ( mParameters .value ( QStringLiteral ( " FILTER_GEOM" ) ) ) ) );
723
+ }
724
+
718
725
// In case the output image is distorted (WIDTH/HEIGHT ratio not equal to BBOX width/height), I and J need to be adapted as well
719
726
int widthParam = mParameters .value ( " WIDTH" , " -1" ).toInt ();
720
727
int heightParam = mParameters .value ( " HEIGHT" , " -1" ).toInt ();
@@ -736,7 +743,7 @@ namespace QgsWms
736
743
{
737
744
featuresRect.reset ( new QgsRectangle () );
738
745
}
739
- else
746
+ else if ( !filterGeom. get () )
740
747
{
741
748
throw QgsBadRequestException ( QStringLiteral ( " ParameterMissing" ),
742
749
QStringLiteral ( " I/J parameters are required for GetFeatureInfo" ) );
@@ -871,7 +878,7 @@ namespace QgsWms
871
878
872
879
if ( vectorLayer )
873
880
{
874
- if ( !featureInfoFromVectorLayer ( vectorLayer, infoPoint.get (), featureCount, result, layerElement, mapSettings, renderContext, version, infoFormat, featuresRect.get () ) )
881
+ if ( !featureInfoFromVectorLayer ( vectorLayer, infoPoint.get (), featureCount, result, layerElement, mapSettings, renderContext, version, infoFormat, featuresRect.get (), filterGeom. get () ) )
875
882
{
876
883
continue ;
877
884
}
@@ -1246,7 +1253,8 @@ namespace QgsWms
1246
1253
QgsRenderContext &renderContext,
1247
1254
const QString &version,
1248
1255
const QString &infoFormat,
1249
- QgsRectangle *featureBBox ) const
1256
+ QgsRectangle *featureBBox,
1257
+ QgsGeometry *filterGeom ) const
1250
1258
{
1251
1259
if ( !layer )
1252
1260
{
@@ -1265,6 +1273,10 @@ namespace QgsWms
1265
1273
{
1266
1274
searchRect = featureInfoSearchRect ( layer, mapSettings, renderContext, *infoPoint );
1267
1275
}
1276
+ else if ( filterGeom )
1277
+ {
1278
+ searchRect = filterGeom->boundingBox ();
1279
+ }
1268
1280
else if ( mParameters .contains ( QStringLiteral ( " BBOX" ) ) )
1269
1281
{
1270
1282
searchRect = layerRect;
@@ -1282,7 +1294,7 @@ namespace QgsWms
1282
1294
const QSet<QString> &excludedAttributes = layer->excludeAttributesWms ();
1283
1295
1284
1296
QgsFeatureRequest fReq ;
1285
- bool hasGeometry = addWktGeometry || featureBBox;
1297
+ bool hasGeometry = addWktGeometry || featureBBox || filterGeom ;
1286
1298
fReq .setFlags ( ( ( hasGeometry ) ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) | QgsFeatureRequest::ExactIntersect );
1287
1299
1288
1300
if ( ! searchRect.isEmpty () )
@@ -1294,6 +1306,11 @@ namespace QgsWms
1294
1306
fReq .setFlags ( fReq .flags () & ~ QgsFeatureRequest::ExactIntersect );
1295
1307
}
1296
1308
1309
+ if ( filterGeom )
1310
+ {
1311
+ fReq .setFilterExpression ( QString ( " intersects( $geometry, geom_from_wkt('%1') )" ).arg ( filterGeom->exportToWkt () ) );
1312
+ }
1313
+
1297
1314
#ifdef HAVE_SERVER_PYTHON_PLUGINS
1298
1315
mAccessControl ->filterFeatures ( layer, fReq );
1299
1316
0 commit comments