Cursors are much faster than field calculations, so performance would improve using an UpdateCursor.
I have a feature class with 266,927 records which I used to test the field calculation and the UpdateCursor. The field calculation was substantially faster than the UpdateCursor. The field calculation completed in 37 seconds. The UpdateCursor took 8 minutes and 50 seconds. My code is a bit more complicated because it includes a sort order, but I wouldn�??t expect to be that much of a performance hit. If UpdateCursor is supposed to be quicker any idea where I may have slowed the process down?Field Calculationrec=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
My UpdateCursor codeimport arcgisscripting
# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
# Input Variables
inputFC = gp.GetParameterAsText(0) #Input Feature Class
inputField = gp.GetParameterAsText(1) #Field to calculate
inputStart = gp.GetParameterAsText(2) #Starting value. Default value of 1 in ArcToolbox
inputIncrement = gp.GetParameterAsText(3) #Incement value. Default value of 1 in ArcToolbox
inputSortField = gp.GetParameterAsText(4) #Field to sort by
inputSortOrder = gp.getparameterastext(5) #Sort order. Value List (Ascending, Descending) with a default value of Ascending in ArcToolbox
def sortVariable(xSortField,xSortOrder):
if xSortOrder == "Descending":
return xSortField + " D"
else:
return xSortField + " A"
# UpdateCursor
def incrementNumbers(vFC,vField,vStart,vIncrement,vFieldList,vSort):
try:
value = int(vStart)
cur = gp.UpdateCursor(vFC,"","",vFieldList,vSort)
row = cur.Next()
while row:
row.setValue(vField,value)
cur.UpdateRow(row)
row = cur.Next()
value = value + int(vIncrement)
except:
# Warning messages
print gp.AddWarning(gp.GetMessages(1))
# Error messages
print gp.AddError(gp.GetMessages(2))
print gp.AddMessage("Complete")
# Variable of fields to use in the UpdateCursor
qFieldList = inputField + "," + inputSortField
# Variable for sort to use in the UpdateCursor
qSort = sortVariable(inputSortField,inputSortOrder)
incrementNumbers(inputFC,inputField,inputStart,inputIncrement,qFieldList,qSort)