Calculate the distances between subsequent 2-D coordinates using Euclidean or Great Circle distance (WGS84 ellipsoid) methods.
Arguments
- x1
trip object, matrix of 2-columns, with x/y coordinates OR a vector of x start coordinates
- y1
vector of y start coordinates, if x1 is not a matrix
- x2
vector of x end coordinates, if x1 is not a matrix
- y2
vector of y end coordinates, if x1 is not a matrix
- longlat
if FALSE, Euclidean distance, if TRUE Great Circle distance
- prev
if TRUE and x1 is a trip, the return value has a padded end value (\"prev\"ious), rather than start (\"next\")
Details
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.
References
Original source taken from sp package, but now using Helmert from Karney (2013) see the geodist package.
Examples
d <- data.frame(x=1:10, y=rnorm(10), tms=Sys.time() + 1:10, id=gl(2, 5))
tr <- trip(d, c("tms", "id"))
#> Warning: input looks like longitude/latitude data, assuming +proj=longlat +datum=WGS84
## 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
trackDistance(tr)
#> 11 12 13 14 15 21 22 23
#> 0.0000 128.6882 139.8684 112.1488 185.7110 0.0000 139.8986 408.7523
#> 24 25
#> 175.4234 117.9707
## the default method does not know about the trips, so this is
##(n-1) distances between all points
trackDistance(coordinates(tr), longlat = FALSE)
#> 2 3 4 5 6 7 8 9
#> 1.158073 1.259577 1.007570 1.675502 1.000085 1.260053 3.694835 1.582369
#> 10
#> 1.060633
## we get NA at the start, end and at transitions between trips
angles <- trackAngle(tr)