Computes, for every cell of a .vec raster, the straight-line Euclidean
distance to the nearest feature cell, in CRS units. Feature cells are the
non-NA cells by default, or the cells whose value is in target. This is the
raster proximity / Euclidean-distance staple, the distance companion to
rasterize().
Usage
proximity(
x,
target = NULL,
band = 1L,
path = NULL,
dtype = "f32",
compression = c("fast", "balanced", "max")
)Arguments
- x
A
vectra_raster(fromvec_open_raster()) or a path to a.vecraster.- target
Optional numeric vector of feature values. When
NULL(default) every non-NA cell is a feature; otherwise a cell is a feature when its value is intarget.- band
Band to read (1-based). Default 1.
- path
Optional output
.vecpath. When given the result is streamed to disk and the openedvec_open_raster()handle is returned invisibly; whenNULLthe result is returned as an in-memory matrix.- dtype
Storage dtype for
.vecoutput (seevec_write_raster()). Default"f32".- compression
Compression effort for
.vecoutput. Default"fast".
Value
When path is NULL, a numeric matrix (row 1 northmost) carrying
gt, extent, and crs attributes, with distance in CRS units and NA
where the raster holds no feature anywhere. When path is given, the
written vectra_raster handle (invisibly).
Details
The exact Euclidean distance transform is separable (Felzenszwalb and Huttenlocher 2012): a one-dimensional lower-envelope-of-parabolas transform along the rows, then the same transform along the columns, each linear in the line length and each line independent. vectra runs it as four streamed passes over tile-row strips, with an out-of-core transpose between the row pass and the column pass, so the whole grid is never resident. The row pass scales squared distances by the x resolution and the column pass by the y resolution, so the result is exact on anisotropic (non-square) cells. This places proximity on the sort / partition tier of the spatial toolbox.
Distances are straight-line Euclidean in the raster CRS units. Cost-distance,
which accumulates a per-cell friction along the path, is a global
shortest-path problem and stays resident: collect() the raster and run a
resident solver for that.
See also
rasterize() to build a raster from streamed points, mask() to
clip a raster to a polygon layer.