0

I tried to create a land composite for mangroves in my study area. The code works fine for creating land composite map using Landsat 8, and when i modify the code for Landsat 7 images, i encounter this error.

Here is my code.

var L7 = ee.ImageCollection("LANDSAT/LE07/C02/T1_L2");
var addIndicesL7 = function (img) {
  var ndvi = img.normalizedDifference (['SR_B4, SR_B3']).rename ('NDVI');
  var ndmi = img.normalizedDifference (['SR_B7, SR_B2']).rename ('NDMI');
  var mndwi = img.normalizedDifference (['SR_B2, SR_B5']).rename ('MNDWI');
  var sr = img.select (['SR_B4']).divide(img.select(['SR_B3'])).rename ('SR');
  var ratio54 = img.select (['SR_B5']).divide(img.select(['SR_B4'])).rename ('R54');
  var ratio35 = img.select (['SR_B3']).divide(img.select(['SR_B5'])).rename ('R35');
  var gcvi = img.expression ('(NIR/GREEN)-1', {
     'NIR':img.select ('SR_B4'),
     'GREEN':img.select ('SR_B2')
   }).rename ('GCVI');
   return img
   .addBands (ndvi)
   .addBands (ndmi)
   .addBands (mndwi)
   .addBands (sr)
   .addBands (ratio54)
   .addBands (ratio35)
   .addBands (gcvi);
   };

 var year = 2021; 
 var startDate = (year-1)+'-01-01'; 
 var endDate = (year+1)+'-12-31'; 


var l7 = L7.filterDate(startDate,endDate)
     .map(maskClouds)
     .map(addIndicesL7);


 var L7composite = l7
               .median()
               .clip(studysite); 

1 Answer 1

1

This wouldn't work for L8 either. normalizedDifference() expects a list with two band names. You provided it with

['SR_B4, SR_B3']

This is a list with with a single string. You want

['SR_B4', 'SR_B3']

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.