1

In the below code, I'm going to remove some images from image collection by if condition in .map() instead of filter.neq(), what should I do for this purpose?

Map.centerObject(table);
Map.addLayer(table);

var s2 = ee.ImageCollection("COPERNICUS/S2")
.filterBounds(table)
.filterDate('2016-01-01','2020-01-01')
.filter(ee.Filter.lessThan('CLOUDY_PIXEL_PERCENTAGE',45))
.filter(ee.Filter.eq('system:index','20170910T071621_20170910T073037_T39SUR').not())
.filter(ee.Filter.eq('system:index','20180518T071621_20180518T071934_T39SUR').not());


print(s2);

code link: https://code.earthengine.google.com/7dc1cf120153095b7f48c133015398ca

1 Answer 1

5

In almost all cases, you are better off using filters. My understanding is that it's significantly more efficient. But if you really need to, you can filter out an element in map() by returning null and setting the dropNulls argument to true.

ee.ImageCollection("COPERNICUS/S2")
  .filterBounds(table)
  .filterDate('2016-01-01','2020-01-01')
  .map(function (image) {
    var index = image.getString('system:index')
    var include = image.getNumber('CLOUDY_PIXEL_PERCENTAGE').lt(45)
      .and(index.match('20170910T071621_20170910T073037_T39SUR').size().eq(0))
      .and(index.match('20180518T071621_20180518T071934_T39SUR').size().eq(0))
    return ee.Algorithms.If(include, image, null)
  }, true)

https://code.earthengine.google.com/20db63310dc07ee66257e0c7de932e0c

Your Answer

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

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