Skip to content
Permalink
Browse files

Merge pull request #6533 from manisandro/wms_filter_geom_crs

Ensure FILTER_GEOM is transformed to layer CRS in GetFeatureInfo
  • Loading branch information
manisandro committed Mar 6, 2018
2 parents ec975ba + 184480b commit 5bf28d56b6ceecd0d0b9765324c671af44e22b4d
@@ -1358,6 +1358,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 );
@@ -1370,9 +1380,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" ) ) )
{
@@ -1390,8 +1400,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() )
@@ -1403,9 +1412,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 5bf28d5

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