English

How to: Calculate cumulative shape length values of a feature class using the Field Calculator

Summary

Features in a geodatabase feature class have a system-generated field for SHAPE_Length. However, there is no system-generated field for the cumulative length values. Therefore, a new field must be created and a Field Calculator expression used to get the correct cumulative length values. The following is an example of a cumulative sum being applied:
 

FeatureIndividual LengthCumulative Length
110m10m
215m25m
35m30m
425m55m
510m65m

Procedure

The instructions provided describe how to generate a field with cumulative length values.

  1. Add a new field to the attribute table.
    Note:
    The name must not contain spaces.
    1. Click the Table Options icon in the upper left hand corner of the attribute table and click Add Field
      Select the attribute table add field option.
    2. In the Add Field dialog box, enter a name for the new field.
    3. Set the Type to Double.
      Selection of name and type in Add Filed dialog box
    4. Click OK to close the dialog box. The new field is created in the attribute table.
  2. Calculate the field:
    Note:
    Ignore the warning that appears and click YES to close the dialog box.
    1. Right-click the heading of the newly-created field and select Field Calculator.
    2. In the Field Calculator dialog box, select the Python parser.
    3. Check the Show Codeblock check box.
    4. Copy and paste the following codeblock into the Pre-Logic Script Code: box.
      cummulativeLength = 0
      
      def cummulativeValue(increment):
          global cummulativeLength
          cummulativeLength += increment
          return cummulativeLength
    5. Copy and paste the following code in the second box:
      cummulativeValue(!SHAPE_Length!)
      Enter the code provided.
    6. Click OK to run the calculation. The fields populated are with the accumulated values.

Related Information