2

Below is the link of my code to calculate EVI in Google Earth engine. It is not giving/rendering color according to the color palette! Please help me in this regard. https://code.earthengine.google.com/995504963211f6c4d300ac364dc6697c

function maskS2clouds(image) {

  var qa = image.select('QA60');


  var cloudBitMask = ee.Number(2).pow(10).int();
  var cirrusBitMask = ee.Number(2).pow(11).int();


  var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
             qa.bitwiseAnd(cirrusBitMask).eq(0));
  return image.updateMask(mask).divide(10000);
}

var composite = s2.filterDate('2018-03-01', '2018-03-15')
                  // Pre-filter to get less cloudy granules.
                  .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
                  .filterBounds(ft)
                  .map(maskS2clouds)
                  //.multiply(100)
                  .median();



Map.setCenter(87.32,22.40, 6);
Map.addLayer(composite, {bands: ['B6', 'B4', 'B3'], min: 0, max: 0.3},'fcc');


var landcover_roi = composite.clip(ft);
var evi =landcover_roi.expression(
    '2.5 * ((NIR-RED) / (NIR +6 * RED -7.5* BLUE))', {
      'NIR':landcover_roi.select('B8'),
      'RED':landcover_roi.select('B4'),
      'BLUE':landcover_roi.select('B2')
    });
Map.addLayer(ft, {}, 'From Fusion Table');

var EVI=evi.multiply(100).uint8()
var meanDictionary = EVI.reduceRegion({
  reducer: ee.Reducer.mean(),
  geometry: ft.geometry(),
  scale: 20,
  maxPixels: 1e9
});

print(meanDictionary)


var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
               '74A901', '66A000', '529400', '3E8601', '207401', '056201',
               '004C00', '023B01', '012E01', '011D01', '011301'];

// Center the map
Map.setCenter(87.32,22.40, 6);

print(EVI);
 Map.addLayer(EVI,{min: -1, max: 1, palette: palette},'Sentinel-2 evi')
Export.image.toDrive({
  image:EVI,
  description: 'evi',
  scale: 30,
 region: ft,
  maxPixels:34089663741
  });
1
  • 1
    Please paste your code here. People will be more likely to help if the code is on site.
    – OverArch
    Sep 26, 2018 at 12:15

1 Answer 1

2

Your stritching values in Map.addLayer are for a float band type (-1 to 1), and are not really stretching much. To use float values you should not change the band's type to unsigned integer 16 bits. This would do it:

var EVI=evi//.multiply(100).uint16();

and the stretching values should be wider to represent the range of the output:

Map.addLayer(EVI,{min: -5, max: 4, palette: palette},'Sentinel-2 evi');

you can play around moving min and max

And if you want/need to change band's type, you should not use an unsigned integer as it not holds negative values, and also change the stretch values to adapt to it. Code:

var EVI = evi.multiply(10).toInt8();
Map.addLayer(EVI,{min: -50, max: 40, palette: palette},'Sentinel-2 evi');
// full stretch
// Map.addLayer(EVI,{min: -125, max: 125, palette: palette},'Sentinel-2 evi');

This is a good option for reducing the size of the output

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.