creates raster mask corresponding to the convex hull of xy positions
raster_chull_mask(xy, r)
a SpatRaster with 0 or 1
2 columns matrix or data.frame. xy positions
raster object. target raster
raster_xy_mask
# create raster
r <- terra::rast(extent = c(0, 40, 0, 40), resolution = 1, crs = "epsg:2154")
# xy positions
xy <- data.frame(
x = c(10, 20, 31.25, 15),
y = c(10, 20, 31.25, 25)
)
# compute mask
mask1 <- raster_chull_mask(xy, r)
# display binary raster
terra::plot(mask1)
graphics::points(xy)
Run the code above in your browser using DataLab