0

I'm trying to map some indexes (NDBI, SAVI, and IBI) using Landsat-5 imagery on Google Earth Engine (GEE). However, my experiment error, I don't know how to solve this problem. Is there any solution to this problem?

Here's my GEE script: https://code.earthengine.google.com/cd1b217f852604520dfdad23f485efe0

or

/**
 * Function to mask clouds based on the pixel_qa band of Landsat SR data.
 * @param {ee.Image} image Input Landsat SR image
 * @return {ee.Image} Cloudmasked Landsat image
 */
var cloudMaskL457 = function(image) {
  var qa = image.select('pixel_qa');
  // If the cloud bit (5) is set and the cloud confidence (7) is high
  // or the cloud shadow bit is set (3), then it's a bad pixel.
  var cloud = qa.bitwiseAnd(1 << 5)
                  .and(qa.bitwiseAnd(1 << 7))
                  .or(qa.bitwiseAnd(1 << 3));
  // Remove edge pixels that don't occur in all bands
  var mask2 = image.mask().reduce(ee.Reducer.min());
  return image.updateMask(cloud.not()).updateMask(mask2);
};

// This function clips images to the AOI feature collection
var clipToCol = function(image){
  return image.clip(aoi);
};

var dataset = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
                  .filterDate('2000-01-01', '2003-12-31').map(clipToCol)
                  .map(cloudMaskL457)
                  .filterBounds(aoi);


print(dataset)

var visParams = {
  bands: ['B3', 'B2', 'B1'],
  min: 0,
  max: 3000,
  gamma: 1.4,
};
Map.setCenter(105.5, -5.9, 8);
Map.addLayer(dataset.median(), visParams);

//SAVI:Soil-Adjusted Vegetation Index
var savi = dataset.map(function(image) {
  return image.select().addBands(image.expression(
                        '1.5 * (NIR - RED) / (NIR + RED + 5000)', {
                        'NIR': image.select('B4'),
                        'RED': image.select('B3')
                    }).float()).rename('SAVI')});
print(savi)

//NDBI:Normalized Normalized Difference Built-Up Index
var ndbi = dataset.map(function(image) {
  return image.select().addBands(image.expression(
                        '(SWIR - NIR) / (SWIR + NIR)', {
                        'NIR': image.select('B4'),
                        'SWIR': image.select('B5')
                    }).float()).rename('NDBI')});

print(ndbi)

//IBI: Index-based Built-up Index
var ibi = dataset.map(function(image) {
  return image.select().addBands(image.expression(
                        '(NIR / (NIR + RED)) + (GREEN / (GREEN + SWIR))', {
                        'NIR': image.select('B4'),
                        'RED': image.select('B3'),
                        'GREEN': image.select('B2'),
                        'SWIR': image.select('B5')
                    }).float()).rename('IBI')});

print(ibi)
  
var colorizedVis = {
  min: 0.0,
  max: 1.0,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ],
};


//Map.addLayer(rgb,visParams, 'R5G6B4');
Map.addLayer(ndbi.median(), colorizedVis, 'NDBI');
Map.addLayer(savi.median(),colorizedVis, 'SAVI');
Map.addLayer(ibi.median(),colorizedVis, 'IBI');


// Export a cloud-optimized GeoTIFF.
Export.image.toDrive({
  image: savi,
  description: 'SAVI_00-03', 
  folder: 'GEE2',
  scale: 30,
  maxPixels: 1e9,
  region: aoi,
  fileFormat: 'GeoTIFF',
  formatOptions: {
    cloudOptimized: true
  }
});
``

1 Answer 1

0

The usage of .select() is wrong. The code you have:

var savi = dataset.map(function(image) {
  return image.select().addBands(image.expression(
                        '1.5 * (NIR - RED) / (NIR + RED + 5000)', {
                        'NIR': image.select('B4'),
                        'RED': image.select('B3')
                    }).float()).rename('SAVI')});

.select() function has these arguments:

Arguments:

this:imagecollection (ImageCollection):

The ImageCollection instance.

selectors (List):

A list of names, regexes or numeric indices specifying the bands to select.

So, the use is image.select(['B3','B4']) for example.

Also, addBands isn't necessary here and requires another image and the bands to add. In the same way, .expression returns a single image. If you want to add this result to the original image with .addBands use something like this:

var savi = dataset.map(function(image) {
  var savi = image.expression('1.5 * (NIR - RED) / (NIR + RED + 5000)', {
                        'NIR': image.select('B4'),
                        'RED': image.select('B3')
                    }).rename('SAVI')
  return image.addBands(savi)
});

The result will be the original image + 'SAVI' band.

If you want to store in different objects:

var savi = dataset.map(function(image) {
  return image.expression('1.5 * (NIR - RED) / (NIR + RED + 5000)', {
                        'NIR': image.select('B4'),
                        'RED': image.select('B3')
                    }).rename('SAVI')});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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