distance-matrix-methods: Distance matrix methods

distance-matrix-methodsR Documentation

Distance matrix methods

Description

Methods to calculate distances between objects and to find the geographically nearest neighbor(s) between objects.

Usage

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, ...)

Arguments

dm

The distance matrix.

file

the file to save to or read from

x

For distanceMatrix: The object to create a distance matrix for.
For nearest: the object to calculate the nearest neighbors for.

all

The possible nearest neighbors for x. For the Station method, all can be omitted. In that case, all will default to stations(endpoint(x)).

n

The number of nearest objects that should be returned.

filter.fun

A function returning a logical vector to subset all and to allow only specific elements of all to be considered for the calculation.

dm

The distance matrix for the objects (generated if missing).

Details

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.

Value

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.

Examples

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)

52North/sensorweb4R documentation built on Oct. 14, 2024, 7:24 p.m.