ArcMap Field Calculator: Calculating Running Total with arcpy

I had a user with a series of GPS points (that were in chronological order) that they wanted to know the accumulated distance from the start to each point in their shapefile. First, we calculated the distance from each point to the previous point into a field called [DistFt].

Then, we hacked out this quick python function to accumulate the total distance in Arcmap’s Field Calculator:

totalDistance = 0

def accumulateDistance(inDist):
   global totalDistance
   totalDistance += inDist
   return totalDistance

And we called it:

accumulateDistance(!DistFt!)

accumulateDistAnd we got what we wanted.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s