how to calculate cumulative distance between points?

5644
2
07-27-2016 03:59 AM
PrasadsinhDalavi
New Contributor II

hello folks, I'm trying to calculate the cumulative distance for a set of points which are located in a linear pattern. I'm using ArcGIS 10.3.1 Standard licence.

0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

If you want distance from the first point in a data table to every other point in sequence,  then use cumulative distance function below.

Do the following:

  • select Python parser
  • toogle on Show  code block
  • paste the following in the Pre-logic Script Code block
  • and the last piece in the expression box

Pre-logic Script Code:

""" input shape field: returns cumulative distance between points
dist_cumu(!Shape!)    #enter into the expression box""" 
x0 = 0.0;  y0 = 0.0;  distance = 0.0 
def dist_cumu(shape):
      global x0;  global y0;  global distance
      x = shape.firstpoint.X;  y = shape.firstpoint.Y
      if x0 == 0.0 and y0 == 0.0:
          x0 = x; y0 = y
      distance += math.sqrt((x - x0)**2 + (y - y0)**2)
      x0 = x;  y0 = y
      return distance

should do it... syntax highlighting isn't taking this morning

DanPatterson_Retired
MVP Emeritus
""" input shape field: returns cumulative distance between points dist_cumu(!Shape!) 
#enter into the expression box"""
x0 = 0.0;  y0 = 0.0;  distance = 0.0
def dist_cumu(shape):
      global x0;  global y0;  global distance
      x = shape.firstpoint.X;  y = shape.firstpoint.Y
      if x0 == 0.0 and y0 == 0.0:
          x0 = x; y0 = y
      distance += math.sqrt((x - x0)**2 + (y - y0)**2)
      x0 = x;  y0 = y
      return distance
0 Kudos