I am trying to download a CSV file with a time series of Landsat 8 EVI2, and with the respective date and plot id from multiple points using GEE according to the following code:
var roi = ee.FeatureCollection([
ee.Feature(ee.Geometry.Point([-43.8115,-16.6648]), {plot_id: 1}),
ee.Feature(ee.Geometry.Point([-43.7923,-16.663]), {plot_id: 2}),
ee.Feature(ee.Geometry.Point([-43.7794,-16.6596]), {plot_id: 3}),
ee.Feature(ee.Geometry.Point([-43.8879,-16.7316]), {plot_id: 4}),
ee.Feature(ee.Geometry.Point([-43.8487,-16.6756]), {plot_id: 5}),
ee.Feature(ee.Geometry.Point([-43.8274,-16.6888]), {plot_id: 6}),
ee.Feature(ee.Geometry.Point([-43.8946,-16.7579]), {plot_id: 7}),
ee.Feature(ee.Geometry.Point([-48.3,-18.9833]), {plot_id: 8}),
ee.Feature(ee.Geometry.Point([-44.1224,-16.3708]), {plot_id: 9}),
ee.Feature(ee.Geometry.Point([-44.1134,-16.3687]), {plot_id: 10})
]);
// Intervalo de tempo da minha série temporal
var startdate = '2013-04-01';
var enddate = '2024-04-30';
var years = ee.List.sequence(ee.Date(startdate).get('year'), ee.Date(enddate).get('year'));
// This function masks clouds in Landsat 8 imagery.
function maskL8(im) {
var qa = im.select('QA_PIXEL');
var mask = qa.eq(2720);
return im.updateMask(mask).copyProperties(im);
}
var ls8toa = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
.filterBounds(roi)
.filterDate(startdate, enddate)
.filter(ee.Filter.lt('CLOUD_COVER',0.3))
.map(function(im) {return maskL8(im)});
// Calcula EVI2 a partir do Landsat8
var ls8_evi2 = ls8toa.map(function(image) {
var evi2 = image.expression(
'2.5*(NIR-RED)/(NIR+2.4*RED+1)', {
'NIR': image.select('SR_B5'),
'RED': image.select('SR_B4')
}).rename('EVI2');
return image.addBands(evi2);
});
var landsat = ee.ImageCollection(ls8_evi2);
var EVI2 = ls8_evi2.select(['EVI2']);
print(EVI2, 'EVI2');
print('Quantas Imagens', EVI2.size());
//Função pra calcular valores médios para cada ponto
var pointsmean = function(image) {
var means = image.reduceRegions({
collection: roi.select(['plot_id']),
reducer: ee.Reducer.mean(),
scale: 30
});
// Atribuindo datas
means = means.map(function(f) { return f.set({date: image.date().format("YYYY-MM-dd")}) });
return means.copyProperties(image);
};
var finalEVI2 = EVI2.map(pointsmean).flatten()
.sort('date', false);
print(finalEVI2, 'final EVI2');
// Exportar tabela em csv direto pro Drive
Export.table.toDrive({
collection: finalEVI2,
description: 'EVI2_walter_'+startdate+'_TO_'+enddate,
folder: 'LS8_walter',
fileFormat: 'CSV'
});
Actually, I used 34 pairs of coordinates instead of 10 as shown in the code above. I simplified the sample in this Question.
The output shown in the console is:
The CSV file is not what I expected (see figure below). I need columns named ‘date’, ‘plot_id’, and ‘EVI2’ with the values.
What is wrong and how to fix it?