Skip to content

Commit

Permalink
Server getfeatureinfo OGC filter support
Browse files Browse the repository at this point in the history
Fixes #41005
  • Loading branch information
elpaso authored and nyalldawson committed Jan 14, 2021
1 parent 0761f88 commit d1f5a52
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -1466,6 +1466,8 @@ namespace QgsWms
fReq.setFilterExpression( QString( "intersects( $geometry, geom_from_wkt('%1') )" ).arg( layerFilterGeom->asWkt() ) );
}

mFeatureFilter.filterFeatures( layer, fReq );

#ifdef HAVE_SERVER_PYTHON_PLUGINS
mContext.accessControl()->filterFeatures( layer, fReq );

Expand Down
81 changes: 81 additions & 0 deletions tests/src/python/test_qgsserver_wms_getfeatureinfo.py
Expand Up @@ -356,6 +356,87 @@ def testGetFeatureInfoFilter(self):
urllib.parse.quote(':"NAME" = \'two\''),
'wms_getfeatureinfo_filter_no_crs')

def testGetFeatureInfoOGCfilterJSON(self):
# OGC Filter test with info_format=application/json

# Test OGC filter with I/J and BBOX
self.wms_request_compare('GetFeatureInfo',
'&LAYERS=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=application%2Fjson&' +
'WIDTH=1266&HEIGHT=531&' +
'QUERY_LAYERS=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&' +
'CRS=EPSG:4326&' +
'BBOX=44.90139177500000045,8.20339159915254967,44.90148522499999473,8.20361440084745297&' +
'I=882&J=282&'
'FILTER=<Filter><PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>2</Literal></PropertyIsEqualTo></Filter>', 'wms_getfeatureinfo_filter_ogc')

# Test OGC filter with I/J and BBOX, filter id 3: empty result
self.wms_request_compare('GetFeatureInfo',
'&LAYERS=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=application%2Fjson&' +
'WIDTH=1266&HEIGHT=531&' +
'QUERY_LAYERS=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&' +
'CRS=EPSG:4326&' +
'BBOX=44.90139177500000045,8.20339159915254967,44.90148522499999473,8.20361440084745297&' +
'I=882&J=282&'
'FILTER=<Filter><PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>3</Literal></PropertyIsEqualTo></Filter>', 'wms_getfeatureinfo_filter_ogc_empty')

# Test OGC filter with no I/J and BBOX
self.wms_request_compare('GetFeatureInfo',
'&LAYERS=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=application%2Fjson&' +
'WIDTH=1266&HEIGHT=531&' +
'QUERY_LAYERS=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&' +
'CRS=EPSG:4326&' +
'FILTER=<Filter><PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>2</Literal></PropertyIsEqualTo></Filter>', 'wms_getfeatureinfo_filter_ogc')

# Test OGC filter with no I/J and wrong BBOX
self.wms_request_compare('GetFeatureInfo',
'&LAYERS=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=application%2Fjson&' +
'WIDTH=1266&HEIGHT=531&' +
'QUERY_LAYERS=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&' +
'CRS=EPSG:4326&' +
'BBOX=46,9,47,10&' +
'FILTER=<Filter><PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>2</Literal></PropertyIsEqualTo></Filter>', 'wms_getfeatureinfo_filter_ogc_empty')

# Test OGC filter with no I/J and BBOX plus complex OR filter
self.wms_request_compare('GetFeatureInfo',
'&LAYERS=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=application%2Fjson&' +
'WIDTH=1266&HEIGHT=531&' +
'QUERY_LAYERS=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&' +
'CRS=EPSG:4326&' +
'FILTER=<Filter><Or><PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>2</Literal></PropertyIsEqualTo>' +
'<PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>3</Literal></PropertyIsEqualTo></Or></Filter>', 'wms_getfeatureinfo_filter_ogc_complex')

# Test OGC filter with no I/J and BBOX plus complex AND filter
self.wms_request_compare('GetFeatureInfo',
'&LAYERS=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=application%2Fjson&' +
'WIDTH=1266&HEIGHT=531&' +
'QUERY_LAYERS=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&' +
'CRS=EPSG:4326&' +
'FILTER=<Filter><And><PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>2</Literal></PropertyIsEqualTo>' +
'<PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>3</Literal></PropertyIsEqualTo></And></Filter>', 'wms_getfeatureinfo_filter_ogc_empty')

# Test OGC filter with no I/J and BBOX plus complex AND filter
self.wms_request_compare('GetFeatureInfo',
'&LAYERS=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=application%2Fjson&' +
'WIDTH=1266&HEIGHT=531&' +
'QUERY_LAYERS=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&' +
'CRS=EPSG:4326&' +
'FILTER=<Filter><And><PropertyIsEqualTo><PropertyName>id</PropertyName><Literal>2</Literal></PropertyIsEqualTo>' +
'<PropertyIsEqualTo><PropertyName>name</PropertyName><Literal>two</Literal></PropertyIsEqualTo></And></Filter>', 'wms_getfeatureinfo_filter_ogc')

def testGetFeatureInfoTolerance(self):
self.wms_request_compare('GetFeatureInfo',
'&layers=layer3&styles=&' +
Expand Down
18 changes: 18 additions & 0 deletions tests/testdata/qgis_server/wms_getfeatureinfo_filter_ogc.txt
@@ -0,0 +1,18 @@
Content-Length: 250
Content-Type: application/json; charset=utf-8

{
"features": [
{
"geometry": null,
"id": "testlayer èé.1",
"properties": {
"id": 2,
"name": "two",
"utf8nameè": "two àò"
},
"type": "Feature"
}
],
"type": "FeatureCollection"
}
@@ -0,0 +1,28 @@
Content-Length: 454
Content-Type: application/json; charset=utf-8

{
"features": [
{
"geometry": null,
"id": "testlayer èé.1",
"properties": {
"id": 2,
"name": "two",
"utf8nameè": "two àò"
},
"type": "Feature"
},
{
"geometry": null,
"id": "testlayer èé.2",
"properties": {
"id": 3,
"name": "three",
"utf8nameè": "three èé↓"
},
"type": "Feature"
}
],
"type": "FeatureCollection"
}
@@ -0,0 +1,7 @@
Content-Length: 51
Content-Type: application/json; charset=utf-8

{
"features": [],
"type": "FeatureCollection"
}

0 comments on commit d1f5a52

Please sign in to comment.