Closed imprompt closed 2 years ago
Thank you very much for reporting this and for the good example. I now get:
extract(r, poly, exact=FALSE, weights=TRUE, normalizeWeights=F, cellnumbers=T, df=T)
# ID cell layer weight
#X 1 1 10 0.01
#X.1 1 2 20 0.06
#X.2 1 3 30 0.07
#X.3 1 4 40 0.42
#layer 2 2 20 0.01
#layer.1 3 1 10 0.04
extract(r, poly, exact=TRUE, weights=TRUE, normalizeWeights=F, cellnumbers=T, df=T)
# ID cell layer weight
#1 1 1 10 0.01
#2 1 2 20 0.06
#3 1 3 30 0.07
#4 1 4 40 0.42
#5 2 2 20 0.01
#6 3 1 10 0.04
Which is the same as what I get with "terra" (the replacement of "raster"):
library(terra)
x <- rast(r)
v <- vect(poly)
extract(x, v, exact=TRUE, cell=TRUE)
# ID layer cell fraction
#1 1 10 1 0.01
#2 1 20 2 0.06
#3 1 30 3 0.07
#4 1 40 4 0.42
#5 2 20 2 0.01
#6 3 10 1 0.04
In the following example, the cell numbers output by the 2nd extract call (exact=T) contain an error. The first call to extract (exact=F) looks correct.