# Prioritising polygons in QGIS

I just created a layer in which I hand drew a lot of polygons.

Now I want to fill out the Attribute table through commands since it will save me a bunch of time.

Therefore, I calculated the area of each polygon using `\$area/10000` to have the size in `ha`.

I want to prioritize each area

• above 10 ha as Prio 1
• each below 1 ha as Prio 3
• each in between as Prio 2

Does anyone have a smart solution to the problem?

My closest approach is: `IF ("Size ha" > 10, 1, 2)`

That however still leaves me with having to distinguish the areas of Prio 2 to Prio 3 manually.

• Just a general annotation: The expamples given on the different tools in the field calculator are quite useful to picture, how the tools work. – Erik Feb 26 at 10:25

Using the `CASE`-statement

``````CASE
WHEN "Size ha" >= 10 THEN 'Prio 1'
WHEN "Size ha" > 1 AND "Size ha" < 10 THEN 'Prio 2'
WHEN "Size ha" <= 1 THEN 'Prio 3'
END
``````

Or as was provided by @Erik, the upper formula can be rewritten using the `if`-statement

``````if("Size ha" >= 10, 'Prio 1', if("Size ha" <= 1, 'Prio 3', 'Prio 2'))
``````

References:

• Ah, thanks. I tried using WHEN clauses, but somehow didnt end up at a fitting result. My command looked different though. I will try it out! – Philip Gatzlaff Feb 26 at 10:23
• Another possbile solution, though I do not like doublechecks on conditions, they tend to be a bit complicated in my experience. – Erik Feb 26 at 10:23
• @Taras that is my own judgement, I usually mess up conditions when having to check upper and lower boundaries ;-) – Erik Feb 26 at 10:32
• @Erik, I think I will happen to me as well. However, when I have for instance 20 conditions I will be lost within a number of parenthesis in If-condition :-) – Taras Feb 26 at 10:35
• Just create a new column and fill it with CASE formula. – Taras Feb 26 at 10:39

This should work

``````if(\$area/10000 > 10,1,if(\$area/10000 < 1,3,2))
``````

Just a capsuled if-condition, first checking for areas greater 10 ha, then checking for those smaller than 1 ha, then giving everything else Prio 2.

There is no need for the `AND` in the `CASE-WHEN-...` construct. Since the first matching result is returned, you can simply make an ascending order of the values you would like to test for:

``````CASE
WHEN "Size ha" <= 1 THEN 'Prio 3'
WHEN "Size ha" < 10 THEN 'Prio 2'
ELSE 'Prio 1'
END
``````

Note also, that there is no explicit test needed for `"Size ha" >= 10`.

• Yes, you right! – Taras Jul 25 at 6:49