nearExtract: Add a circular buffer to a point until a valid raster value...

View source: R/nearExtract.R

nearExtractR Documentation

Add a circular buffer to a point until a valid raster value is extracted

Description

Add a circular buffer to a point until a valid raster value is extracted

Usage

nearExtract(x, y, fun = mean, b = NULL, bstep = NULL, ...)

Arguments

x

raster layer

y

sf points object

b

optional, inital buffer radius, or vector of buffer radii in metres

bstep

optional, incremental buffer radius increase in metres

...

additional arguments passed to terra::extract()

Value

A dataframe as returned by terra::extract() with an additional column b, which specifies the radius of the buffer necessary to intersect a valid raster pixel.

Examples

r <- rast(nrows = 100, ncols = 100, xmin = 0, xmax = 1, ymin = 0, ymax = 1)
values(r) <- seq(0, 100, length.out = 100*100)
p <- data.frame(
  id = LETTERS[1:10],
  lon = seq(-0.5, 1.5, length.out = 10),
  lat = seq(-0.5, 1.5, length.out = 10))
psf <- st_as_sf(p, coords = c("lon", "lat"), crs = 4326)
crs(r) <- crs(psf)

nearExtract(r, psf)
nearExtract(r, psf, b = 1000)
nearExtract(r, psf, b = 1000, bstep = 10000)
nearExtract(r, psf, bstep = 10000)
nearExtract(r, psf, fun = min)
nearExtract(r, psf, fun = min, method="bilinear")


johngodlee/JLGMisc documentation built on July 17, 2025, 3:09 a.m.