10

How can I use nested styles?

I found Nathan W.'s post "Improvements to the QGIS rule based rendering" about nested styles, but I do not understand how to use?

  • Welcome to gis.stackexchange! Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq. – underdark Sep 2 '16 at 16:46
14

Hopefully the following image will help a little:

Nested style

Essentially, you can move a rule 'inside' another by dragging it across. This creates a nested style. In the image, I dragged the last 2 rules (blue and yellow) inside the green rule. Now if you add a filter (expression) to the green rule and if it applies to any feature, the features will not only turn green but may also turn blue and yellow depending on filters for these rules.

If the green rule does not apply to any feature, then they turn red as the red rule is outside the nested style. So a nested style can almost be seen as a standard IF, THEN, ELSE statement.

| improve this answer | |
  • @CarlosPires - Most welcome! Hope it was helpful =) – Joseph Apr 26 '16 at 14:02
  • @Rostranimin - Many thanks for the edit, much clearer now :) – Joseph Sep 2 '16 at 11:07
  • @Joseph - welcome - I came to the site to ask the same question and the answer got me most of the way. Nathan's post was helpful and I came across this in the process too... lists.osgeo.org/pipermail/qgis-developer/2012-January/… Trial and error got me the rest of the way. If you have time to add an image of the QGIS symbol on/off checkbox that would be helpful. – Rostranimin Sep 2 '16 at 12:05
  • 1
    @Rostranimin - Thank you but I would have been happier if you posted an answer (which you should consider) with your explanation with the image you proposed considering the amount of detail you added. If you do post an answer, I will rollback the changes on this post =) – Joseph Sep 2 '16 at 15:10
  • 1
    @Joseph - that's fair enough. I thought your answer was really good so didn't want to be adding something that felt like it was competing - but on the other hand I understand how you might feel, particularly once the big image is added. I'll do my best to get to this soon. – Rostranimin Sep 2 '16 at 22:04
5

Nested styles are possible for rule-based styling. (note - I haven't checked other types of styling)

It's not just the styling and symbology legend that are nested. The evaluation of the style rules is nested too.

To set up the nesting use drag and drop.

For example - see image. This is for a dataset with fields entitled 'height' and 'flow'. The initial setup, which I've created by hand (one style after another) might look like this. Note that I've made duplicate styles for flow greater than / less than 5.

Image of rule based styling before nesting created

We're going to combine the rules evaluating flow with the rules evaluating height. The rules evaluating flow are dragged on top of those evaluating height. So rules 3 and 4 in the list are dropped on top of rule 1 - and of course rules 5 and 6 are dropped on top of rule 2. We now have this (see image):

Image of rule based styling after nesting applied

It should be obvious that after dragging what we might call the 'child' categories onto the 'parent' categories then to see the child categories (the categories evaluating flow) you need to expand the style tree using the little +/- square box which can be seen to the left of the styles (image).

image showing expand control on rule based styling

Now - we don't (on this occasion) need to have any symbols for the parent rules. All cases will be covered by the child categories (flow will either be less than 5 or greater than / equal to 5) - so we don't need the black lines. To hide these double-click the individual style to enter the normal style design dialog. Then clear/uncheck the box next to the word 'symbol' (see image).

Image showing how to hide the parent style

We're left with a style set up as shown.

Image showing completed nested style

So in our example if 'height' > 2 AND 'flow' > 5 we get a plain red line - whereas if 'height' <= 2 AND 'flow' > 5 we get a dotted red line.

Image showing final styles

| improve this answer | |

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.