3

I am using a WFS of road centrelines available here for a small mapping project in QGIS. There are a number of features in my area of interest that I just want to exclude. I figured that an attribute filter might be the easiest way to achieve this.

In the query builder dialogue within the layer properties, I added the following filter:

"t50_fid" NOT IN (3324565)

Although the "Test" button tells me that the where clause manages to return n – 1 rows, when I close the dialogue the layer fails to load, with the following exception logged:

Layer NZ Road Centerlines (Topo, 1:50k): Download of features for layer data.linz.govt.nz:layer-329 failed or partially failed: Server generated an exception in GetFeature response: org.xml.sax.SAXException: Attempted to construct illegal filter - I dont understand the tag: fes:ValueReference. HINT: tags are case-sensitive! Attempted to construct illegal filter - I dont understand the tag: fes:ValueReference. HINT: tags are case-sensitive!. You may attempt reloading the layer with F5

So the NOT IN clause seems to construct an invalid CQL filter, with the layer source that is produced looking like so:

filter='"t50_fid" NOT IN (3324565)' retrictToRequestBBOX='1' srsname='EPSG:2193' typename='data.linz.govt.nz:layer-329' url='https://data.linz.govt.nz/services;key=*MYKEY*/wfs?' version='auto' table="" sql=

The following filter does work successfully, but the cost is that the syntax is harder to use if I want to exclude a longer list of features.

"t50_fid" != 3324565 (OK for one feature)

"t50_fid" != 3324565 AND "t50_fid" != 3324566 AND ... (gets cumbersome quickly, and hard to adjust).

This style of filter produces the following layer source:

filter='"t50_fid" != 3324565' retrictToRequestBBOX='1' srsname='EPSG:2193' typename='data.linz.govt.nz:layer-329' url='https://data.linz.govt.nz/services;key=*MYKEY*/wfs?' version='auto' table="" sql=

Incidentally, I figured that maybe my use of NOT IN is incorrect. "t50_fid" NOT IN (3324565,) causes no exception or warning, but fails to filter anything. "t50_fid" NOT IN [3324565] has an identical result.

5

You can successfully use the NOT IN syntax if you are filtering more than one feature.

"attribute" NOT IN (1, 2) ← works

"attribute" NOT IN (1) ← does not work

So I suppose this syntax is limited to filtering based on arrays of length greater than 1. However you can work around this if you still want to with:

"attribute" NOT IN (1, 1) ← works

In my case: "t50_fid" NOT IN (3324565, 3324565).

I find this behaviour a little strange and I think it smells like a bug, but that is a workaround.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.