distFromPos: Distance matrix from position matrix

View source: R/utilityFunctions.R

distFromPosR Documentation

Distance matrix from position matrix

Description

Distance matrix from position matrix

Usage

distFromPos(
  pos,
  surface = "ellipsoid",
  units = c("km", "m", "miles", "nautical miles")
)

Arguments

pos

Number of sites by 2 matrix with positions of each site. If surface is 'ellipsoid' or 'sphere', then column 1 should be longitude and column 2 should be latitude. If surface is 'plane', column 1 can be x-position and column 2 y-position.

surface

Surface to calculate distances on. Either 'ellipsoid' (default), 'sphere', or 'plane'.

units

Units of return distance matrix. If surface is 'plane', then this argument is ignored and the return units will be the same as the pos units. Options are 'km' (kilometers, default), 'm' (meters), 'miles', and 'nautical miles'.

Value

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.

Note

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.

Examples

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

SMBC-NZP/MigConnectivity documentation built on March 26, 2024, 4:22 p.m.