Skip to content
Permalink
Browse files

Merge pull request #9204 from troopa81/wms_filters

Add possbility to define one filter for several layers
  • Loading branch information
pblottiere committed Feb 25, 2019
2 parents 2f305c5 + 9aa0023 commit 9f576b678eceefb4ebac5eda1ab90d89978cf960
@@ -1332,15 +1332,19 @@ namespace QgsWms
}
else if ( !f.isEmpty() )
{
// filter format: "LayerName:filterString;LayerName2:filterString2;..."
// filter format: "LayerName,LayerName2:filterString;LayerName3:filterString2;..."
// several filters can be defined for one layer
const QStringList splits = f.split( ':' );
if ( splits.size() == 2 )
{
QgsWmsParametersFilter filter;
filter.mFilter = splits[1];
filter.mType = QgsWmsParametersFilter::SQL;
filters.insert( splits[0], filter );
const QStringList layers = splits[0].split( ',' );
for ( const QString &layer : layers )
{
QgsWmsParametersFilter filter;
filter.mFilter = splits[1];
filter.mType = QgsWmsParametersFilter::SQL;
filters.insert( layer, filter );
}
}
else
{
@@ -798,6 +798,46 @@ def test_wms_getmap_filter(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_Filter4")

# display multiple features filtered from multiple layers with same filter for some
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "Country,Country_Diagrams,Hello",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "1017529,-4226661,11271098,17063190",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"FILTER": "Country,Country_Diagrams: \"name\" IN ( 'africa' , 'eurasia' );Hello: \"color\" IN ( 'magenta' , 'cerese' )"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_Filter5")

# Error in filter (missing quote after africa) with multiple layer filter
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "Country,Country_Diagrams,Hello",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "1017529,-4226661,11271098,17063190",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"FILTER": "Country,Country_Diagrams: \"name\" IN ( 'africa , 'eurasia' );Hello: \"color\" IN ( 'magenta' , 'cerese' )"
}.items())])

expected = self.strip_version_xmlns(b'<ServiceExceptionReport >\n <ServiceException code="Filter string rejected">The filter string "name" IN ( \'africa , \'eurasia\' ) has been rejected because of security reasons. Note: Text strings have to be enclosed in single or double quotes. A space between each word / special character is mandatory. Allowed Keywords and special characters are AND,OR,IN,&lt;,>=,>,>=,!=,\',\',(,),DMETAPHONE,SOUNDEX. Not allowed are semicolons in the filter expression.</ServiceException>\n</ServiceExceptionReport>\n')
r, h = self._result(self._execute_request(qs))

self.assertEqual(self.strip_version_xmlns(r), expected)

def test_wms_getmap_filter_ogc(self):
filter = "<Filter><PropertyIsEqualTo><PropertyName>name</PropertyName>" + \
"<Literal>eurasia</Literal></PropertyIsEqualTo></Filter>"
Binary file not shown.
Binary file not shown.

0 comments on commit 9f576b6

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