Distance between points
Calculate the geographic distance between two (sets of) points on a sphere (
longlat=TRUE) or on a plane (
pointDistance(p1, p2, longlat, ...)
- x and y coordinate of first (set of) point(s), either as c(x, y), matrix(ncol=2), or SpatialPoints*.
- x and y coordinate of second (set of) second point(s) (like for
p1). If this argument is missing, a distance matrix is computed for
- Logical. If
TRUE, coordinates should be in degrees; else they should represent planar ('Euclidean') space (e.g. units of meters)
- Additional arguments. Can be used to set the radius,
r, of the world (modeled as a sphere), when
- A single value, or a vector, or matrix of values giving the distance in meters (longlat=TRUE) or map-units (for instance, meters in the case of UTM)
p2is missing, a distance matrix is returned
a <- cbind(c(1,5,55,31),c(3,7,20,22)) b <- cbind(c(4,2,8,65),c(50,-90,20,32)) pointDistance(c(0, 0), c(1, 1), longlat=FALSE) pointDistance(c(0, 0), c(1, 1), longlat=TRUE) pointDistance(c(0, 0), a, longlat=TRUE) pointDistance(a, b, longlat=TRUE) #Make a distance matrix dst <- pointDistance(a, longlat=TRUE) # coerce to dist object dst <- as.dist(dst)
Looks like there are no examples yet.