import arcpy, os, string LAYERS = arcpy.GetParameterAsText(0) SLOSHFILEDS = [f.name for f in arcpy.ListFields(LAYERS,"","DOUBLE") arcpy.CalculateField_management (LAYERS, "MAXSURGE", max(SLOSHFILEDS))
SLOSHFILEDS = arcpy.ListFields(LAYERS,"","DOUBLE") fieldNameList = [] for field in SLOSHFILEDS: if not field.required: fieldNameList.append(field.name) arcpy.CalculateField_management (LAYERS, "MAXSURGE", max(fieldNameList))
Solved! Go to Solution.
curs.updateRow(row)
field_str = "!" + "!, !".join(fieldNameList) + "!"
import arcpy import os import string LAYERS = arcpy.GetParameterAsText(0) SLOSHFIELDS = [f for f in arcpy.ListFields(LAYERS,"","DOUBLE")] fieldNameList = [] for field in SLOSHFIELDS : if not field.required: fieldNameList.append(field.name) max_field = "MAXSURGE" curs = arcpy.UpdateCursor(LAYERS) for row in curs: max_val = 0 for field in fieldNameList: val = row.getValue(field) if val > max_val: max_val = val row.setValue(max_field, max_val) curs.updateRow(row)
LAYERS = arcpy.GetParameterAsText(0) SLOSHFILEDS = [f.name for f in arcpy.ListFields(LAYERS,"","DOUBLE") #presuming this filters your fields to the ones you want to compare rows = arcpy.UpdateCursor(LAYERS) #leaving field names out of the cursor tool returns all fields for row in rows: comp_values = [] for fname in SLOSHFILEDS: comp_values.append(row.fname) max_val = max(comp_values) row.MAXSURGE = max_val rows.updateRow(row)
SLOSHSTRING = str(fieldNameList) calculation = "\"max(" + SLOSHSTRING + ")\"" arcpy.CalculateField_management (LAYERS, "MAXSURGE", calculation, "PYTHON", "")
arcpy.CalculateField_management (LAYERS, "MAXSURGE", "max( !SURGE90!, !SURGE90_1!, !SURGE90_12!, !SURGE90_13!, !SURGE90_14!, !MAXSURGE!)", "PYTHON", "")
arcpy.CalculateField_management (LAYERS, "MAXSURGE", "max( !SURGE90!, !SURGE90_1!, !SURGE90_12!, !SURGE90_13!, !SURGE90_14!, !MAXSURGE!)", "PYTHON", "")
arcpy.CalculateField_management (LAYERS, "MAXSURGE", max({ListObject}), "PYTHON", "")
curs.updateRow(row)
field_str = "!" + "!, !".join(fieldNameList) + "!"
"exceptions.RuntimeError: Row: Field fname does not exist."
LAYERS = arcpy.GetParameterAsText(0) SLOSHFILEDS = [f.name for f in arcpy.ListFields(LAYERS,"","DOUBLE") #presuming this filters your fields to the ones you want to compare rows = arcpy.UpdateCursor(LAYERS) #leaving field names out of the cursor tool returns all fields for row in rows: comp_values = [] for fname in SLOSHFILEDS: nom = fname.name comp_values.append(row.getValue(nom)) max_val = max(comp_values) row.MAXSURGE = max_val rows.updateRow(row)
Ok, this has got under my skin a little