I am using R.
I have a polygon v that covers multiple raster cells in raster z.
How could I calculate what proportion of the polygon is covered by each category in the raster?
I read a solution on Unexpected behaviour of extract function in the raster package which suggested rasterizing the polygon, polygonizing the raster, and then using terra::extract. This may work for the reproducible example here, but I'm looking for a solution that will scale to work with 2500 polygons and a raster with 100,000 rows and 100,000 columns.
I have assumed that the above solution would not work well with such a large dataset.
library(terra) f <- system.file("ex/lux.shp", package="terra") v <- vect(f) v <- v[1,] z <- rast(v, resolution=.09, names="test") values(z) <- 1:ncell(z) levels(z) <- 0:ncell(z) plot(z) plot(v, add = T)