Geographic Information Systems Asked on August 7, 2020
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
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
Answered by Daniel Wiell on August 7, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP