Skip to content
Permalink
Browse files

Merge pull request #4772 from mhugent/feature_info_filter_geometry

WMS Server: Feature info with geometry filter
  • Loading branch information
mhugent committed Jun 26, 2017
2 parents 1730bc9 + e7ea972 commit a2d00d52f931e9ad1f27a4422d23c2514d6020c0
@@ -715,6 +715,13 @@ namespace QgsWms
j = -1;
}

//read FILTER_GEOM
std::unique_ptr<QgsGeometry> filterGeom;
if ( mParameters.contains( QStringLiteral( "FILTER_GEOM" ) ) )
{
filterGeom.reset( new QgsGeometry( QgsGeometry::fromWkt( mParameters.value( QStringLiteral( "FILTER_GEOM" ) ) ) ) );
}

//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 +743,7 @@ namespace QgsWms
{
featuresRect.reset( new QgsRectangle() );
}
else
else if ( !filterGeom.get() )
{
throw QgsBadRequestException( QStringLiteral( "ParameterMissing" ),
QStringLiteral( "I/J parameters are required for GetFeatureInfo" ) );
@@ -871,7 +878,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.get() ) )
{
continue;
}
@@ -1246,7 +1253,8 @@ namespace QgsWms
QgsRenderContext &renderContext,
const QString &version,
const QString &infoFormat,
QgsRectangle *featureBBox ) const
QgsRectangle *featureBBox,
QgsGeometry *filterGeom ) const
{
if ( !layer )
{
@@ -1265,6 +1273,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 +1294,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 +1306,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,
@@ -126,6 +126,15 @@ def test_project_wms(self):
'FEATURE_COUNT=10&FILTER=testlayer%20%C3%A8%C3%A9' + urllib.parse.quote(':"NAME" = \'two\' OR "utf8nameè" = \'three èé↓\''),
'wms_getfeatureinfo_filter_or_utf8')

# Test feature info request with filter geometry
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=text%2Fxml&' +
'width=600&height=400&srs=EPSG%3A3857&' +
'query_layers=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&FILTER_GEOM=POLYGON((8.2035381 44.901459,8.2035562 44.901459,8.2035562 44.901418,8.2035381 44.901418,8.2035381 44.901459))',
'wms_getfeatureinfo_geometry_filter')

# Test DescribeLayer
self.wms_request_compare('DescribeLayer',
'&layers=testlayer%20%C3%A8%C3%A9&' +
@@ -0,0 +1,14 @@
Content-Length: 261
Content-Type: text/xml; charset=utf-8

<GetFeatureInfoResponse>
<Layer name="testlayer èé">
<Feature id="1">
<Attribute name="id" value="2"/>
<Attribute name="name" value="two"/>
<Attribute name="utf8nameè" value="two àò"/>
<BoundingBox CRS="EPSG:3857" minx="913214.6741" maxx="913214.6741" miny="5606017.8743" maxy="5606017.8743"/>
<Attribute name="geometry" value="Point (913214.6741 5606017.8743)" type="derived"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>

0 comments on commit a2d00d5

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