Skip to content
Permalink
Browse files

Ensure FILTER_GEOM is transformed to layer CRS in GetFeatureInfo

  • Loading branch information
manisandro committed Mar 5, 2018
1 parent 350218d commit 6108ed8470e09595918278f71057ee0a4889a5a4
@@ -1357,6 +1357,16 @@ namespace QgsWms
return false;
}

QgsFeatureRequest fReq;

// Transform filter geometry to layer CRS
std::unique_ptr<QgsGeometry> layerFilterGeom;
if ( filterGeom )
{
layerFilterGeom.reset( new QgsGeometry( *filterGeom ) );
layerFilterGeom->transform( QgsCoordinateTransform( mapSettings.destinationCrs(), layer->crs(), fReq.transformContext() ) );
}

//we need a selection rect (0.01 of map width)
QgsRectangle mapRect = mapSettings.extent();
QgsRectangle layerRect = mapSettings.mapToLayerCoordinates( layer, mapRect );
@@ -1369,9 +1379,9 @@ namespace QgsWms
{
searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
}
else if ( filterGeom )
else if ( layerFilterGeom )
{
searchRect = filterGeom->boundingBox();
searchRect = layerFilterGeom->boundingBox();
}
else if ( mParameters.contains( QStringLiteral( "BBOX" ) ) )
{
@@ -1389,8 +1399,7 @@ namespace QgsWms
bool segmentizeWktGeometry = QgsServerProjectUtils::wmsFeatureInfoSegmentizeWktGeometry( *mProject );
const QSet<QString> &excludedAttributes = layer->excludeAttributesWms();

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

if ( ! searchRect.isEmpty() )
@@ -1402,9 +1411,10 @@ namespace QgsWms
fReq.setFlags( fReq.flags() & ~ QgsFeatureRequest::ExactIntersect );
}

if ( filterGeom )

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

#ifdef HAVE_SERVER_PYTHON_PLUGINS
@@ -193,11 +193,20 @@ def test_getfeatureinfo(self):
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=text%2Fxml&' +
'width=600&height=400&srs=EPSG%3A3857&' +
'width=600&height=400&srs=EPSG%3A4326&' +
'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 feature info request with filter geometry in non-layer CRS
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 ((913213.6839952 5606021.5399693, 913215.6988780 5606021.5399693, 913215.6988780 5606015.09643322, 913213.6839952 5606015.0964332, 913213.6839952 5606021.5399693))',
'wms_getfeatureinfo_geometry_filter_3857')

# Test feature info request with invalid query_layer
self.wms_request_compare('GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&' +
@@ -7,7 +7,7 @@ Content-Type: text/xml; charset=utf-8
<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"/>
<BoundingBox CRS="EPSG:4326" minx="8.2035" maxx="8.2035" miny="44.9014" maxy="44.9014"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>
@@ -0,0 +1,13 @@
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"/>
</Feature>
</Layer>
</GetFeatureInfoResponse>

0 comments on commit 6108ed8

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