distm: Distance matrix

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/distm.R

Description

Distance matrix of a set of points, or between two sets of points

Usage

1
distm(x, y, fun=distGeo)

Arguments

x

longitude/latitude of point(s). Can be a vector of two numbers, a matrix of 2 columns (first one is longitude, second is latitude) or a SpatialPoints* object

y

Same as x. If missing, y is the same as x

fun

A function to compute distances (e.g., distCosine or distGeo)

Value

Matrix of distances

Author(s)

Robert Hijmans

References

http://en.wikipedia.org/wiki/Great_circle_distance

See Also

distGeo, distCosine, distHaversine, distVincentySphere, distVincentyEllipsoid

Examples

1
2
3
4
xy <- rbind(c(0,0),c(90,90),c(10,10),c(-120,-45))
distm(xy)
xy2 <- rbind(c(0,0),c(10,-10))
distm(xy, xy2)

Example output

Loading required package: sp
         [,1]     [,2]     [,3]     [,4]
[1,]        0 10018754  1570278 12323603
[2,] 10018754        0  8905559 15028131
[3,]  1570278  8905559        0 13890254
[4,] 12323603 15028131 13890254        0
         [,1]     [,2]
[1,]        0  1570278
[2,] 10018754 11131949
[3,]  1570278  2226390
[4,] 12323603 12128822

geosphere documentation built on May 2, 2019, 5:16 p.m.