Select to view content in your preferred language

Multiple Totals In a single Attribute Table field

394
2
12-12-2022 06:30 AM
TimothyODoherty
New Contributor II

So I have multiple rivers within the one shapefile, I want to get the length for each river, I have this script inserted into the field calculator but it outputs a total for all the rivers, I would like to stop with every new river and start a new total. 

 

Expression:

accumulate(!Shape_Length!)

Code Block:

total = 0

def accumulate(increment):

global total

if total:

total += increment

else: total = increment

return total

 

I have a river ID to differentiate each river in the shapefile. This can be seen in the image as SegmentID

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

Use

Summary Statistics (Analysis)—ArcGIS Pro | Documentation

with your river name/id as the case field


... sort of retired...
AyanPalit
Esri Regular Contributor

Agree with @DanPatterson on using 'SUM' with river ID as 'case_field'  Summary Statistics (Analysis)—ArcGIS Pro | Documentation

Alternately, use 'groupby' river ID in your Python expression.  

Ayan Palit | Principal Consultant Esri
0 Kudos