Tuesday, 30 August 2016

QGIS 3 - Variables in rule-based rendering?


I'll try and lay this out clearly, I have most of it covered, but there's a very specific thing I'm looking for in the rules - whether or not it can be done and if so, how?



Key things I have done and/or plan as outcomes;



  • QGIS 3.4.2

  • A dataset of just over 556000 rows - all points representing one building each

  • 583 groupings for each by round which are unique, the name covers region, service, round number and day like so '(SH) Food 1 Mon'

  • These rounds have anywhere between a few hundred and several thousand points in each

  • The groupings have been first set as categorised and then Rule-Based so each round is split out from the others

  • They're to be exported via an atlas and show one round at a time (once I've bounding geometry to use for each round) and all will have the same symbols - with only one round showing each time, there's no demand to have different symbols


I'm looking to use an atlas due to the volume of images this will produce, doing it by hand would take an age.



Previously when doing similar work on far less categories I've used this code and adapted it for each category (this is using the round example from above)


if("Round Name" = @atlas_pagename, "Round Name" = '(SH) Food 1 Mon', Null)

That works perfectly once all categories have the right round name in before the Null and also the ELSE category has been deleted.


Now here's where I've become stuck - with 583, it takes an awfully long time to change each category by hand once I've moved from Categorised to Rule-Based.


So, the key question here is this; there a way of putting a variable in where I've been typing the round name in order to have QGIS do that part for me by reading and using each round name for each category?


I've looked around on here and not found anything apart from using some Python script which I'm not very handy with so thought I'd ask this first before trying to get my head around that.


I think that covers it and hopefully it's all clear!



Answer



Since your goal is to display, on each atlas page, a different value for a single field in your data, it shouldn't require multiple rules.



You can read the value for each feature at render time using the Expression Builder. While the function attribute( $currentfeature, "your_field") can help return field values dynamically for each feature, in your case, this isn't necessarily needed. If there are corresponding fields in your coverage layer (where the corresponding field controls atlas page name) and data layer (where the corresponding field contains the round number), it can be as simple as this symbology rule for your data layer:


"Data_layer_field" = @atlas_pagename

This will show only features for which the fields match.


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...