rDistance: Calculate the distance map for a raster

Description Usage Arguments Details Value References See Also Examples

View source: R/modify.operators.R

Description

The distance map of a binarised raster contains the distance of each background cell to the nearest foreground cell.

Usage

1
rDistance(obj, method = "euclidean")

Arguments

obj

[RasterLayer(1)]
The object to modify.

method

[character(1)]
the distance measure to be calculated. Either "euclidean" (default), "manhatten" or "chessboard" distance.

Details

In contrast to distance, the distance values here do not warp around the boundaries of the map.

Value

A RasterLayer of the same dimension as obj, where the value of the background cells has been replaced with the distance to the nearest foreground cell.

References

Meijster, A., Roerdink, J.B.T.M., Hesselink, W.H., 2000. A general algorithm for computing distance transforms in linear time, in: Goutsias, J., Vincent, L., Bloomberg, D.S. (Eds.), Mathematical Morphology and Its Applications to Image and Signal Processing. Springer, pp. 331–340.

See Also

Other operators to modify cell values: rBinarise, rCategorise, rFillNA, rOffset, rPermute, rRange, rSubstitute

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
input <- rtRasters$continuous

# the different distance metrics
binarised <- rBinarise(input, thresh = 40)
disEuc <- rDistance(binarised)
disMan <- rDistance(binarised, method = "manhattan")
disChb <- rDistance(binarised, method = "chessboard")

distances <- raster::stack(binarised, disEuc, disMan, disChb)
visualise(distances)

# calculate distance from edge to patch interior
inverted <- rPermute(binarised)
visualise(rDistance(inverted))

EhrmannS/rasterTools documentation built on Sept. 4, 2019, 10:34 a.m.