Tim, here is an an approach: library(raster) b <- brick(system.file("external/rlogo.grd", package="raster")) p <- SpatialPoints(cbind(sample(77,10), sample(77,10)))
methods <- c("bilinear","simple","bilinear") k <- methods == "simple" x1 <- extract(b[[which(k), drop=F]], p) x2 <- extract(b[[which(!k), drop=F]], p, method='bilinear') x <- cbind(x1, x2) x <- x[, names(b)] Robert On Wed, Jul 20, 2016 at 11:04 AM, Howard, Tim G (DEC) <tim.how...@dec.ny.gov> wrote: > Hi all, > I have a raster brick for which I'd like to extract data from each layer to a > point dataset, but I'd like to use method="simple" for some of the layers and > method="bilinear" for others. > > It looks like the call to extract won't take a vector for method like this: > > x <- extract(myBrick, mySpatialPoints, > method=c("simple","bilinear","bilinear")) > > my ugly hack is to loop it like this: > > listOfMethods <- c("simple","bilinear","bilinear") > > for(k in 1:nrow(listOfMethods)){ > x <- extract(myBrick [[k]], mySpatialPoints, method= listOfMethods > [[k]], sp=TRUE) > if(k == 1){ > y <- x > } else { > layerName <- names(x@data)[ncol(x@data)] > y@data <- cbind(y@data, x@data[,layerName]) > names(y@data)[length(names(y@data))] <- layerName > } > } > > > Any suggestions for a better approach? > > Aside: Note the myBrick[[k]] syntax (which is pretty fast!). I spent a while > trying to use layer=1, nl=1 in the call like this: > > x <- extract(myBrick, mySpatialPoints, layer=k, nl=1, method= listOfMethods > [[k]], sp=TRUE) > > but that consistently resulted in this error: > > Error in cvv[cells, ] : incorrect number of dimensions > > Thanks in advance, > Tim > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo