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

Reply via email to