Solved! Go to Solution.
You could use a cursor with a sort on it:
infc = my input feature class
myField = field I am after the max value from
OID = ObjectID field of my FC.maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID)
change the myField field to the one you want the max value from and grab the "OID" of that record as maxValue variable.
this would give you the values, could then use that to select by.
R_
Is there a way to select a record based on the highest value of a field? And also is there a way to check if a record is selected based on the highest value before I update a record? Thanks
maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID)
You could use a cursor with a sort on it:
infc = my input feature class
myField = field I am after the max value from
OID = ObjectID field of my FC.maxValue = arcpy.SearchCursor(infc, "", "", "", myField+ " D").next().getValue(OID)
change the myField field to the one you want the max value from and grab the "OID" of that record as maxValue variable.
this would give you the values, could then use that to select by.
R_
maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID A").next().getValue("OBJECTID") with maxValue as rows: # row comes back as a tuple in the order specified here, so Office is row[0], Forester is row[1] yearonly = DateStart[5:9] for row in rows: row[0] = yearonly rows.updateRow(row)
maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID A") for srow in maxValue: result = int(arcpy.GetCount_management("Stewardship").getOutput(0)) arcpy.AddMessage(result)
maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID A").next().getValue("OID") arcpy.SelectLayerByAttribute_management("Counties", "NEW_SELECTION", maxValue) result = int(arcpy.GetCount_management("Stewardship").getOutput(0)) arcpy.AddMessage(result)
I think I am getting there but still getting an error for the first line. Do you see anything wrong on the first line? Thanks!!!!
I am getting this error:
Error Info:
<type 'exceptions.RuntimeError'>: ERROR 999999: Error executing function.maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID A").next().getValue("OID") arcpy.SelectLayerByAttribute_management("Counties", "NEW_SELECTION", maxValue) result = int(arcpy.GetCount_management("Stewardship").getOutput(0)) arcpy.AddMessage(result)
rows = arcpy.UpdateCursor("Stewardship", "", "", "", "OBJECTID A") row = rows.next() row.yearonly = DateStart[5:9] rows.updateRow(row)