Select to view content in your preferred language

Summing together feature attributes within the same Feature Class

4243
5
Jump to solution
02-26-2015 12:46 PM
JacobGuthrie
Deactivated User

I ran into this problem when I wanted to show road segments' total volumes as one single label for each segment, but our feature class has features for both directions of the roadways with separate volumes for each direction.

 

Is there a way to sum together the PCE_VOLU_3 field for each feature with the same attributes for the NO field? Any scripting solutions(python would be preferred)? I figured out a way to accomplish this in Excel by creating a formula by identifying cells, but I would much prefer to find a way to accomplish this in Arc map.

 

Any help would be appreciated.

 

Thank you,

Jacob

0 Kudos
1 Solution

Accepted Solutions
OwenEarley
Frequent Contributor

The Summary Statistics tool will produce a separate table. You can always join this back to your original data if you want to use the values for labels, etc.

View solution in original post

0 Kudos
5 Replies
OwenEarley
Frequent Contributor

Check out the Summary Statistics tool. You could SUM the PCE_VOLU_3 fields using NO as your case field.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Once you sum the values, how do you want to store them?  Do you want a separate table?  Do you want a new column in this table where is shows the same sum for all of the records with the same NO?

0 Kudos
JacobGuthrie
Deactivated User

A separate table would be best.

0 Kudos
OwenEarley
Frequent Contributor

The Summary Statistics tool will produce a separate table. You can always join this back to your original data if you want to use the values for labels, etc.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

As Owen Earley‌ suggests, the Summary Statistics tool should work, and it is scriptable through Python.

You could also use a data access (arcpy.da) search cursor approach, a bit more involved but likely more performant than Summary Statistics.

# import functions from modules that are available but not commonly imported
from collections import defaultdict
from numpy import fromiter, dtype

# sum PCE_VOLU_3 by NO
stats = defaultdict(int)
with arcpy.da.SearchCursor(input_fc, ['NO','PCE_VOLU_3']) as cur:
    for k, v in cur:
        stats += v

# create iterable and populate numpy array  
stats_iterable = ((k, v) for (k, v) in stats.iteritems())  
tmp1 = fromiter(stats_iterable,  
                dtype([('NO', 'i4'), ('SUM_PCE_', 'f8')]))

# Dump numpy array to table  
arcpy.da.NumPyArrayToTable(tmp1, out_table)  
del tmp1  
del stats 
0 Kudos