In QGIS I am working on a streets layer, on the attribute table I have these fields:

enter image description here

"CVE_VIAL" is an ID of the street and each street could be divided into several sections, each of these sections have an ID ("ID_TRAMO") that when concatenated with "CVE_VIAL" results in unique "ID".

In this example, I've already calculated one by one "ID_TRAMO" with consecutive numbers, and what I'm trying to find right now is a way to do this automatically.

  • 1
    One question per Question, please (choose a platform, and tell us what you tried)
    – Vince
    Feb 24 at 3:33
  • 2
    I feel like I've answered a question like this before... have a look at gis.stackexchange.com/questions/353618/… and see if it suits your needs, in your case CVE_VIAL replaces name and ID_TRAMO replaces ID_2 in my answer. If you don't have any python skills don't panic, the function can easily be modified to an advanced field calculation in ArcGIS but the function as written will have no respect for any values already assigned, again this isn't too difficult to fix if you need to keep existing Feb 24 at 4:05
  • Please, do not forget about "What should I do when someone answers my question?"
    – Taras
    May 23 at 8:08

2 Answers 2

  1. Add autoincremental field, name it temp and group values by "CVE_VIAL"

  2. Field Calculate a new string field named "ID_TRAMO" with the formula:

    lpad( to_string("temp"), 5, '0')

enter image description here

  • 1
    Thank you, this worked for me :) Feb 24 at 22:22

Use this expression:

array_find(array_agg($id, group_by:=CVE_VIAL), $id) + 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.