Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 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) {

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

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 ;-) – fdetsch May 2 '13 at 7:11
@flowia, nope, he used 2 rasters substructed from initial, not the bands of the given raster. – SS_Rebelious May 3 '13 at 6:43

Your Answer


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.