1

I need to quickly applie (and then change/remove) the same filter for about 100 layers in my QGis project (all put together in one group). Since there is no implemented solution right now (a feature request already exists for this issue), I searched the internet and found a good working workaround using the python-console and the function setSubsetSring. The syntax (in my case) is as follows:

layers = iface.mapCanvas().layers()
for layer in layers:
layer.setSubsetString('"Art" = \'Ki\'')

I can now applie the filter to any visible layers at once, and also change it by repeating the code and changing the value '\Ki\' to something else like '\Fl\' or anything else. Waht I now want to do is to remove the applied filter, so all features will be visible again. Since I'm absolutely new to Python, I just cant't figure out the right syntax for this job. Already tried things like

layer.setSubsetString('"Art" != \'xyz\'')

and something else, but I always get something like

File "<input>", line 2 layer.setSubsetString('"Art" != \'xyz\") IndentationError: expected an indented block

3
layers = iface.mapCanvas().layers()
for layer in layers:
   layer.setSubsetString('"Art" = \'Ki\'')

to clear:

layers = iface.mapCanvas().layers()
for layer in layers:
   layer.setSubsetString('')
  • Hi Nathan, thanks for your reply! After some restarts of Qgis, it now works like a charme! Thanks so much :) – Björn Geßler Jun 12 '15 at 14:43

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.