If the field isn't indexed and has a lot of unique variables the sort can take a while. I wouldn't think it would be in the order of 8 minutes though. The 9.3 cursors were not quite as fast if I recall. If you are reading the feature class in the update cursor instead of a layer how you are with the field calculator that can also have an impact.
Cursors are much faster than field calculations, so performance would improve using an UpdateCursor.
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
import 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)
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.