Skip to content

Commit

Permalink
[FEATURE]: Select features in feature info intersecting a geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jun 22, 2017
1 parent 5c6e794 commit e0efbda
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
29 changes: 25 additions & 4 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -715,6 +715,17 @@ namespace QgsWms
j = -1;
}

//read FILTER_GEOM
QgsGeometry* filterGeom = 0;
if( mParameters.contains( QStringLiteral( "FILTER_GEOM" ) ) )
{
filterGeom = new QgsGeometry( QgsGeometry::fromWkt( mParameters.value( QStringLiteral( "FILTER_GEOM" ) ) ) );
if( filterGeom->isNull() )
{
delete filterGeom; filterGeom = nullptr;
}
}

//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
int widthParam = mParameters.value( "WIDTH", "-1" ).toInt();
int heightParam = mParameters.value( "HEIGHT", "-1" ).toInt();
Expand All @@ -736,7 +747,7 @@ namespace QgsWms
{
featuresRect.reset( new QgsRectangle() );
}
else
else if( !filterGeom )
{
throw QgsBadRequestException( QStringLiteral( "ParameterMissing" ),
QStringLiteral( "I/J parameters are required for GetFeatureInfo" ) );
Expand Down Expand Up @@ -871,7 +882,7 @@ namespace QgsWms

if ( vectorLayer )
{
if ( !featureInfoFromVectorLayer( vectorLayer, infoPoint.get(), featureCount, result, layerElement, mapSettings, renderContext, version, infoFormat, featuresRect.get() ) )
if ( !featureInfoFromVectorLayer( vectorLayer, infoPoint.get(), featureCount, result, layerElement, mapSettings, renderContext, version, infoFormat, featuresRect.get(), filterGeom ) )
{
continue;
}
Expand Down Expand Up @@ -1246,7 +1257,8 @@ namespace QgsWms
QgsRenderContext &renderContext,
const QString &version,
const QString &infoFormat,
QgsRectangle *featureBBox ) const
QgsRectangle *featureBBox,
QgsGeometry* filterGeom ) const
{
if ( !layer )
{
Expand All @@ -1265,6 +1277,10 @@ namespace QgsWms
{
searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
}
else if( filterGeom )
{
searchRect = filterGeom->boundingBox();
}
else if ( mParameters.contains( QStringLiteral( "BBOX" ) ) )
{
searchRect = layerRect;
Expand All @@ -1282,7 +1298,7 @@ namespace QgsWms
const QSet<QString> &excludedAttributes = layer->excludeAttributesWms();

QgsFeatureRequest fReq;
bool hasGeometry = addWktGeometry || featureBBox;
bool hasGeometry = addWktGeometry || featureBBox || filterGeom;
fReq.setFlags( ( ( hasGeometry ) ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) | QgsFeatureRequest::ExactIntersect );

if ( ! searchRect.isEmpty() )
Expand All @@ -1294,6 +1310,11 @@ namespace QgsWms
fReq.setFlags( fReq.flags() & ~ QgsFeatureRequest::ExactIntersect );
}

if( filterGeom )
{
fReq.setFilterExpression( QString("intersects( $geometry, geom_from_wkt('%1') )").arg( filterGeom->exportToWkt() ) );
}

#ifdef HAVE_SERVER_PYTHON_PLUGINS
mAccessControl->filterFeatures( layer, fReq );

Expand Down
3 changes: 2 additions & 1 deletion src/server/services/wms/qgswmsrenderer.h
Expand Up @@ -223,7 +223,8 @@ namespace QgsWms
QgsRenderContext &renderContext,
const QString &version,
const QString &infoFormat,
QgsRectangle *featureBBox = nullptr ) const;
QgsRectangle *featureBBox = nullptr,
QgsGeometry* filterGeom = nullptr ) const;
//! Appends feature info xml for the layer to the layer element of the dom document
bool featureInfoFromRasterLayer( QgsRasterLayer *layer,
const QgsMapSettings &mapSettings,
Expand Down

0 comments on commit e0efbda

Please sign in to comment.