View source: R/utilityFunctions.R
distFromPos | R Documentation |
Distance matrix from position matrix
distFromPos(
pos,
surface = "ellipsoid",
units = c("km", "m", "miles", "nautical miles")
)
pos |
Number of sites by 2 matrix with positions of each site. If
|
surface |
Surface to calculate distances on. Either 'ellipsoid' (default), 'sphere', or 'plane'. |
units |
Units of return distance matrix. If |
Square matrix of distances between sites. If surface
is
'ellipsoid' or 'sphere', then argument units
will determine units;
if surface
is 'plane', the units will be the same as the pos
units.
In version 0.4.3 we switched package dependencies from geosphere
to geodist
. As a result, spherical distances (and possibly
ellipsoid distances) may differ slightly from those calculated with earlier
versions of our package.
nBreeding <- 100
nWintering <- 100
breedingPos <- matrix(c(rep(seq(-99, -81, 2), each = sqrt(nBreeding)),
rep(seq(49, 31, -2), sqrt(nBreeding))),
nBreeding, 2)
winteringPos <- matrix(c(rep(seq(-79, -61, 2), each = sqrt(nWintering)),
rep(seq(9, -9, -2), sqrt(nWintering))),
nWintering, 2)
head(breedingPos)
tail(breedingPos)
head(winteringPos)
tail(winteringPos)
breedDist <- distFromPos(breedingPos, 'ellipsoid')
nonbreedDist <- distFromPos(winteringPos, 'ellipsoid')
breedDist[1:12, 1:12]
breedDist[1:12, c(1,91,100)]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.