I have a QGIS project with plenty of geometric layers coming from a PostGIS database.
Each and every layer has the same filter expression to limit the display to a same object: the filter simply being "id=<whatever_id_i_need_to_display>"
.
This allows me to limit the display to only the desired feature. Indeed, there are more than 200'000 features in the DB, displaying them all tends to slow down, if not crashing QGIS.
But it's somewhat tedious to manually change the filter on dozens of layers.
Is it possible to set such filter expression to many layers in one operation using the GUI?
I "naturally" tried to right click on the selection of all the layers I'd like to change the filter, but when the query builder window opens, it specifically targets the one layer I mouse-clicked on it, not taking into account all the selected layers.
There seems to be a Python solution: How to apply a filter to multiple vector layers in QGIS? but unfortunately there is a bug with SIP on my installation, so all Python related stuff is not available. Therefore, I am looking for a simple operation that I can perform with the graphical interface.
Info:
QGIS version | 3.24.2-Tisler |
---|---|
QGIS code revision | 13c1a02865 |
Qt version | 5.15.3 |
Python version | 3.10.4 |
GDAL/OGR version | 3.4.1 |
PROJ version | 8.2.1 |
EPSG Registry database version | v10.041 (2021-12-03) |
GEOS version | 3.10.2-CAPI-1.16.0 |
SQLite version | 3.37.2 |
PDAL version | 2.3.0 |
PostgreSQL client version | unknown |
SpatiaLite version | 5.0.1 |
QWT version | 6.1.4 |
QScintilla2 version | 2.11.6 |
OS version | Ubuntu 22.04 LTS |
EDIT:
Babel's answers are valid and his first one is really nice when working with few simple features.
But in my situation, I do have some layers with large data (up to hundreds of MB), therefore, when I remove the filter expression on those layers and rely only on the style definition, QGIS loads each and every features even so it has been told to display only one. And by loading them all, it consumes all the memory, up to the crash.
Therefore, I absolutely need to build a filter expression at the provider level, namely my PostgreSQL database, to only retrieve one single (or a small subset of) features for visualization purposes, and of course being able to switch from feature N to M in less than 2 seconds, for all my 100 layers.
The key idea is really to be able to switch the visualization to any other feature based on its id
, for all layers in one quick and single operation.
EDIT 2:
The advanced filter expression within the attribute table is not working. Indeed, it permits the filtering of feature, but only once everything has been loaded inside QGIS. Therefore, if I apply a filter based on @id_def
as suggested, it will still show 200'000
features when I show the feature count in the table of content, and when enabling a single layer having large data, it again eats all my memory up to the crash:
So, it's mandatory that this filter is being applied as the provider level, i.e. before querying the features. Well actually not really before but for the querying of the feature(s).