I'm using QGIS 3.4 , and without going into python scripting, is there a way I can create some kind of rule based styles where I can add a parameter?

I have a number of layers, each with between 1 and 10 rule based styles. For instance, here is one with 3 rules:

Plan1818 = 'Y' AND ("Type" = 'Deposit') and Status = 'Used'
Plan1818 = 'Y' AND ("Type" = 'Cut') and Status = 'Used'
Plan1818 = 'Y' AND ("Type" = 'Structure') and Status = 'Used'

I have 20+ 'Plans', and growing, and I am loading the saved style from one, loading it the next, and then changing the plan number for each rule.

I feel as there should be way to add the plan number as a parameter, but I've not found one yet. I tried a separate, rule Plan1818 = 'Y' and removing it from each of the others, but that didn't seem to work, even adjusting the symbol level.

Typical plan


  • Provided Plans1818 in the example is a field name, maybe you could rename the layer the same and, in your expression, instead of the field name, you could insert attribute( $currentfeature, @layer_name).
    – Gabriel
    Dec 4, 2018 at 21:48
  • I see where you are coming from @GabrielC, but unfortunately each plan has at east 5 different layers, a mixture of lines, polygons and points. These are grouped by the plan number in each case and as far as I can see, the group name is not an attribute that can be retrieved. Dec 5, 2018 at 0:02
  • Do the layers absolutely need to have a specific name? They could all have the plan name as a prefix and with a string function like left(string,length), you could extract the correct field name to query like this. There is a field named Plan1818 in my test layer and only the one with the correct value was symbolized.
    – Gabriel
    Dec 6, 2018 at 14:53
  • Nice idea @GabrielC, but unfortunately they do need specific names. The same layers are used in just about all the plans and the elements within these layers, which are surface types, context and other lines, artefacts, site levels etc, and they may appear in one or more of the plans (20 and rising) as we excavate further. Dec 8, 2018 at 0:29
  • Just to make sure, I'm not talking about the actual file name, just the label it takes in the layer list. As far as I understand it without seeing a screenshot of your layers list, they would just be copied layers from the same data files, am I correct? If not I absolutely don't understand your project structure. Updating the question with those screenshots might shed more light on the problem.
    – Gabriel
    Dec 8, 2018 at 2:54

1 Answer 1


The easiest way to do this would be to add a prefix like Plan0000_ to your layer names in the layers list and then set your symbology rules like this:

attribute( $currentfeature, left(@layer_name,8)) = 'fieldvalue' AND "whatever other filter"

This extracts the first 8 characters of your layer name (the plan name) and for each feature in the layer, queries the field of that name to match the values as the first filter.

enter image description here

Your symbology should then be universal for each layer type. Hope this helps!

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.