Skip to main content
Solved

How do I create unique ID by groups?


max_d

Hello,

I want to create a unique numeric ID in a new attribute field from a two-letters string attribute, this way:

feature - ID

AA - 1

AB - 2

AC - 3

BA - 1

BB - 2

CA - 1

CB - 2

 

CC - 3

 

CD - 4

etc...

 

I guess I need to count how many times a letter is listed and then create IDS for every count and repeat but I don't know how to do this.

 

Many thanks,

 

Max

Best answer by bwn

As long as it is a 2 character identifier and it is the first character that resets the ID Counter every time it changes:

  1. Input to Sorter: Sort by "Feature" Ascending
  2. Then use SubstringExtractor or AttributeCreator to extract the First Letter to a new Attribute, let's call it "FirstChar"
  3. The use Counter, set the Counter Name to @Value(FirstChar)

 

View original
Did this help you find an answer to your question?

5 replies

fmelizard
Safer
Forum|alt.badge.img+19
  • Safer
  • May 7, 2020

Hi @max_d Is the ID based only on the 2nd character in the string?


bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • Best Answer
  • May 8, 2020

As long as it is a 2 character identifier and it is the first character that resets the ID Counter every time it changes:

  1. Input to Sorter: Sort by "Feature" Ascending
  2. Then use SubstringExtractor or AttributeCreator to extract the First Letter to a new Attribute, let's call it "FirstChar"
  3. The use Counter, set the Counter Name to @Value(FirstChar)

 


max_d
  • Author
  • May 8, 2020
fmelizard wrote:

Hi @max_d Is the ID based only on the 2nd character in the string?

HiDanatsafe, indeed, the ID is based on the first one character in the string . A,B,C,D, etc.


tomfriedl
Contributor
Forum|alt.badge.img+13
  • Contributor
  • May 8, 2020
bwn wrote:

As long as it is a 2 character identifier and it is the first character that resets the ID Counter every time it changes:

  1. Input to Sorter: Sort by "Feature" Ascending
  2. Then use SubstringExtractor or AttributeCreator to extract the First Letter to a new Attribute, let's call it "FirstChar"
  3. The use Counter, set the Counter Name to @Value(FirstChar)

 

nice idea!


max_d
  • Author
  • May 8, 2020

Thank you Bwn, it's working really well!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings