trackDistance: Determine distances along a track

View source: R/distance.R

trackDistanceR Documentation

Determine distances along a track


Calculate the distances between subsequent 2-D coordinates using Euclidean or Great Circle distance (WGS84 ellipsoid) methods.


trackDistance(x1, y1, x2, y2, longlat = TRUE, prev = FALSE)



trip object, matrix of 2-columns, with x/y coordinates OR a vector of x start coordinates


vector of y start coordinates, if x1 is not a matrix


vector of x end coordinates, if x1 is not a matrix


vector of y end coordinates, if x1 is not a matrix


if FALSE, Euclidean distance, if TRUE Great Circle distance


if TRUE and x1 is a trip, the return value has a padded end value (\"prev\"ious), rather than start (\"next\")


If x1 is a trip object, arguments x2, x3, y2 are ignored and the return result has an extra element for the start point of each individual trip, with value 0.0.

The prev argument is ignore unless x1 is a trip.

Distance values are in the units of the input coordinate system when longlat is FALSE, and in kilometres when longlat is TRUE.

This originally used spDistsN1, then implemented the sp gcdist source directly in R, and now uses geodist.

Please see the traipse package for a more modern approach.


Vector of distances between coordinates.


Original source taken from sp package, but now using Helmert from Karney (2013) see the geodist package.


 d <- data.frame(x=1:10, y=rnorm(10), tms=Sys.time() + 1:10, id=gl(2, 5))
 tr <- trip(d, c("tms", "id"))

 ## the method knows this is a trip, so there is a distance for every
 ## point, including 0s as the start and at transitions between
 ## individual trips

## the default method does not know about the trips, so this is
##(n-1) distances between all points
trackDistance(coordinates(tr), longlat = FALSE)

## we get NA at the start, end and at transitions between trips

 angles <- trackAngle(tr)

trip documentation built on July 9, 2023, 7:29 p.m.