2

I have a feature class generated in ModelBuilder using a transect script that contains multiple transects. Before moving on to further build the survey I would like to assign ID's to each feature in the class using field calculator. It needs to be string, i.e. A,B,C....and so on. After 26 features I would like to name it AA, BB, CC and so on.

Does anyone have a script that could accomplish this?

1
  • 1
    Have you written/found the code to do this using sequential numbers? Once you have that this distills to a pure Python question that I think will be better researched at Stack Overflow.
    – PolyGeo
    Commented Feb 15, 2017 at 19:26

1 Answer 1

3

Field Calculator (with Python) - Check Show Codeblock on.

This will cycle through the alphabet A-Z, then AA-ZZ and then AAA - ZZZ and so on

Pre-Logic Script

import string
alphabet = list(string.ascii_uppercase)
record_count = 0
multiplier = 0

def alphabet_ID():
    global alphabet
    global record_count
    global multiplier
    if record_count % len(alphabet) == 0:
        multiplier += 1
        record_count += 1
        return alphabet[0] * multiplier
    else:
        alpha_index = record_count % len(alphabet)
        record_count += 1     
        return alphabet[alpha_index] * multiplier

Function block

alphabet_ID()

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.