Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Regarding yesterday's question about how to speed up band math in the R 'raster' package, would it be the same to use overlay to calculate NDVI instead of calc? If that's not the case, what's the hidden advantage of calc with that particular kind of operations?

Cheers, Florian

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

I would expect overlay to be a little slower, but perhaps not much, and the code is perhaps more elegant:

f_NDVI2 <- function(x, y) {
  (x-y)/(x+y)
}

NDVI <- overlay(raster[[60]], raster[[75]], fun=f_NDVI2)
share|improve this answer
add comment

In manual to 'raster' package it is clearly described in which cases one should use calc, overlay or simple band math.calc is used for operation with a single Raster object and overlay is used when calculations involve several Raster objects (or when dataset is too large to be loaded into memory). In my case (you linked to my question) there was only one Raster object of a small size with many bands in it, so there was no point to use overlay. And there is one more thing to take into account: can you imagine how would overlay function look like to operate over only 2 bands from 100 bands Raster?

share|improve this answer
    
See @RobertH 's solution. That's how it would look like ;-) –  flowla May 2 '13 at 7:11
1  
@flowia, nope, he used 2 rasters substructed from initial, not the bands of the given raster. –  SS_Rebelious May 3 '13 at 6:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.