2

I often find myself in the situation of needing to look at several spatial attributes for a particular item at once, each associated with a single ID field or record, and wanting to look at several such records in sequence. For example, I might have some data where I have a set of say, a hundred users, each with a home location, work location, a GPS trace, and so on. Let's say these are all in the same row in a PostGIS table, but since they are separate geometry fields, need to be loaded in QGIS as several distinct layers. If I want to look at all the data for user 1, what I've been doing is setting an identical "provider feature filter" for each layer so I can filter the data to just that user. That's fine for one user, but if I then want to look at user 2, user 3 and so on I have to (for each layer) open up the layer properties window, open the query builder, and increment the id. This can get very tedious if each user has many geometry features!

The way I've solved this before is to create a new field in my PostGIS table(s) to indicate an 'active' user, setting those records to true and all others to false and then targeting that field with the layer filters. But I still have to flip to a new window and run a query after editing some text for each new record.

I'm wondering if there might be a simpler/quicker solution to this, without having to leave the QGIS window? Is there some way to link layers so they share a filter?

1

The clean way would be to create a drop box with the list of users, and that filters all layers based on the selected user.

The quick way could be to create a project variable and to use this variable in each layer filter.

Go to project / project properties / variables, add a new variable using the + button, call it active_user_id (or whatever). Click on its value column to set the active id, for instance 1

Go to each of your layer, right click, properties / general / provider feature filter and set it to "id" = @active_user_id

To change the active user, go back to the project property and change the value of the active_user_id variable. All layers will immediately be filtered using this new value.

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.