2

I have to deal with a QGIS project containing a huge number of layers. To bring order into the project and filter the information respectively layers I need, I am looking for a way to filter the layers by their name (using a substring of the name) either:

  1. in the Layers panel using the expression builder or
  2. in the DB Manager using SQL to create a virtual layer (with the UNION function?)

I tried several ways/expressions in both methods, but could not find a way to achieve my goal.

Any suggestions?

4
  • 1
    What do you mean by "filter the layers by their name"? Like you have 20 layers polygon_1 to polygon_20, 20 layers point_1 to point_20 and you only want to show layers containing polygon in their name?
    – Babel
    May 5, 2022 at 13:42
  • Exactly, this would be very helpful. In addition, it would be very helpful being able to filter by projection (e.g. EPSG).
    – communy
    May 5, 2022 at 14:26
  • Are you aware of the possibility that you can group layers? Making a layer group with all layers containing polygon allows you to toggle visibility for all these layers at once.
    – Babel
    May 5, 2022 at 14:50
  • Yes I am - I use groups often. The problem is that the layers I want to filter are located in many groups created by some else - I want to bring order to this.
    – communy
    May 5, 2022 at 16:18

1 Answer 1

3

Define a custom variable containing the expression you want to use for filtering layers. Then for each layer, use this variable as condition if the layer should be visible or not. When you change the variable's value, the visibility will change accordingly.

  1. Create acustom variable layerfilter: Menu Project > Properties > Variables and add a new variable with the green + icon.

  2. Define an expression for the variable to filter, e.g.:

    layer_property (@layer, 'crs') =  'EPSG:4326'
    

    to filter for layers with CRS = EPSG:4326 or

    regexp_match(layer_property (@layer, 'name'), 'buffer')
    

    to filter for layers that contain buffer in their name.

  3. In the layer styling panel, select the symbol layer and at the bottom, use data driven override for Enable Symbol Layer. Paste the expression eval (@layerfilter) so that the expression form the variable will be used to decide if the symbol layer should be visible or not.

enter image description here

1
  • Thank you very much, this is a good idea that I will try. However, it will likely not solve my issue, which is to merge specific layers into one layer - i.e. option 2 mentioned in my initial post. Perhaps I will have to be more specific about this aim and open a new topic
    – communy
    May 5, 2022 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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