Learn R Programming

MigConnectivity (version 0.4.7)

distFromPos: Distance matrix from position matrix

Description

Distance matrix from position matrix

Usage

distFromPos(
  pos,
  surface = "ellipsoid",
  units = c("km", "m", "miles", "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.

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'.

Examples

Run this code
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)]

Run the code above in your browser using DataLab