0

I want to use Calculate Field in ArcGIS Pro to count up sequentially, but start over with each new group. The groups are defined by FEATUREID.

Example of desired output:

FEATUREID GEOMETRYID A 1 A 2 A 3 B 1 C 1 C 2

How can I modify the AutoIncrement() script to produce my desired result?

    rec=0
def SequentialNumber():
    global rec
    pStart = 1
    pInterval = 1
    if (rec == 0):
        rec = pStart
    else:
        rec = rec + pInterval
    return rec
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
mil
  • 11
  • 3
  • 1
    Or this https://gis.stackexchange.com/questions/200150/auto-incrementing-field-based-on-groups-within-feature-class#200154 – FelixIP Oct 04 '22 at 18:42
  • I hadn't seen the info from the first comment before, but couldn't get that to work. I had already seen the page FelixIP linked earlier today. Not sure what error I made then, but upon review I did get it to work. Thanks! – mil Oct 04 '22 at 20:30

1 Answers1

1

In the expression box:

//FIELD is the name of the field that you want to use as a unique identifier/what you want to group by

    GroupOrder(!FIELD!)

And in the code box:

d={}
def GroupOrder(FIELD):
  N=d.get(FIELD,0);N+=1
  d[FIELD]=N
  return N

This is the copy of the python command:

    arcpy.management.CalculateField("dataset_name", "Field_calc", GroupOrder( !FIELD!)", "PYTHON3", """d={}
    def GroupOrder(FIELD):
      N=d.get(FIELD,0);N+=1
      d[FIELD]=N
      return N""", "TEXT", "NO_ENFORCE_DOMAINS")
//replace dataset_name with the name of your layer
//replace Field_calc with the name of the field you're trying to calculate information for
//replace the 4 instances of FIELD with the name of the field you're grouping by

This will produce:

table of prodecut

mil
  • 11
  • 3
  • Ok overall, but too many changes to my code, GroupOrder(!FIELD!) would suffice without any modification of code within function itself. +1 for efforts. – FelixIP Oct 05 '22 at 03:02