dist_to_nearest {starsExtra} | R Documentation |
Calculate raster of distances to nearest feature
Description
Given a stars
raster and an sf
vector layer, returns a new raster with the distances of each cell centroid to the nearest feature in the vector layer.
Usage
dist_to_nearest(x, v, progress = TRUE)
Arguments
x |
A |
v |
An |
progress |
Display progress bar? The default is |
Value
A stars
raster with distances to nearest feature
Examples
# Sample 'sf' layer
x = st_point(c(0,0))
y = st_point(c(1,1))
x = st_sfc(x, y)
x = st_sf(x)
x = st_buffer(x, 0.5)
# Make grid
r = make_grid(x, res = 0.1, buffer = 0.5)
d = dist_to_nearest(r, x, progress = FALSE)
# Plot
plot(d, breaks = "equal", axes = TRUE, reset = FALSE)
plot(st_geometry(x), add = TRUE, pch = 4, cex = 3)
[Package starsExtra version 0.2.8 Index]