Skip to content
Permalink
Browse files

[FEATURE]: Select features in feature info intersecting a geometry

  • Loading branch information
mhugent committed Jun 22, 2017
1 parent 5c6e794 commit e0efbda97fbb6ea50bad86832cde23d48388275a
Showing with 27 additions and 5 deletions.
  1. +25 −4 src/server/services/wms/qgswmsrenderer.cpp
  2. +2 −1 src/server/services/wms/qgswmsrenderer.h
@@ -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();
@@ -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" ) );
@@ -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;
}
@@ -1246,7 +1257,8 @@ namespace QgsWms
QgsRenderContext &renderContext,
const QString &version,
const QString &infoFormat,
QgsRectangle *featureBBox ) const
QgsRectangle *featureBBox,
QgsGeometry* filterGeom ) const
{
if ( !layer )
{
@@ -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;
@@ -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() )
@@ -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 );

@@ -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,

0 comments on commit e0efbda

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