I have a municipality polygon that looks like this:
shp_muni
class : SpatVector
geometry : polygons
dimensions : 1, 1 (geometries, attributes)
extent : 5.08748, 5.467728, 52.43524, 52.69111 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84
names : PC4
type : <int>
values : 8244
I have a raster that covers the entire world with resolution of 0.25
class : SpatRaster
dimensions : 696, 1440, 1 (nrow, ncol, nlyr)
resolution : 0.25, 0.25 (x, y)
extent : -180, 180, -90, 84 (xmin, xmax, ymin, ymax)
coord. ref. : lon/lat WGS 84
source : memory
name : year_value
min value : 1
max value : 100
I want to calculate mean, max, and min of raster cells that fall within the municipality including the cells that intersect with the boundary of the polygon. I did this:
cells_score <- terra::extract(temp_rast, shp_muni, exact = T, cells = T, na.rm = TRUE, as.raster = F)
cells_score
ID year_value cell fraction
1 14 180741 0.24591428
1 14 180742 0.50551934
1 17 182181 0.03271280
1 16 182182 0.09146393
Using the above, I can calculate min(=14), max(=17) and mean (using the fraction as weights after re-normalising the fraction so that it adds up to 1). However, if I do the following, I get a different number for min:
terra::extract(temp_rast, shp_muni, "max", touches = T, na.rm = TRUE, as.raster = F)
ID year_value
1 17
terra::extract(temp_rast, shp_muni, "min", touches = T, na.rm = TRUE, as.raster = F)
ID year_value
1 0
Why I am getting different values using the two approaches?