I have raster (1300 by 1400 cells) with 3 layers and I would like to make focal calculations using data from all 3 layers. For example one of the layers is land cover map and I would like to use in calculations only these pixels in the focal window that have the same land cover type as the central pixel of the window. I suppose this is not possible with the “focal” function in raster package that is why I tried to extract the data from the 3 layers for every moving window extent by the “getValuesFocal”. After doing this my idea was to loop through the rows of the array resulting from “getValuesFocal”. However the array is very big and do not fit the memory so I get error message:
dataraster <- stack(classification, layer2, layer3)
data <- getValuesFocal(dataraster, ngb=11, names=TRUE, padValue=NA, array=TRUE)
Error: cannot allocate vector of size 1.7 Gb
In addition: Warning messages:
1: In `rownames<-`(`*tmp*`, value = 1:1879200) :
Reached total allocation of 8008Mb: see help(memory.size)
I know that packages like ff and bigmemory allow for handling big datasets but how can I use them when my dataset cannot be initially created. I am using 64-bit R and have 8GB RAM. Is there way to write the result of “getValuesFocal” in a file? I will be grateful for any help.