5

I have a layer with around 1000 lines. Some Name are repeated several times and I wish to have every name unique. Thus I try in the field calculator to add an integer at the end of the name only when it is a duplicate, and of course I want to increment the integer value each time it is used. As an example, in my layer I have in the Column 'Name':

Name_One
Name_One
Name_Two
Name_Two
Name_One

And I would like it to become

Name_One1
Name_One2
Name_Two1
Name_Two2
Name_One3

I tried first to identify the duplicate with the function

if(count("Name", "Name") = 1, 1, 0)

Then with the new column "uniqueness" that hold the value of the previous command I try

CASE
    WHEN 'uniqueness' = 0 THEN @a
    WHEN 'uniqueness' = 0 THEN @a = @a+1
    ELSE @a = 1
END

(@a is a project variable equal to 1)

But it doesn't work.

How can I do that?

5

QGIS 3.0/3.2

(1) Use Add autoincremental field tool (in Processing Toolbox | Vector table) to create new incremental number field.

  • Input layer: your layer
  • Field name: any name (default value is AUTO)
  • Start values at: 1
  • Group values by: select your column Name
  • Advanced parameters - Sort expression: select id

(2) Put Name and AUTO fields together

Open the Field Calculator and create a new field by concat("Name", "AUTO")

enter image description here

0

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.