Skip to content

Commit

Permalink
Merge pull request #6544 from manisandro/wms_filter_geom_crs_30
Browse files Browse the repository at this point in the history
Ensure FILTER_GEOM is transformed to layer CRS in GetFeatureInfo
  • Loading branch information
manisandro authored Mar 6, 2018
2 parents 350218d + 6108ed8 commit ec5a8a4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
22 changes: 16 additions & 6 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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" ) ) )
{
Expand All @@ -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() )
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion tests/src/python/test_qgsserver_wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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&' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
@@ -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 ec5a8a4

Please sign in to comment.