get.distances.prepaired: Find distances between points, for pairs of points already...

View source: R/get.distances.prepaired.R

get.distances.prepairedR Documentation

Find distances between points, for pairs of points already organized as pairs.

Description

get.distances.prepaired returns all the distances between each specified pair of points.

Usage

get.distances.prepaired(pts)

Arguments

pts

A matrix or data.frame that has columns names 'fromlon', 'fromlat', 'tolon', 'tolat' with datum=WGS84 assumed.

Details

May need to fix cases where only a single row is input. This function returns a matrix or vector of distances, between points specified as pairs of lat/lon values. Points are specified using latitude and longitude in decimal degrees. Relies on the sp package for the spDistsN1 and SpatialPoints functions.

Value

Returns a vector of distances as numbers, in kilometers. Each element corresponds to one row in pts.

See Also

get.distances.all for a useful general function, get.distances for get.distances() which allows you to specify a search radius and get distances only within that radius which can be faster, get.nearest which finds the distance to the single nearest point within a specified search radius instead of all topoints, and proxistat which calculates a proximity score for each spatial unit based on distances to nearby points.

Examples

test.from <- structure(list(fromlat = c(38.9567309094, 38.9507043428, 38.0), 
 fromlon = c(-77.0896572305, -77.0896199948, -77.0)), 
 .Names = c("lat", "lon"), row.names = c("one", "two", "three"), class = "data.frame")
test.to <- structure(list(tolat = c(38.9575019287, 38.9507043428, 38.9514152435), 
 tolon = c(-77.0892818598, -77.0896199948, -77.0972395245)), 
 .Names = c("lat", "lon"), class = "data.frame", row.names = c("a", "b", "c"))
get.distances.prepaired(data.frame(
  fromlat=test.from$lat, fromlon=test.from$lon, tolat=test.to$lat, tolon=test.to$lon)
)

ejanalysis/proxistat documentation built on April 2, 2024, 10:13 a.m.