I previously asked for help in Prioritizing the Attribute table of a self made polygon layer Prioritising polygons in QGIS

Now I want to change this prioritisation in accordance to multiple values of multiple columns.

I am looking for a nice way to add the logic

If "Area Size" > 10 ha then Prio = 1

If "Sun intensity" = high then Prio -1, otherwise Prio stays the same

If "Groundpoints" > X, then Prio +1, otherwise Prio -1

If "Restriction" = True, then Prio = 0

the minimum Priority possible is 1, because 0 determines the site of interest to be deleted and is only possible to be acchieved if "Restriction" = true.

The highest Priority possible is 3, which can either be determined through Area size (previous post) or additional factors (current post)

I am aware that I can achieve this command through endless WHEN, AND or OR Cases, however, I am looking for a clean and easy to understand solution.

  • I assume this is a typo, but the "groundpoints" value has no effect on the outcome ("If "Groundpoints" > X, then Prio +1, otherwise Prio +1"). – csk Mar 12 at 16:56
  • yes, its a typo, sorry. I changed it – Philip Gatzlaff Mar 13 at 18:43

Your pseudocode is written where you create an integer variable, and then add or subtract to it as you work through the lines of code. There's another, much simpler method, based on the fact that:

A true/false statement

  • evaluates to 1 when true
  • evaluates to 0 when false

So, we can simply convert your conditions to true/false statements and add them together. Each true/false statement should be set up so that it's true when you want to increase the priority. We have to reverse some of the statements, and adjust the syntax as follows:

If "Area Size" > 10 ha then Prio = 1

  • no change needed: ("Area Size" > 10)

If "Sun intensity" = high then Prio -1, otherwise Prio stays the same

  • reverse using != (!= means "does not equal"): ("Sun intensity" != 'high')

If "Groundpoints" > X, then Prio +1, otherwise Prio -1

  • substitute a numerical value for X in this statement: ("Groundpoints" > X)

If "Restriction" = True, then Prio = 0

  • this condition overrules the other conditions, so make it an if-statement, where the sum of the other conditions is the "else" outcome: if("Restriction" = 'True', 0, [sum of other conditions])

The final expression looks like this:

if("Restriction" = 'True', 0, ("Area Size" > 10) + ("Sun intensity" != 'high') +("Groundpoints" > X))

Every value in double quotes must be a field in the current layer's attribute table.

Use the expression in the Field Calculator to create or update the field "Prio".

enter image description here

My output preview (shown at the bottom of the field calculator window) is NULL because my layer doesn't the fields "Area Size", "Sun intensity" and "Groundpoints". Your output preview should be an integer between 0 and 3.

  • thanks for the solution, however, this disregards the prioritization in regards to area size, which i linked in my first post.Because the Prioritization will also have to change in accordance to area size. So everything over 10 ha is prio 1, between 10 and 5 ha is prio 2, between 5 and 1 ha is prio 3 – Philip Gatzlaff Mar 13 at 18:45
  • I didn't answer your other question when I answered this question. – csk Mar 13 at 18:53

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.