Search code examples
rstackoverlayraster

Overlay Many ASCII layers in Raster Package R


I have 120 species distribution maps as .asc files which I have stacked using the r package "raster". I would like to add all of these layers to produce a richness map for a large spatial extent. I have tried to use the overlay function to simply sum all of the asc files into a single map but I an error. Does anyone have any suggestions on how to correct this. Thanks in advance!

SDM.Stack<-stack (files)

#Overlay Function 
SDM.Overlay.Map1<-overlay (SDM.Stack, fun=function(x,y){return(x+y)}, unstack=FALSE)

#Error in .overlayList(x, fun = fun, filename = filename, ...) : 
  cannot use this formula, probably because it is not vectorized

Solution

  • If you just adding the values across the layers for each cell.

    calc(SDM.Stack, sum)