pointDist: Calculate distance matrix between geographic points

View source: R/pointDist.r

pointDistR Documentation

Calculate distance matrix between geographic points

Description

This function calculates a distance matrix between points. It is similar to the dist() function except that it does its calculations in geographic space.

Usage

pointDist(x, y = NULL, distFunct = NULL, longLat = NULL, ...)

Arguments

x

A data frame, matrix, SpatialPoints, SpatialPointsDataFrame, or SpatVector object. If a data frame or matrix then the coordinate reference system is assumed to be unprojected (WGS84). Note that if you are using terra SpatVector objects, then the distance function in that package will be much faster for large sets of points.

y

If NULL then pairwise distances are calculated between all points in x. However, if y is a data frame, matrix, SpatialPoints, SpatialPointsDataFrame, or SpatVector object then distances are between all points in x and y.

distFunct

Either a function or NULL. If NULL then distCosineis used to calculate distances. More accurate distances can be obtained by using other functions (see distHaversine and related "dist" functions). Alternatively, a custom function can be used so long as its first argument is a 2-column numeric matrix with one row for the x- and y-coordinates of a single point and its second argument is a two-column numeric matrix with one or more rows of other points.

longLat

Two-element character list or two-element integer list. If x (and y) is a data frame then this should be a character list specifying the names of the fields in x or a two-element list of integers that correspond to longitude and latitude (in that order). For example, c('long', 'lat') or c(1, 2). If x (and y) is a matrix then this is a two-element list indicating the column numbers in x (and y) that represent longitude and latitude. For example, c(1, 2). If x is a SpatialPoints object then this argument is ignored.

...

Arguments to pass to distFunct.

Value

Matrix of values in units given by the coordinate reference system of x or in meters (if x is a matrix, data frame, or unprojected).

See Also

distCosine, pairDist, distance

Examples


set.seed(17)
# random points centered on long -90, lat 45
x <- cbind(rnorm(5, -90), rnorm(5, 45))
pointDist(x)


adamlilith/enmSdm documentation built on Jan. 6, 2023, 11 a.m.