Tuesday, 9 February 2016

Sorting feature class to calculate sequential ID field using ArcGIS Field Calculator?


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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...