2

Is there a way/function to calculate the proportion of each raster cell covered by a polygon? The polygons are usually larger than single cells and the landscape I'm working on is pretty big. I'll like to do it without converting the raster into cell-polygons and st_union/st_join, but I'm not sure if it's possible.

The output I'm looking for is a raster with cell values showing the proportion of each cell covered by the polygons layer.

Guillermo.D
  • 399
  • 2
  • 14
  • Any computation will require knowing the coordinates of the intersection points, so no matter what you do, you have to feed the raster cell corner coords as well as the polygon vertex coords into the calculator. If your raster is uniform, then at least you know "ahead of time" all the corner coords and can loop on them. – Carl Witthoft Jun 01 '23 at 16:27
  • 1
    To be tested, but you might increase efficiency by first filtering cells that contain one or more polygon's vertex. – Josep Pueyo Jun 01 '23 at 17:28

1 Answers1

1

Thanks for the comments. At the end the terra::rasterize() function with the cover = T parameter applied on the polygons layer does exactly what I was looking for... and it's super fast.

I was able to keep it all on the "raster side" and avoid the more intense processing of vectorizing the raster template and doing intersects/spatial joins.

Guillermo.D
  • 399
  • 2
  • 14