1

I'm just starting to work with Google Earth Engine and I'm trying to calculate a simple index based on an expression. I found this image.expression function, but can't figure out what is the equivalent for an imageCollection.

var s2 = ee.ImageCollection("COPERNICUS/S2_SR")
    .filterDate('2020-01-01', '2021-01-01')
    .filterBounds(geometry)
    .filter(ee.Filter.lt('CLOUD_COVERAGE_ASSESSMENT', 10));
    
var image = ee.Image(s2.first())

// **HOW DO I DO THIS TO AN IMAGE COLLECTION, INSTEAD OF JUST THE SINGLE IMAGE**? 
var index= image.expression(
    '(1-((B6*B7*B8A)/B4)**0.5)*((B12-B8A)/((B12+B8A)**0.5)+1)', {
      'B4': image.select('B4'),
      'B6': image.select('B6'),
      'B7': image.select('B7'),
      'B8A': image.select('B8A'),
      'B12': image.select('B12')
});

Map.addLayer(index, {min: 0, max: 0.99, palette: ['FF0000', '00FF00']});


3

Whenever you know how to transform a single image and you want to do it to every image in a collection, use ImageCollection.map():

var s2_index = s2.map(function (image) {
  return image.expression(
    '(1-((B6*B7*B8A)/B4)**0.5)*((B12-B8A)/((B12+B8A)**0.5)+1)', {
      'B4': image.select('B4'),
      'B6': image.select('B6'),
      'B7': image.select('B7'),
      'B8A': image.select('B8A'),
      'B12': image.select('B12')
  });
});

// s2_index is an ImageCollection
1
  • I see that makes sense. Thanks a lot for the help Kevin! – SyverPet Apr 8 at 8:48

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.