Skip to content
Prev 23805 / 29559 Next

Needing to speed up a process involving calc() and cover() raster functions

so, essentially what you want is pixels which have NAs throughout all 
layers (i.e. are above the thresholds) set to NA and the rest set to 1.
although, I don't quite see the use-case, but this is how you could do 
it a little faster:

library(Rcpp) ## You need RcppArmadillo also installed
cppFunction("
                 arma::vec allNA(arma::mat x, arma::vec tr){
                 arma::vec out(x.n_rows);
                 out.fill(NA_REAL);
                  for(int i = 0; i < tr.n_elem; i++) {
                        out.elem(find(x.col(i) < tr(i))).ones();
                 }
                 return out;
                 }
                 ", depends = "RcppArmadillo")


r <- calc(classified, function(x){allNA(x,tr=threshs)}, forcefun=T)


-
Benjamin
On 23.12.2015 15:04, Mathieu Rajerison wrote: