View source: R/get.distances.prepaired.R
get.distances.prepaired | R Documentation |
get.distances.prepaired
returns all the distances between each specified pair of points.
get.distances.prepaired(pts)
pts |
A matrix or data.frame that has columns names 'fromlon', 'fromlat', 'tolon', 'tolat' with datum=WGS84 assumed. |
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.
Returns a vector of distances as numbers, in kilometers. Each element corresponds to one row in pts.
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.
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)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.