Skip to content

Commit 184480b

Browse files
committedMar 6, 2018
Ensure FILTER_GEOM is transformed to layer CRS in GetFeatureInfo
1 parent 7c3ab9f commit 184480b

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed
 

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,16 @@ namespace QgsWms
13581358
return false;
13591359
}
13601360

1361+
QgsFeatureRequest fReq;
1362+
1363+
// Transform filter geometry to layer CRS
1364+
std::unique_ptr<QgsGeometry> layerFilterGeom;
1365+
if ( filterGeom )
1366+
{
1367+
layerFilterGeom.reset( new QgsGeometry( *filterGeom ) );
1368+
layerFilterGeom->transform( QgsCoordinateTransform( mapSettings.destinationCrs(), layer->crs(), fReq.transformContext() ) );
1369+
}
1370+
13611371
//we need a selection rect (0.01 of map width)
13621372
QgsRectangle mapRect = mapSettings.extent();
13631373
QgsRectangle layerRect = mapSettings.mapToLayerCoordinates( layer, mapRect );
@@ -1370,9 +1380,9 @@ namespace QgsWms
13701380
{
13711381
searchRect = featureInfoSearchRect( layer, mapSettings, renderContext, *infoPoint );
13721382
}
1373-
else if ( filterGeom )
1383+
else if ( layerFilterGeom )
13741384
{
1375-
searchRect = filterGeom->boundingBox();
1385+
searchRect = layerFilterGeom->boundingBox();
13761386
}
13771387
else if ( mParameters.contains( QStringLiteral( "BBOX" ) ) )
13781388
{
@@ -1390,8 +1400,7 @@ namespace QgsWms
13901400
bool segmentizeWktGeometry = QgsServerProjectUtils::wmsFeatureInfoSegmentizeWktGeometry( *mProject );
13911401
const QSet<QString> &excludedAttributes = layer->excludeAttributesWms();
13921402

1393-
QgsFeatureRequest fReq;
1394-
bool hasGeometry = addWktGeometry || featureBBox || filterGeom;
1403+
bool hasGeometry = addWktGeometry || featureBBox || layerFilterGeom;
13951404
fReq.setFlags( ( ( hasGeometry ) ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) | QgsFeatureRequest::ExactIntersect );
13961405

13971406
if ( ! searchRect.isEmpty() )
@@ -1403,9 +1412,10 @@ namespace QgsWms
14031412
fReq.setFlags( fReq.flags() & ~ QgsFeatureRequest::ExactIntersect );
14041413
}
14051414

1406-
if ( filterGeom )
1415+
1416+
if ( layerFilterGeom )
14071417
{
1408-
fReq.setFilterExpression( QString( "intersects( $geometry, geom_from_wkt('%1') )" ).arg( filterGeom->asWkt() ) );
1418+
fReq.setFilterExpression( QString( "intersects( $geometry, geom_from_wkt('%1') )" ).arg( layerFilterGeom->asWkt() ) );
14091419
}
14101420

14111421
#ifdef HAVE_SERVER_PYTHON_PLUGINS

‎tests/src/python/test_qgsserver_wms.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,20 @@ def test_getfeatureinfo(self):
193193
self.wms_request_compare('GetFeatureInfo',
194194
'&layers=testlayer%20%C3%A8%C3%A9&' +
195195
'INFO_FORMAT=text%2Fxml&' +
196-
'width=600&height=400&srs=EPSG%3A3857&' +
196+
'width=600&height=400&srs=EPSG%3A4326&' +
197197
'query_layers=testlayer%20%C3%A8%C3%A9&' +
198198
'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))',
199199
'wms_getfeatureinfo_geometry_filter')
200200

201+
# Test feature info request with filter geometry in non-layer CRS
202+
self.wms_request_compare('GetFeatureInfo',
203+
'&layers=testlayer%20%C3%A8%C3%A9&' +
204+
'INFO_FORMAT=text%2Fxml&' +
205+
'width=600&height=400&srs=EPSG%3A3857&' +
206+
'query_layers=testlayer%20%C3%A8%C3%A9&' +
207+
'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))',
208+
'wms_getfeatureinfo_geometry_filter_3857')
209+
201210
# Test feature info request with invalid query_layer
202211
self.wms_request_compare('GetFeatureInfo',
203212
'&layers=testlayer%20%C3%A8%C3%A9&' +

‎tests/testdata/qgis_server/wms_getfeatureinfo_geometry_filter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Content-Type: text/xml; charset=utf-8
77
<Attribute name="id" value="2"/>
88
<Attribute name="name" value="two"/>
99
<Attribute name="utf8nameè" value="two àò"/>
10-
<BoundingBox CRS="EPSG:3857" minx="913214.6741" maxx="913214.6741" miny="5606017.8743" maxy="5606017.8743"/>
10+
<BoundingBox CRS="EPSG:4326" minx="8.2035" maxx="8.2035" miny="44.9014" maxy="44.9014"/>
1111
</Feature>
1212
</Layer>
1313
</GetFeatureInfoResponse>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Content-Length: 261
2+
Content-Type: text/xml; charset=utf-8
3+
4+
<GetFeatureInfoResponse>
5+
<Layer name="testlayer èé">
6+
<Feature id="1">
7+
<Attribute name="id" value="2"/>
8+
<Attribute name="name" value="two"/>
9+
<Attribute name="utf8nameè" value="two àò"/>
10+
<BoundingBox CRS="EPSG:3857" minx="913214.6741" maxx="913214.6741" miny="5606017.8743" maxy="5606017.8743"/>
11+
</Feature>
12+
</Layer>
13+
</GetFeatureInfoResponse>

0 commit comments

Comments
 (0)
Please sign in to comment.