Gorelick,
Thank you for your reply and the suggestion to solve my problem. In addition to your answer, I have also come up with a solution based on the script provided in this URL: https://code.earthengine.google.com/e95b7ebd9ecf4f5f35133fbb12638722
Below I present my script
/* -------------------------- Study region -----------------------------*/
var study_region = ee.FeatureCollection('path/to/aoi/shapefile/');
var empty = ee.Image().byte();
var region_draw = empty.paint({
featureCollection: study_region,
color: 1,
width: 3
});
Map.addLayer(region_draw, {palette: 'red'}, 'study_region');
Map.centerObject(study_region);
/* ---------------------- Customize Parameters -------------------------*/
var yStart = 1988;
var yEnd = 2022;
var listYears = ee.List.sequence(yStart, yEnd, 1);
/* ----------------------- Get Landsat images --------------------------*/
var featCol = ee.FeatureCollection(listYears.map(function(year){
// set start and end date from the year
var start_date = ee.Date.fromYMD(year, 1, 1);
var end_date = ee.Date.fromYMD(ee.Number(year).add(1), 1, 1);
var start_day = 1;
var end_day = 365;
var collection4 = ee.ImageCollection('LANDSAT/LT04/C02/T1_L2')
.filterBounds(study_region)
.filterDate(start_date, end_date)
.filter(ee.Filter.dayOfYear(start_day,end_day));
var collection5 = ee.ImageCollection('LANDSAT/LT05/C02/T1_L2')
.filterBounds(study_region)
.filterDate(start_date, end_date)
.filter(ee.Filter.dayOfYear(start_day,end_day));
var collection7 = ee.ImageCollection('LANDSAT/LE07/C02/T1_L2')
.filterBounds(study_region)
.filterDate(start_date, end_date)
.filter(ee.Filter.dayOfYear(start_day,end_day));
var collection8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterBounds(study_region)
.filterDate(start_date, end_date)
.filter(ee.Filter.dayOfYear(start_day,end_day));
var collection9 = ee.ImageCollection('LANDSAT/LC09/C02/T1_L2')
.filterBounds(study_region) //Use the same mask for Landsat 9*/
.filterDate(start_date, end_date)
.filter(ee.Filter.dayOfYear(start_day,end_day));
var LS4_size = collection4.size();
var LS5_size = collection5.size();
var LS7_size = collection7.size();
var LS8_size = collection8.size();
var LS9_size = collection9.size();
// Return the size in a feature
var feature = ee.Feature(ee.Geometry.Point([0,0]), {
year:ee.Number(year).format('%d'), 'system:time_start':start_date.millis(),
LS4: LS4_size, LS5: LS5_size, LS7: LS7_size, LS8: LS8_size, LS9: LS9_size});
return feature;
}));
/* ---------------------- Create the chart -------------------------*/
// plot as a chart
var chart = ui.Chart.feature.byFeature(
featCol, 'year', ['LS4', 'LS5', 'LS7', 'LS8', 'LS9'])
.setChartType('ColumnChart').setOptions( {
title: 'Number of observations and their according Landsat collection from the ImageCollection',
isStacked: true, bar: {groupWidth: '95%'},
legend: { position: 'in'},
vAxis: {title: 'Number of Observations'},
hAxis: {title: 'Year', },
})
.setSeriesNames(['Landsat-4', 'Landsat-5', 'Landsat-7', 'Landsat-8', 'Landsat-9']);
print(chart);
print('Feature Collection', featCol);