Learn R Programming

trip (version 1.1-21)

trackDistance: Determine distances along a track

Description

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

Usage

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

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\")

Value

Vector of distances between coordinates.

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 but now implements the sp gcdist source directly in R.

References

Original source taken from sp package.

Examples

Run this code
## Continuing the example from '?"trip-methods"':
utils::example("trip-methods", package="trip",
               ask=FALSE, echo=FALSE)

 ## 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)

## 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

 ## Not run: 
#  require(rgdal)
#  trackAngle(tr)
#  ## End(Not run)

Run the code above in your browser using DataLab