Using Cumulative Geometry Calculation to Add Field in ArcPy

236
1
05-31-2019 05:18 PM
RobertClark5
New Contributor

I am using Desktop 10.6, basic license, Spatial Analyst, python 2.6, 2019 AD.

I have 4 overlapping features in a polygon feature class. I'd like to sort the features by the depth field, calculate the acreage for the largest depth, then move to the next depth, calculate its acreage and then add it to the previous depth, and so on. This code currently does not work past adding the cumulative field. In the attached photo, the cumulative depth is what I am trying to generate. The acres field is to show the progression. Testing the code in the Python window in Desktop reveals that the running total is not behaving as I would expect (printing repeating values versus an increasing value).

enter image description here

tempPgs = "LayerName"sort_fields = [tempPgs, "DESCENDING"]
arcpy.AddField_management(tempPgs, "cumulative", "DOUBLE")
CursorFieldNames = ["SHAPE@","cumulative"]
with arcpy.da.UpdateCursor(tempPgs, CursorFieldNames) as cursor:    
   for row in cursor:        
      AreaValue = row[0].getArea('GEODESIC', 'ACRES') #Read area value as double        
      running += AreaValue #Capture running total        
      row[1] = AreaValue #Write total area value plus the previously added values to field        
      cursor.updateRow(row)    
   del row, cursor #Clean up cursor objects
Tags (3)
0 Kudos
1 Reply
DanPatterson_Retired
MVP Esteemed Contributor

don't you want

row[1] = running