Select to view content in your preferred language

Calculate the distance between two sequential points in EPSG 4326 (WGS84 Geographic)?

365
2
Jump to solution
10-11-2024 08:25 AM
Labels (2)
AustinLewis
Occasional Contributor

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
     

 

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
AustinLewis
Occasional Contributor

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

  

View solution in original post

0 Kudos
2 Replies
AustinLewis
Occasional Contributor

  I am also open to using Arcade or any other code solutions!

0 Kudos
AustinLewis
Occasional Contributor

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

  

0 Kudos