Hello,
I have a feature class of points representing positions that are ordered in such that they are chronological. The feature class is in WGS 84 geographic as it is part of a larger global dataset. I am trying to calculate the geodesic distance between each point and the previous point in the field calculator. My problem is all the tools I can find/think (ex. point.distanceTo()) of are only appropriate for a planar projected dataset. Does anyone now a way of doing this? Eventually, I will use this distance to calculate speed.
What I have now would would for a projected dataset. I will show that below.
# In the field calculator
distance(!Shape!)
# In the code block
i=0
def distance(shape):
global prev_point
global i
point = arcpy.PointGeometry(shape.getPart(0))
if i > 0:
distance = point.distanceTo(prev_point)
else:
distance = 0
i+=1
prev_point = point
return distance
Solved! Go to Solution.
I have found my issue. I needed specify the spatial reference frame when generating my point object. Additionally, I used "angleAndDistanceTo() instead of distanceTo(), as it has the option of using the 'GEODESIC' method. I believed I used something like the code below.
# In the field calculator
distance(!Shape!)
# In the code block
i=0
def distance(shape):
global prev_point
global i
spref = arcpy.SpatialReference(3426)
point = arcpy.PointGeometry(shape.getPart(0),spref)
if i > 0:
angle, distance = point.angleAndDistanceTo(prev_point,'GEODESIC')
else:
distance = 0
i+=1
prev_point = point
return distance
I am also open to using Arcade or any other code solutions!
I have found my issue. I needed specify the spatial reference frame when generating my point object. Additionally, I used "angleAndDistanceTo() instead of distanceTo(), as it has the option of using the 'GEODESIC' method. I believed I used something like the code below.
# In the field calculator
distance(!Shape!)
# In the code block
i=0
def distance(shape):
global prev_point
global i
spref = arcpy.SpatialReference(3426)
point = arcpy.PointGeometry(shape.getPart(0),spref)
if i > 0:
angle, distance = point.angleAndDistanceTo(prev_point,'GEODESIC')
else:
distance = 0
i+=1
prev_point = point
return distance