I am in ArcMap and I want to sort the records based on a field and then do a Calculate Field with an auto-incrementing value with the sort in-place. Any ideas?
It looks like I could get an update cursor on the feature class then do an auto-increment, but I would still like to see if there is a way to do this in the Field Calculator in ArcMap.
Answer
I used ModelBuilder and I did a field sort followed by calculate field using the sort code below and it worked great.
Previously, I had tried these two steps outside of ModelBuilder and it failed.
Expression:
autoIncrement()
Expression Type: PYTHON_9.3
Code Block:
rec=0
def autoIncrement():
global rec
pStart = 1 #adjust start value, if req'd
pInterval = 1 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec
No comments:
Post a Comment