4

I am wanting to add numbering with letters for polygons with the same value.

An example would be a field consisting of fruit types:

Apple
Apple
Apple
Pear
Pear
Banana
Orange
Orange
Orange
Orange

which would be converted to:

AppleA
AppleB
AppleC
PearA
PearB
BananaA
OrangeA
OrangeB
OrangeC
OrangeD

2 Answers 2

14

You can follow the method in this answer and convert the numbers to letters by replacing +1 with +65 to generate output from 65-90 (ASCII codes from A-Z) and then putting the numeric result through char(). Then concatenate the resulting letter to your field.

"YOUR_FIELD" ||
char(
    array_find(
        array_sort(
            array_agg($id, 
                      group_by:="YOUR_FIELD")),
        $id)
    +65)

Before and after:

enter image description here enter image description here

0
9

You can create a virtual layer with the query:

select *,
concat( "Fruit", Char(64 + row_number() over(partition by "Fruit"))) as newfruit
from testpoints

row_number function will enumerate (1,2,3,...) each unique Fruit and Char will replace each number with the unicode character

Change "Fruit" to the name of your field and testpoints to the name of your layer.

enter image description here

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.