ERROR 000539: Error running expression: CalcDiff(r"C:\Export_Output.dbf", "PIPELENGTH", "DISTANCE") <type 'exceptions.TypeError'>: 'geoprocessing cursor object' object is not iterable Failed to execute (CalculateValue).
import arcgisscripting gp = arcgisscripting.create(9.3) def CalcDiff(tbl,valField,diffField): procFields = valField + ";" + diffField sortField = valField Rows = gp.UpdateCursor(tbl, "", "", procFields, sortField) lastVal = 0 Row = Rows.next() while Row: val = float(Row.getValue(valField)) # calc the difference between the last value and this one diff = val - lastVal Row.setValue(diffField,diff) Rows.updateRow(Row) lastVal = val Row = Rows.next() del Row, Rows return tbl
What is the syntax I should be using? Thanks.
import arcpy def CalcDiff(tbl,valField,diffField): procFields = valField + ";" + diffField sortField = valField Rows = gp.UpdateCursor(tbl, "", "", procFields, sortField) lastVal = 0 while Row: val = float(Row.getValue(valField)) # calc the difference between the last value and this one diff = val - lastVal Row.setValue(diffField,diff) Rows.updateRow(Row) lastVal = val del Row, Rows return tbl
The sort ascending must also be done in the field calculator before doing the calculation.
import arcgisscripting gp = arcgisscripting.create(9.3) def CalcDiff(tbl,valField,diffField): procFields = valField + ";" + diffField sortField = valField Rows = gp.UpdateCursor(tbl, "", "", procFields, sortField) lastVal = 0 for Row in Rows: val = float(Row.getValue(valField)) # calc the difference between the last value and this one diff = val - lastVal Row.setValue(diffField,diff) Rows.updateRow(Row) lastVal = val del Row, Rows return tbl
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.