0

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.


Working code:

enter image description here

contours = arcpy.GetParameterAsText(0) desc = arcpy.Describe(contours) arcpy.env.workspace = desc.path arcpy.AddField_management(contours, "Cumulative_AC", "DOUBLE") arcpy.AddField_management(contours, "Acres", "DOUBLE") CursorFieldNames = ["SHAPE@", "Cumulative_AC", "Acres"] RunTl = 0 with arcpy.da.UpdateCursor(contours, CursorFieldNames, sql_clause=(None, 'ORDER BY DEPTH DESC')) as cursor: for row in cursor: AreaValue = row[0].getArea('GEODESIC', 'ACRES') # Read area value as double RunTl += AreaValue # Capture running total row[1] = RunTl # Write total area value plus the previously added values to field row[2] = AreaValue cursor.updateRow(row) del RunTl 
6
  • 2
    Your del statement is not required when using with for your cursor. What happens when you remove that line of code? Commented Jun 1, 2019 at 2:16
  • 2
    You have already sorted the values since you make no attempt at this in the code? Commented Jun 1, 2019 at 7:09
  • @PolyGeo, no change. Commented Jun 3, 2019 at 16:23
  • @BERA You're right, didn't add the sort_management tool yet. Will update. Commented Jun 3, 2019 at 16:23
  • @SonofaBeach screenshot is showing what I want the results to be in column "cumulative". Commented Jun 3, 2019 at 16:24

1 Answer 1

4

It looks like you’re setting the ‘cumulative’ field to the area of that record only, not the running total.

Try replacing:

row[1] = AreaValue 

with:

row[1] = running 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.