2

I'm using the LANDSAT/LC08/C01/T1_RT_TOA dataset. Using this I want to calculate the RVI of a region. This is done by dividing the Near Infrared band (B5 in the dataset) by the Red band (B4 in the dataset). I do this by firstly defining both bands as separate variables namely nir and red. Using this I do the following:

var rvi = nir.divide(red)

When doing this is keeps giving me the error:

nir.divide is not a function

Is there any other way to do this bandmath?

https://code.earthengine.google.com/fabbbc2aa3288e6b8e1daad980d66655

0
2

nir is an image collection, and you cannot do band math directly with one.

Depending of what you're trying to do, you either turn the collection it into an image, for instance by taking the median value, and do the calculations on that image:

var mosaic = dataset.median()
var nir = mosaic.select('B5')
var red = mosaic.select('B4')
var rvi = mosaic.divide(red)

Or you do the calculations on every image in the collection:

var rviCollection = dataset.map(function (image) {
  var nir = image.select('B5')
  var red = image.select('B4')
  var rvi = nir.divide(red).rename('rvi')
  return rvi
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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