1

I have a vector with different land use classes for which I want to add labels that correspond to their number. I am trying to use to QGIS field calculator, I have the code to replace one value into a new column, but I want to do it for all the independent variables. My code however seems incorrect and the label name doesn't change to what I want it to be. I have a total of six values that need a new label. I am using the code

replace("land_classes", '6', 'type 1') + replace("land_classes", '7', 'type 2')

enter image description here

asked Sep 4, 2023 at 12:28

1 Answer 1

4

It would be better to use a CASE statement Like so :

CASE
 WHEN "land_classes"='6' THEN 'type 1'
 WHEN "land_classes"='7' THEN 'type 2'
 ...
 ...
 ELSE 'Not a valid land use class'
END

Note that I assume that the "land_classes" is a text field so the value are between quote (as you did in your expression), if the "land_classes" field is rather a numeric field (by your picture that seem likely) you should not use quote around the value (so change ='6' to =6 ).

Also made sure to set the output field to string type.

answered Sep 4, 2023 at 12:52
1
  • Thanks J.R. this did exactly the trick Commented Sep 4, 2023 at 14:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.