You could use a cursor with a sort on it:infc = my input feature classmyField = field I am after the max value fromOID = 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(infc, "", "", "", myField+ " D").next().getValue(OID)
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("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)
minValue = arcpy.SearchCursor("Stewardship", "", "", "", "OID A").next().getValue("OID") arcpy.MakeFeatureLayer_management ("Stewardship", "feat_layer") arcpy.SelectLayerByAttribute_management ("feat_layer", "NEW_SELECTION", " [OID] = " + maxValue) Whatever you do now on "feat"layer" will honor the selection if that tool supports it.
maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID D").next().getValue("OBJECTID") arcpy.AddMessage(maxValue)
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.
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.
I have OBJECTID, not OID, however when I try your code it prints always the first record. I tried both with A and D. I tried sorting by SequenceNumber (numbers from 1 to 8), and I tried sorting by OBJECTID. Which I get is always the first number. So for example, SequenceNumber 1 I get OBJECTID 2451 (object id for sequence number 1) and if I sort by OBJECTID, I get 2445, no matter what (the objectids go from 2445 to 2451). I am using SQL feature class. Any idea why this is happening? Also, you mentioned you can't do anything with a fc for a selection. Is that the same with a selection by location? Because I was able to select by location just using the fc name ("Stewardship), without creating a feature layer. Would you know why that worked? Thank you!!! maxValue = arcpy.SearchCursor("Stewardship", "", "", "", "OBJECTID D").next().getValue("OBJECTID") arcpy.AddMessage(maxValue)
maxValue = arcpy.SearchCursor(infc, "", "", "", "OBJECTID D").next().getValue("OBJECTID") max Value = 2110 minValue = arcpy.SearchCursor(infc, "", "", "", "OBJECTID A").next().getValue("OBJECTID") min Value = 1
I am actually running the script I am writing so I am not directly using the tool. Not sure why it works.
ExecuteError: Failed to execute. Parameters are not valid. The value cannot be a feature class ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByAttribute).
Rhett, Please disregard my dumb question 🙂It was really the problem with the tab! It is working great! I will post another thread if I have any more questions about the updating of rows using this type of selection! Thank you so much! You rock!
I created a toolbox and added the script and I am running from there, when I click on the script.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.