1

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 return 1 (or Yes)
  • if max-min < 0.014 then return 2 (or No)

in the field called "YES_NO".

enter image description here

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Nov 7, 2018 at 7:49
5
  • 1
    have you already seen these articles: Determining Min/Max values from feature class using ArcPy?, arcpy min/max/unique values of a field? Commented Nov 7, 2018 at 8:00
  • So all rows will have yes or all will have no? Commented 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. Commented Nov 7, 2018 at 8:10
  • no, can be completely 1 or completely 2 Commented 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 1 Commented Nov 7, 2018 at 8:15

1 Answer 1

2

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.