1

I'm trying to apply a rule to NOOA NDVI the already classified region to only display dense vegetation areas but it's saying NDVI is not a function.

Here is the code:

//collecting data using ndvi
var good = ee.ImageCollection('NOAA/CDR/AVHRR/NDVI/V5')
                  .filter(ee.Filter.date('2018-05-01', '2018-06-01'))
                  //.median()
                  //.good.lt(0.27).and(good.gt(0.18))
                  //.map(function(good){return good.lt(0.18).and(good.gt(0.27))})
                  .map(function(good){return good.clip(roi)});

Map.setCenter (37.577717495842506,0.3597340638009545,12);
var ndvi = good.select('NDVI')
var ndvi2 =ndvi
          .where(ndvi.gt(0.27).and(ndvi.lte(0.36)), 4)
          .where(ndvi.gt(0.36).and(ndvi.lte(0.74)), 5)
var ndvi2 = ndvi2.clip(roi);

The error shows this

Line 14: ndvi.gt is not a function

1 Answer 1

1

You are applying an image function (.gt()) to an image collection. So you have to select an image, or map the logic in a function over the entire imageCollection. Here is the solution to applying it to an image:

var ndviImage = ndvi.first() // now it is an image

var ndvi2 =ndviImage
          .where(ndviImage.gt(0.27).and(ndviImage.lte(0.36)), 4)
          .where(ndviImage.gt(0.36).and(ndviImage.lte(0.74)), 5)

https://code.earthengine.google.com/461a18758e1ee190a0b9449e0a6e3ffc

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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