32

I'm trying to use the QGIS Atlas tools to build student 'scattermaps', i.e. display the school and the students that attend that school, for 215 schools.

The schools layer is the coverage layer, and is being driven by the SCHNUM (school number) value. This is working fine, that is it is driving the pages correctly.

How, though, can I display only features from other layers, in this case the student point layer, that match the corresponding SCHNUM value for the current feature in the coverage layer?

I would also like to switch the coverage layer (schools) to 'hidden' and use the same technique to only display the current school from a duplicate schools layer.

There is a presentation available here that alludes to the use of a layer rendering rule setting using $atlasfeatureid, but I can't figure out how that works.

I also found this bug tracker page that shows this working, but again, I can't get it to work on my data:

1
  • Sorry to post this as an answer even though its a question. Is there any recommended video tutorial for this? I tried following along and somehow always managed to get lost at some point. Having the same problem.
    – JRamos
    Jun 11, 2019 at 13:54

2 Answers 2

56

Indeed, you need to use rule-based symbology to achieve what you want.

You need to create a rule for what you want to show, and ELSE rule for all others.

enter image description here

In the ELSE rule, deselect the symbol checkbox to make it invisible.

enter image description here

Hide other features from the coverage layer

The rule to show only the current atlas feature can be the following:

$id  =  @atlas_featureid 

enter image description here

note: I believe that @atlas_featureid variable is a 2.12 syntax. I think that in 2.8.x you would need to use a function called $atlas_featureid.

Hide features outside the current atlas feature

The recipe is the same as before, one else rule to hide features, one to show.

For your particular question, you seem to have a shared attribute called SCHNUM. In that case the rule can be:

"Layers_field" = attribute (@atlas_feature, 'coverage_layer_field_name')

in your particular case:

"SCHNUM"  =  attribute( @atlas_feature , 'SCHNUM')

Notice the difference between both SCHNUM. The first, in double quotes, represents each current layer feature's value of the field that stores the school code. The second, in single quotes, is a string with the name of the coverage layer that stores the school code.

Note: Again I think @atlas_feature variable is a "new" thing, and in 2.8.x you will need to use the function $atlas_feature

enter image description here

2
  • Alexandre very efficient his solution as opposed to computing the intersection. However, what I want to show is a classified layer (thematic map). How would it be to apply your solution in this case?
    – viniciovcl
    Jun 27, 2020 at 18:29
  • That's another question. The answer involves a few steps. Ask it and ping me, I will try to provide an answer. Jun 27, 2020 at 20:57
6

Starting from QGIS 3.16 Hannover, there is a button that allows you to view the current geometry of the atlas:

https://changelog.qgis.org/en/qgis/version/3.16/#add-automatic-clipping-settings-for-atlas-maps

enter image description here

Your Answer

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

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