I have an imported version of a GPX file plotting the route of a trail. I also have a list of coordinates for waypoints along the route. I am trying to calculate how far along the route each waypoint is.
After importing and formatting the lat/long information, I use the following code:
trail = GeoPosition /@ data[[All, 1]]
Then I bring in the waypoint:
waypoint
= GeoPosition[{34.56544401, -77.90251801}]`
I can find the first point on the route with this:
start = First[trail]
And find the straight line distance with this:
GeoDistance[waypoint, start]
But how do I have Mathematica measure that distance along the path instead of straight distance?
Additionally, I have found I can find the closest route point with this:
GeoNearest[trail, waypoint]
And I can find out far the waypoint is from one of the route points with this:
Min[GeoDistance[randomblaze, trail]]
In looking for possible solutions, I found this example on the Wolfram Community and he does some cool stuff using Accumulate
as a way of calculating overall distance. I could use that function combined with finding the nearest route point and have the answer, but that won't always work. You see there are gaps in some of the GPX route coordinates where at times there is up to half a mile between coordinates. I have cases where waypoints are returning the same route point as closest because they really are the closest in the dataset, even though the waypoints themselves are seperated by some distances. In cases like that, my distance calculations could be off by a pretty substantial bit.
Is there an another way to do what I am trying to do, or am I stuck with either the drawbacks of finding the distances to the nearest route point or manually entering the waypoint coordinates into the appropriate spot within the route points?