Thanks! It works with raster_1.6-22 and sp_0.9-72
The last 2 lines must be fun1 <- function(x,y) { x[y!=248 & y!=232] <- NA; return(x)} rc <- overlay(rNDVI, rSM, fun=fun1) Is it required to include datatype and/or format in overlay() to get the result (rc) written to disk and not fully loaded in RAM? Agus 2010/11/19 Robert J. Hijmans <r.hijm...@gmail.com>: > Hi Agus, > > Your example with overlay works for me. I think you need to update > 'raster' . In earlier versions many functions only worked for > RasterLayer objects, now most functions also support multi-layer > (RasterStack or RasterBrick) objects. > > Robert > > On Fri, Nov 19, 2010 at 8:50 AM, Agustin Lobo <alobolis...@gmail.com> wrote: >> Hi! >> >> I have to set as NA data in a 3D array (time series of images) >> according to values in another 3D array of Quality flags >> >> #Example >> NDVI = round(array(rnorm(5*5*3,180,10),dim=c(5,5,3))) >> SM = array(rep(248,5*5*3),dim=c(5,5,3)) >> SM[4,3:4,1:2] = 232 >> SM[2,3:4,1:2] = 243 >> SM[3,4,1:2] = 243 >> >> #The only valid data are the ones for which SM is either 232 or 248, so: >> NDVI[SM!=248] <- NA >> NDVI[SM!=232] <- NA >> #which is the same as >> NDVI[SM!=248 & SM!=232] <- NA >> >> #The problem is that what I really have are images 3697 columns x >> 1905 rows and 360 Bands (and even larger) , so I try package raster >> >> require(rgdal) >> require(raster) >> >> #First, I make fake data: >> rNDVI = stack(raster(NDVI[,,1]),raster(NDVI[,,2]),raster(NDVI[,,2])) >> rSM = stack(raster(SM[,,1]),raster(SM[,,2]),raster(SM[,,2])) >> >> fun <- function(x,y) { x[y!=248 & y!=232] <- NA; return(x)} >>> rc <- overlay(rNDVI, rSM, fun) >> Error in function (classes, fdef, mtable) : >> unable to find an inherited method for function "overlay", for >> signature "RasterStack", "RasterStack" >> Calls: overlay -> <Anonymous> >> >> #It seems that calc() must be used for stacks, but seems to me that calc() >> #only accepts one stack, not two. Maybe I should just stack both NDVI and SM? >> >> Thanks! >> Agus >> > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo