6

Attributes

I'd like to convert unique labels C3nv to 1, C3pr to 2, C3rt to 3 and so on using the field calculator.

Is that possible or would I need to write a stand-alone script?

1
  • Do you have an exhaustive list of unique labels, or are you planning to use the expression on several layers with varying numbers of unique labels?
    – Erik
    Commented Aug 15, 2022 at 12:29

1 Answer 1

8

The very basic approach to this is:

CASE
WHEN "index" = 'C3nv' THEN 1
WHEN "index" = 'C3pr' THEN 2
WHEN "index" = 'C3rt' THEN 3
ELSE 0
END

Or a little more elegant and a huge time saver for a big list:

array_find(array_distinct(array_agg("index",order_by:=$id)),"index") + 1

You can also change the order_by part to whatever sorting you wish.

0

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.