@@ -715,6 +715,13 @@ namespace QgsWms
715715 j = -1 ;
716716 }
717717
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+
718725 // 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
719726 int widthParam = mParameters .value ( " WIDTH" , " -1" ).toInt ();
720727 int heightParam = mParameters .value ( " HEIGHT" , " -1" ).toInt ();
@@ -736,7 +743,7 @@ namespace QgsWms
736743 {
737744 featuresRect.reset ( new QgsRectangle () );
738745 }
739- else
746+ else if ( !filterGeom. get () )
740747 {
741748 throw QgsBadRequestException ( QStringLiteral ( " ParameterMissing" ),
742749 QStringLiteral ( " I/J parameters are required for GetFeatureInfo" ) );
@@ -871,7 +878,7 @@ namespace QgsWms
871878
872879 if ( vectorLayer )
873880 {
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 () ) )
875882 {
876883 continue ;
877884 }
@@ -1246,7 +1253,8 @@ namespace QgsWms
12461253 QgsRenderContext &renderContext,
12471254 const QString &version,
12481255 const QString &infoFormat,
1249- QgsRectangle *featureBBox ) const
1256+ QgsRectangle *featureBBox,
1257+ QgsGeometry *filterGeom ) const
12501258 {
12511259 if ( !layer )
12521260 {
@@ -1265,6 +1273,10 @@ namespace QgsWms
12651273 {
12661274 searchRect = featureInfoSearchRect ( layer, mapSettings, renderContext, *infoPoint );
12671275 }
1276+ else if ( filterGeom )
1277+ {
1278+ searchRect = filterGeom->boundingBox ();
1279+ }
12681280 else if ( mParameters .contains ( QStringLiteral ( " BBOX" ) ) )
12691281 {
12701282 searchRect = layerRect;
@@ -1282,7 +1294,7 @@ namespace QgsWms
12821294 const QSet<QString> &excludedAttributes = layer->excludeAttributesWms ();
12831295
12841296 QgsFeatureRequest fReq ;
1285- bool hasGeometry = addWktGeometry || featureBBox;
1297+ bool hasGeometry = addWktGeometry || featureBBox || filterGeom ;
12861298 fReq .setFlags ( ( ( hasGeometry ) ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) | QgsFeatureRequest::ExactIntersect );
12871299
12881300 if ( ! searchRect.isEmpty () )
@@ -1294,6 +1306,11 @@ namespace QgsWms
12941306 fReq .setFlags ( fReq .flags () & ~ QgsFeatureRequest::ExactIntersect );
12951307 }
12961308
1309+ if ( filterGeom )
1310+ {
1311+ fReq .setFilterExpression ( QString ( " intersects( $geometry, geom_from_wkt('%1') )" ).arg ( filterGeom->exportToWkt () ) );
1312+ }
1313+
12971314#ifdef HAVE_SERVER_PYTHON_PLUGINS
12981315 mAccessControl ->filterFeatures ( layer, fReq );
12991316
0 commit comments