Select to view content in your preferred language

# Summing a field in the field calculator

1369
2
10-24-2022 12:33 PM
Status: Open
Labels (1)
New Contributor II

I am a GIS instructor at UBC. I'm looking to show my students how to normialize a field by its sum (e.g. divide shape area by the sum of shape area to calculate relative coverage). This seems like it should be an easy thing to do. In python using numpy, it would be ...

Relative_Cover = Shape_Area/Shape_Area.sum()

I want to show my students how to do something like this in the field calculator, but it doesn't seem like there is a way? I've been searching the docs and I cannot find a way to get the field calculator to calculate the sum of a field without using python (too complex for intro GIS students).

I could have them create a summary table then join it to the original, or manually type in the summary statistics. But this is clunky and easy to make a typo. Is there no way to sum a field within the field calculator? This really seems like something that should exist already, but it doesn't, so I'd like to submit a feature request.

Tags (2)

@JuneSkeeter maybe I am missing something, but I believe the reason you cannot do this in Field Calculator is because this problem requires the iteration of the table, in order to sum all of the Shape_Area fields, prior to performing the final calculation; and Field Calculator lacks that functionality. It can perform accumulative calculations, but only through a single loop.

Unless there is some other functionality I have missed, your best option would be to perform the action you mentioned, of creating a summary table, then copying your sum value and pasting it into your formula. I know that's a few extra clicks, but if may paraphrase you: unless you can learn some Python, these are the tools you have to work with. Not unlike finding duplicate values and then selecting those values in the attribute table: you can do it outside of Python, but you are going to be clicking through a few dialog windows to get you to the same result only a few lines of code would get you.

On a side note: since you are working with students and molding our next batch of GIS professionals, might this be a good side exercise of learning the value of copying and pasting, instead of manually typing? As GIS professionals, I am sure we have all had to experience the horrors of human error when dealing with dataset management, and learning the harsh lessons of how simple workflows, like copying and pasting instead of manually typing, could mitigate a lot of future headaches for clients and colleagues.

the reason you cannot do this in Field Calculator is because this problem requires the iteration of the table, in order to sum all of the Shape_Area fields, prior to performing the final calculation; and Field Calculator lacks that functionality.

This is true for Python. In Python, things like this are easiest done with an arcpy.da.UpdateCursor.

You can do it with Arcade:

``\$feature.Shape_Area / Sum(\$featureset, "Shape_Area")``