I have a shapefile with a field attribute called "Value"
.
I would like to find the min
and max
in this field and
- if
max-min > 0.014
return1
(orYes
) - if
max-min < 0.014
then return2
(orNo
)
in the field called "YES_NO"
.
Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Nov 7, 2018 at 7:49
-
1have you already seen these articles: Determining Min/Max values from feature class using ArcPy?, arcpy min/max/unique values of a field?Taras– Taras ♦2018年11月07日 08:00:13 +00:00Commented Nov 7, 2018 at 8:00
-
So all rows will have yes or all will have no?Bera– Bera2018年11月07日 08:07:29 +00:00Commented Nov 7, 2018 at 8:07
-
It is unclear. Do you want to know if the difference between two successive rows more or less than 0.014, or just max - min values in the Value field more or less than 0.014? Please explain in your question.ahmadhanb– ahmadhanb2018年11月07日 08:10:49 +00:00Commented Nov 7, 2018 at 8:10
-
no, can be completely 1 or completely 2Anahita Kp– Anahita Kp2018年11月07日 08:11:16 +00:00Commented Nov 7, 2018 at 8:11
-
in this example the max = 1.1255 and min = 1.0852. max - min = 0.040 so its > 0.014. so the field YES-NO is filled completely by 1Anahita Kp– Anahita Kp2018年11月07日 08:15:54 +00:00Commented Nov 7, 2018 at 8:15
1 Answer 1
Use the da.SearchCursor to find min, max and diff. Update field with the UpdateCursor:
import arcpy
fc = r'C:\data.gdb\featureclass'
fields = ['Value','YES_NO']
all_rows = [i[0] for i in arcpy.da.SearchCursor(fc,fields[0])]
min_val = min(all_rows)
max_val = max(all_rows)
difference = max_val-min_val
if difference > 0.014:
newval = 1
elif difference <= 0.014:
newval = 2
else:
newval = 3
with arcpy.da.UpdateCursor(fc,fields[1]) as cursor:
for row in cursor:
row[0] = newval
cursor.updateRow(row)
answered Nov 7, 2018 at 8:16
lang-py