0

I am trying to create a unique ID for my street feature class. (My unique ID starts with first 3 letters of the Street Name, 2 letters of the Street type, and 3 letters of the City Name Abbreviated.)

Where I am stuck is that I am trying to get a number to increment on the segments that would be duplicated. For example, Glenacre Drive has three segments. The UniqueID would be GLEDRHQF01, GLEDRHQF02, GELDRHQF03.

I cannot figure out how to create sequential numbers not based off of the ObjectID sorting... For example, I used the following Field Calculator but realized it is looking at the ObjectID sort and my streets aren't entered in order...

Pre-Logic Script Code:

prevFieldValue = ''
counter = 1
def GetDuplicateCounter(myFieldValue):
  global prevFieldValue
  global counter
  if myFieldValue == prevFieldValue:
    counter += 1
  else:
    counter = 1
  prevFieldValue = myFieldValue
  return counter

= GetDuplicateCounter( !UNIQUEID! )

BERA
  • 72,339
  • 13
  • 72
  • 161
  • You can't control the order of the objectids, and only by specifying an ORDER BY can you run an arcpy.da.UpdateCursor calculation. – Vince May 11 '21 at 00:26
  • 1
    See if this https://gis.stackexchange.com/questions/200150/auto-incrementing-field-based-on-groups-within-feature-class/200154#200154 helps – FelixIP May 11 '21 at 00:46
  • 3
    As an aside, unique IDs should generally be simple unique integers. In general, including anything with actual meaning (eg, abbreviated streets), has the potential to cause problems later on (eg, street might have a name change). Anything with actual meaning should be in normal attribute fields, rather than unique identifiers. (Using simple integers also has the advantage of faster database indexing for searching/joining, etc.) – Son of a Beach May 11 '21 at 01:10
  • Have you tried Sort? Or just sort the table manually in the attriburte table by right-clicking one of the gray headers then Advanced sorting – BERA May 11 '21 at 05:32

0 Answers0