I need to get the value of a pixel (I have coordinates for this pixels) and its 8 surrounding pixel from the pixel/point. I am working with NetCDF files. I am working with R.
This is my code till now:
nc <- nc_open(file, readunlim=FALSE)
mylon <- ncvar_get(nc,"lon")
mylat <- ncvar_get(nc,"lat")
my coordinates in real-world: lat 52.5935 lon 18.4467
lon.coor <- mylon[which.min(abs(mylon-18.4467))]
var <- nc[lon.coor, lat.coor, ]
In var are the values for my point. But I also need the values of the 8 surrounding pixels to get an average.