I have multiple rasters in a folder. I need to extract mean of each of these rasters over a pixel (I do points and note polygons).
It says extract can be used for points, lines and polygons too. BUT for the function (fun = mean). I would like to know by this method, if I must obligatorily do fun='mean' ? Because I have points in my shapefile and not polygon... ? The points are on each pixel of my raster
Can you help me please ?Thank you
It's here the code I want to do :
test <- list.files("my_path", pattern = "\\.tif$", full=TRUE)
STACK <- stack(ff)
SHAPE <- shapefile("my_path/supplimentY.shp")
extr <- extract(STACK, SHAPE, *fun='mean'*, na.rm=TRUE, df=TRUE)
From the extract
example:
library(raster)
r <- raster(ncol=36, nrow=18, vals=1:(18*36))
###############################
# extract values with points
###############################
xy <- cbind(-50, seq(-80, 80, by=20))
sp <- SpatialPoints(xy)
raster::extract(r, sp)
and from the documentation:
If y represents points, fun is only used when a buffer is used
so you should not supply a function to the fun
argument since there are no values to summarize, because points fall in one single pixel of each layer in the stack.
If you want a summary of the values near points, you can specify the radius of a buffer around each point from which to extract cell values with the buffer
argument. Or you can change the method
argument to 'bilinear', in this way the returned values are interpolated from the values of the four nearest raster cells.