distance-matrix-methods | R Documentation |
Methods to calculate distances between objects and to find the geographically nearest neighbor(s) between objects.
saveDistanceMatrix(dm, file)
readDistanceMatrix(file)
distance(x)
## S4 method for signature 'DistanceStation'
distance(x)
nearest(x, all, dm = NULL, n = 1, ...)
## S4 method for signature 'Station,Station'
nearest(x, all, dm = NULL, n = 1,
filter.fun = NULL, ...)
## S4 method for signature 'Station,missing'
nearest(x, all, dm = NULL, n = 1,
filter.fun = NULL, ...)
distanceMatrix(x, ...)
## S4 method for signature 'SpatialPoints'
distanceMatrix(x, ...)
## S4 method for signature 'Station'
distanceMatrix(x, ...)
dm |
The distance matrix. |
file |
the file to save to or read from |
x |
For |
all |
The possible nearest neighbors for |
n |
The number of nearest objects that should be returned. |
filter.fun |
A function returning a |
dm |
The distance matrix for the objects (generated if missing). |
nearest
calculates the nearest objects of all
in relation
to x
. The distance matrix can be supplied using the dm
parameter and can be calculated using distanceMatrix
. As this
computation is quite expensive the distance matrix can be saved and read
using saveDistanceMatrix
and readDistanceMatrix
.
nearest
returns the same class or a subclass of all
. The
returned vector or vectorized object is sorted by their distance to
x
. Additionally the distance can be obtained using distance
.
The distance is calculated using computations on an ellipsoid and the returned value is in meters.
For nearest
: a subset of all
orderd by their distance
to x
, enriched with an additional distance attribute.
For distanceMatrix
and readDistanceMatrix
: a distance
matrix of class dist
.
For distance
: a numeric vector containing the distance in meters.
endpoint <- example.endpoints()[2]
sta.all <- stations(endpoint)
station <- sample(sta.all, 1)
dm <- distanceMatrix(sta.all)
sta.near <- nearest(station, stations = sta.all, dm = dm, n = 5)
distance(sta.near)
## Not run:
saveDistanceMatrix(dm, 'distance_matrix.rds')
sta.near <- nearest(station, stations = sta.all,
dm = readDistanceMatrix('distance_matrix.rds'))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.