I am working in R and want to calculate the value of a polygon. The value should consider the weights on each intersecting cell. When I try to run the "extract" function with a sample raster and polygon I get different weights that the ones I calculate manually, resulting in different final value.
Here is my sample code:
r <- raster(nrow=2, ncol=2, xmn=-180, xmx=60, ymn=-30, ymx=90) r <- c(1,2,4,5) s <- raster(xmn=-120, xmx=-40, ymn=20, ymx=60, nrow=1, ncol=1) s.pl <- as(s, 'SpatialPolygons') w <- raster::extract(r, s.pl, method="simple",weights=T, normalizeWeights=F) mean.value <- raster::extract(r, s.pl, method="simple",weights=T, fun=mean)
The value I get is 2.14 but according to the actual weights of the cells it should be 2. Can it be because of the projection that is in lat/lon? But even when I assign projection in meters I have the same result. How can I get the value of 2 that I am interested in? I also tried with "resample" function but I get different results as well.
My final target is to create a new raster with different resolution and extents from the original one and assign the values based on the weights of the cells of the original raster that intersect with the cells of the new raster. But it seems that neither resample nor extract functions give the expected outcome.
Hope my question makes sense.