var vegSHP = ee.Geometry.Polygon(
[[[-47.93318633174054, -15.923525740817693],
[-47.84117583369367, -15.948285390673487],
[-47.79070738886945, -15.876308885443688],
[-47.83565782221213, -15.84506420705287],
[-47.90844224604025, -15.867191599980972]]]);
var addNDVI = function(image) {
var ndvi = ee.Image(0).expression(
'2.5 * ((NIR - RED) / (NIR + RED))*100', {
'NIR': image.select('B8'),
'RED': image.select('B4'),
});//.toUint16();
return image.addBands(ndvi.rename('ndvi'));
};
var image = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(vegSHP);
var bandasFiltro= image.select('B.*')
.map(addNDVI);
print(bandasFiltro, "bandasFiltro");
var dates = bandasFiltro
.map(function(bandasFiltro) {
return ee.Feature(null, {'date': bandasFiltro
.date()
.format('YYYY-MM')});
})
.distinct('date')
.aggregate_array('date');
var bandasFiltroData= bandasFiltro
.filterDate(dates.get(1),dates.get(2)) // pegando o primeiro valor da data e o segundo
.median()
.clip(vegSHP)
.set("periodo", ee.String(dates.get(0)).cat("_").cat(dates.get(2)))
for (var i = 0; i < 4-1; i++){
var inicio= dates.get(i);
var fim= dates.get(i+1);
var imgMediana= ee.Image(bandasFiltro
.filterDate(inicio,fim)
.median()
.clip(vegSHP))
.set("periodo", ee.String(inicio).cat("_").cat(fim));
//print(imgMediana);
var id= ee.String("sentinel_2_")
.cat(inicio).replace("\\-", "")
.cat("_")
.cat(fim).replace("\\-", "");
//print(id)
Export.image.toDrive({
image:imgMediana,
description: id,
folder: 'ProjetoJBB',
fileNamePrefix: id,
region: vegSHP,
crs: 'EPSG:4326',
scale: 10,
maxPixels: 10000000000});
}
edit: code added