Friday, 6 October 2017

Filtering features in other layers of QGIS Atlas?


I'm trying to use the QGIS Atlas tools to build student 'scattermaps', ie. 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:



Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...