I have a data frame in r with x and y coordinates and each point has a circumference (tree_crown) around it. I'm wanting to build a raster file that each cell would have a value equal to the percent of the area being covered by the points (and the area of the circles around them). The x and y range is from 0 to 5147.815, and I'm wanting the resolution to be 1x1

My data looks like this: enter image description here

Here is the idea behind the output:

enter image description here

1 Answer 1


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:



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) %>%

pct_cov <- coverage_fraction(grid, canopy)[[1]]

plot(st_geometry(canopy), add=TRUE)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.