1

I just perform a NDVI classification, and I want to know if I can plot or display the values of the NDVI lower than 0.8, or within a range for example from 0.3 to 0.5 and the rest of values in black or just not to plot them.

Here is part of my code:

//cargar coleccion de landsat
///////////////////////////////////////////////////////////////
var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')


//geometry with the AOI 
var roi = geometry;

//filtrar la imagen de acuerdo a la cobertura de nubes en el poligono
////////////////////////////////////////////////////////////////////
var l8f = l8.filterBounds(roi);

var withCloudiness = l8f.map(function(img_zone) {
  var cloud = ee.Algorithms.Landsat.simpleCloudScore(img_zone).select('cloud');
  var cloudiness = cloud.reduceRegion({
    reducer: 'mean', 
    geometry: roi, 
    scale: 30,
  });
  return img_zone.set(cloudiness);
});

var filteredCollection = withCloudiness.filter(ee.Filter.lt('cloud', 10));


var image = ee.Image(filteredCollection.filterBounds(roi)
    .filterDate('2017-03-30', '2017-07-30')
    .sort('CLOUD_COVER')
    .first());



var red = image.select('B4');

//infrarrojo cercano
var NIR = image.select('B5')


var nvdi = (NIR.subtract(red)).divide(NIR.add(red)).rename('NDVI');


Map.addLayer(nvdi,{min: -1, max: 1},'ndvi_rice_1')

2 Answers 2

0

Not sure if this is the most direct way or not, but ee.Image has built-in filtering methods (less than [lt], greater than [gt], etc.). They return a boolean which you can multiply against your original image:

var nvdi = (NIR.subtract(red)).divide(NIR.add(red)).rename('NDVI');
var filtered = nvdi.gt(0.75); // boolean (0,1) where nvdi > 0.75
var multiplied = nvdi.multiply(filtered); // multiply to set <= 0.75 to 0
Map.addLayer(multiplied,{min: -1, max: 1},'ndvi_rice_1'); // plot
1
  • This seems to work well, just to tell you all, i will change the code to plot only the values between the selected range. Once i have it, i will put the code, here in the comments. thank you. Commented Jul 8, 2019 at 20:10
0

You can simply use .and()

For example

var nvdi = (NIR.subtract(red)).divide(NIR.add(red)).rename('NDVI');

var filtered = nvdi.lt(0.75).and(nvdi.gt(0.35));  // to get between say 0.35 and 0.75 

Map.addLayer(filtered,{min: -1, max: 1},'ndvi_rice_1'); // plot`

Your Answer

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

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