0

I'm trying to apply a code that was desenvolved in a ARSET training for my interest area, but appears completly white when I aply map.addLayer instead the composition defined. I've tried to adjust the max, min.

enter image description here

function maskClouds(image) {
  

    var cloudShadowBitMask = ee.Number(2).pow(4).int();
    var cloudsBitMask = ee.Number(2).pow(3).int();  
    
    var qa = image.select('QA_PIXEL');
    
    var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).and(qa.bitwiseAnd(cloudsBitMask).eq(0)); 
  
  return image.updateMask(mask).divide(10000).copyProperties(image, ["system:time_start"]);
}

var addIndicesL8 = function(img) {
  // NDVI
  var ndvi = img.normalizedDifference(['SR_B5','SR_B4']).rename('NDVI');
  // NDMI (Normalized Difference Mangrove Index - Shi et al 2016 - New spectral metrics for mangrove forest identification)
  var ndmi = img.normalizedDifference(['SR_B7','SR_B3']).rename('NDMI');
  // MNDWI (Modified Normalized Difference Water Index - Hanqiu Xu, 2006)
  var mndwi = img.normalizedDifference(['SR_B3','SR_B6']).rename('MNDWI');
  // SR (Simple Ratio)
  var sr = img.select('SR_B5').divide(img.select('SR_B4')).rename('SR');
  // Band Ratio 54
  var ratio54 = img.select('SR_B6').divide(img.select('SR_B5')).rename('R54');
  // Band Ratio 35
  var ratio35 = img.select('SR_B4').divide(img.select('SR_B6')).rename('R35');
  // GCVI
  var gcvi = img.expression('(NIR/GREEN)-1',{
    'NIR':img.select('SR_B5'),
    'GREEN':img.select('SR_B3')
  }).rename('GCVI');
  return img
    .addBands(ndvi)
    .addBands(ndmi)
    .addBands(mndwi)
    .addBands(sr)
    .addBands(ratio54)
    .addBands(ratio35)
    .addBands(gcvi);
};

var startDate = '2019-01-01' ;

var endDate = '2019-12-31';

var l8 = L8.filterDate(startDate,endDate)

    .map(maskClouds)

    .map(addIndicesL8)
    

var composite = l8
             
              .median()
             
              .clip(geometry);

var srtmClip = SRTM.clip(geometry);

var elevationMask = srtmClip.lt(65);

var NDVIMask = composite.select('NDVI').gt(0.25);  
var MNDWIMask = composite.select('MNDWI').gt(-0.50); 

var compositeNew = composite
                        .updateMask(NDVIMask)
                        .updateMask(MNDWIMask)
                        .updateMask(elevationMask)

var visPar = {bands:['NDVI'], min: -1, max:1 }; 

Map.addLayer(compositeNew.clip(geometry), visPar , 'Landsat Composite 2019')  

0

Your Answer

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