@@ -715,6 +715,17 @@ namespace QgsWms
715715 j = -1 ;
716716 }
717717
718+ // read FILTER_GEOM
719+ QgsGeometry* filterGeom = 0 ;
720+ if ( mParameters .contains ( QStringLiteral ( " FILTER_GEOM" ) ) )
721+ {
722+ filterGeom = new QgsGeometry ( QgsGeometry::fromWkt ( mParameters .value ( QStringLiteral ( " FILTER_GEOM" ) ) ) );
723+ if ( filterGeom->isNull () )
724+ {
725+ delete filterGeom; filterGeom = nullptr ;
726+ }
727+ }
728+
718729 // 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
719730 int widthParam = mParameters .value ( " WIDTH" , " -1" ).toInt ();
720731 int heightParam = mParameters .value ( " HEIGHT" , " -1" ).toInt ();
@@ -736,7 +747,7 @@ namespace QgsWms
736747 {
737748 featuresRect.reset ( new QgsRectangle () );
738749 }
739- else
750+ else if ( !filterGeom )
740751 {
741752 throw QgsBadRequestException ( QStringLiteral ( " ParameterMissing" ),
742753 QStringLiteral ( " I/J parameters are required for GetFeatureInfo" ) );
@@ -871,7 +882,7 @@ namespace QgsWms
871882
872883 if ( vectorLayer )
873884 {
874- if ( !featureInfoFromVectorLayer ( vectorLayer, infoPoint.get (), featureCount, result, layerElement, mapSettings, renderContext, version, infoFormat, featuresRect.get () ) )
885+ if ( !featureInfoFromVectorLayer ( vectorLayer, infoPoint.get (), featureCount, result, layerElement, mapSettings, renderContext, version, infoFormat, featuresRect.get (), filterGeom ) )
875886 {
876887 continue ;
877888 }
@@ -1246,7 +1257,8 @@ namespace QgsWms
12461257 QgsRenderContext &renderContext,
12471258 const QString &version,
12481259 const QString &infoFormat,
1249- QgsRectangle *featureBBox ) const
1260+ QgsRectangle *featureBBox,
1261+ QgsGeometry* filterGeom ) const
12501262 {
12511263 if ( !layer )
12521264 {
@@ -1265,6 +1277,10 @@ namespace QgsWms
12651277 {
12661278 searchRect = featureInfoSearchRect ( layer, mapSettings, renderContext, *infoPoint );
12671279 }
1280+ else if ( filterGeom )
1281+ {
1282+ searchRect = filterGeom->boundingBox ();
1283+ }
12681284 else if ( mParameters .contains ( QStringLiteral ( " BBOX" ) ) )
12691285 {
12701286 searchRect = layerRect;
@@ -1282,7 +1298,7 @@ namespace QgsWms
12821298 const QSet<QString> &excludedAttributes = layer->excludeAttributesWms ();
12831299
12841300 QgsFeatureRequest fReq ;
1285- bool hasGeometry = addWktGeometry || featureBBox;
1301+ bool hasGeometry = addWktGeometry || featureBBox || filterGeom ;
12861302 fReq .setFlags ( ( ( hasGeometry ) ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) | QgsFeatureRequest::ExactIntersect );
12871303
12881304 if ( ! searchRect.isEmpty () )
@@ -1294,6 +1310,11 @@ namespace QgsWms
12941310 fReq .setFlags ( fReq .flags () & ~ QgsFeatureRequest::ExactIntersect );
12951311 }
12961312
1313+ if ( filterGeom )
1314+ {
1315+ fReq .setFilterExpression ( QString (" intersects( $geometry, geom_from_wkt('%1') )" ).arg ( filterGeom->exportToWkt () ) );
1316+ }
1317+
12971318#ifdef HAVE_SERVER_PYTHON_PLUGINS
12981319 mAccessControl ->filterFeatures ( layer, fReq );
12991320
0 commit comments