3

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
5

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.

5
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 as

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
  • 1
    @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
  • 1
    @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
  • 1
    Just create a new column and fill it with CASE formula. – Taras Feb 26 at 10:39
0

CASE

WHEN "Size ha" =>10 THEN 'Prio 1' for the area above 10 ha

WHEN "Size ha" <10 AND "Size" >1 THEN 'Prio 2' for the area between 10 ha to 1 ha

WHEN "Size ha" <1 THEN 'Prio 3' for the area below 1 ha

END

Use the code to update the priority field.

  • May I ask what is the difference with my answer? Thank you – Taras May 22 at 4:43

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.