You can construct polygons like the ones shown in your image by converting your points into an sf
object and then using st_buffer
. To compute the fraction of each grid cell that is covered by the polygons, you can use exactextractr::coverage_fraction
. It's important to first dissolve the buffered points into a single polygon using st_union
, so that areas covered by more than one tree aren't double-counted. Here's an example using constructed data:
library(sf)
library(exactextractr)
library(raster)
set.seed(123)
n_trees <- 50
trees <- data.frame(x_cor=runif(n_trees, min=0, max=50),
y_cor=runif(n_trees, min=0, max=50),
tree_crown=runif(n_trees, min=0.5, max=5))
grid <- raster(xmn=0, xmx=50, ymn=0, ymx=50, res=10, crs=NA)
canopy <- st_as_sf(trees, coords=c('x_cor', 'y_cor')) %>%
st_buffer(dist=.$tree_crown) %>%
st_union()
pct_cov <- coverage_fraction(grid, canopy)[[1]]
plot(pct_cov)
plot(st_geometry(canopy), add=TRUE)
