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
Use
Summary Statistics (Analysis)—ArcGIS Pro | Documentation
with your river name/id as the case field
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.