Learn R Programming

raster (version 1.8-3)

pointDistance: Distance between points

Description

Calculate the geographic distance between two (sets of) points on a sphere (latlong=TRUE) or on a plane (latlong=FALSE).

Usage

pointDistance(p1, p2, longlat, ...)

Arguments

p1
x and y coordinate of first (set of) point(s), either as c(x, y), matrix(ncol=2), or SpatialPoints*.
p2
x and y coordinate of second (set of) second point(s). Like p1. If p1 and p2 are both matrices they should have the same number of rows. If this argument is missing, a distance matrix is computed for p1
longlat
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 longlat=TRUE Default is r=6378137

Value

  • A single value or a vector of values giving the distance in meters (longlat=TRUE) or map-units (for instance, meters in the case of UTM) If p2 is missing, a distance matrix is returned

See Also

distanceFromPoints, distance, gridDistance, spDistsN1

Examples

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

Run the code above in your browser using DataLab