2

I am working with vegetation types within a project site. Each vegetation type belongs to a broader group termed a "vegetation group". For example, in the screen shot below, I have the two vegetation types 'WC1' and 'WC2' which belong to the 'Wet Coniferous Forest Group'.

Is there a way by expression to populate a new column with the the appropriate vegetation group based on the vegetation types in a column? In this example, all 'WC1' and 'WC2' would be in the 'Wet Coniferous Forest Group' which would be in a new column.

enter image description here

2 Answers 2

8

Use the Field calculator with a CASE-statement. The expression looks like this, where "vegetation_type" is the name of the field containing the WC1, WC2 values:

case 
    when "vegetation_type" in ('WC1', 'WC2') then 'Wet Coniferous Forest Group'
end

Before the end statement, you can add as many similar when ... then statements as you like:

when "vegetation_type" in ('WC3', 'WC4') then 'Another Group'

You can also add an else statement that returns the output in all other cases, something like else 'other'. Add this after the last when statement, before end:

case 
    when "vegetation_type" in ('WC1', 'WC2') then 'Wet Coniferous Forest Group'
    when "vegetation_type" in ('WC3', 'WC4') then 'Another Group'
    else 'other'
end
1
  • This worked great! Thanks
    – Erioderma
    Commented Jan 12, 2022 at 18:19
4

Another way of doing this which may work better if you have a dynamic data set, would be to make a look-up table. i.e. a table with two fields type and group and then fill in the table with the actual groups,

 type | group
 -----+----------------
 WC1  | Wet Coniferous
 WC2  | Wet Coniferous
 WC3  | Another group
 WC4  | Something else

Then you join this table to the existing data set

1
  • I will look into using this solution as well. Thanks
    – Erioderma
    Commented Jan 12, 2022 at 18:19

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.