0

I am trying to calculate field with the formula. I tried arcpy.calculate field management but still having difficulty.

(10/10.4*(100*(math.exp(0.000871* !A!)-1+math.exp(0.000537* !B! )-1+math.exp(0.000487* !C! )-1)))

I used the below code.

with arcpy.da.UpdateCursor(fc, (VALUE, A, B, C)) as cursor: for row in cursor: row[0] = (10/10.4*(100*(math.exp(0.000871* !A!)-1+math.exp(0.000537* !B! )-1+math.exp(0.000487* !C! )-1))) cursor.updateRow()

3
  • A field cannot do a calculation by itself. Fields do not have a 'calculation' type. Just text, integers, floats, etc. You may want to look into using a database 'view' which can include automatic calculation columns. In ArcGIS, you can use a 'Query Layer' which is essentially a layer based on a spatial view definition. Or you can just create a spatial view and drag it onto ArcMap. I haven't checked, but there may be arcpy equivalents for doing similar things, but you should probably explain further what you are actually trying to achieve. Nov 23, 2018 at 2:02
  • 3
    Please use code block formatting on code. All it takes is indenting four spaces or using the {} button in the editor. The result will be legible code (and fewer downsides)
    – Vince
    Nov 24, 2018 at 17:28
  • 1
    And please don't re-ask questions. All you needed to do was make the code edit and vote to reopen.
    – Vince
    Nov 24, 2018 at 19:49

1 Answer 1

2
#You need to reference each Field its Index in your list of Fields.
# what values are in A,B,C? string, integer,double? you may need to cast them

with arcpy.da.UpdateCursor(fc, ['VALUE', 'A', 'B', 'C']) as cursor: 
        for row in cursor:
            calc_a = math.exp(0.000871* row[1])-1
            calc_b = math.exp(0.000871* row[2])-1
            calc_c = math.exp(0.000871* row[3])-1
            row[0] = (10/10.4 * (100* (calc_a + calc_b + calc_c))))
            cursor.updateRow()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.