I am trying to filter an ImageCollection
by multiple time intervals (rain seasons) that change from year to year. Hence, I can't just use the ee.Filter.calendarRange
.
I tried to merge the dates together and filter the collection but it does not work. What do I have to do?
var ROI = /* color: #0b4a8b */ee.Geometry.Polygon([
[36.5048217773437, 0.560293804172086],
[37.9302978515625, 0.560293804172086],
[37.9302978515625, 1.875580463973453],
[36.5048217773437, 1.875580463973453]
]);
Map.centerObject(ROI,8);
var s2 = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(ROI);
var longRain2016 = s2.filterDate('2016-04-01','2016-05-31');
var shortRain2016 = s2.filterDate('2016-11-15','2016-12-31');
var longRain2017 = s2.filterDate('2017-04-01','2017-05-31');
var shortRain2017 = s2.filterDate('2017-10-01','2017-12-31');
var longRain2018 = s2.filterDate('2018-03-01','2018-05-31');
var dateFilter = ee.ImageCollection(longRain2016.merge(shortRain2016).merge(longRain2017).merge(shortRain2017).merge(longRain2018));
var s2dateFilter = s2.filter(dateFilter);
var count = s2dateFilter.size();
print('Number of filtered images in the region of interest: ', count);