# Exporting Time Series Data using Google Earth Engine and JavaScript?

I'm new to the GEE platform.

How can I create a time series analysis (vegetation indices) of a particular shape?

would like to export in table form

 var OLI = ('LANDSAT/LC08/C01/T1_RT_TOA');

//lOCALIZAÇÃO

var shp = ee.FeatureCollection(table);

// DEFINIÇÃO DO CENTRO DA ÁREA DE ESTUDO

Map.centerObject(shp);

// SELEÇÃO IMAGEM LANDSAT EM FUNÇÃO DO TEMPO E LOCALIZAÇÃO

var imagery = ee.ImageCollection(OLI)

var collection = ee.ImageCollection(imagery
.filterDate('2015-01-01','2019-09-17')
.filterBounds(shp));

print ("Coleção de Imagens clipadas: ", collection);

// MOSAICO E CLIP DA IMAGEM

var clipimagem = collection.mosaic().clip(shp);

//------------------ CALCULOS ÍNDICES DE VEGETAÇÃO ---------------------------

// Use the normalizedDifference(A, B) to compute (A - B) / (A + B)
var ndvi = clipimagem.normalizedDifference(['B5', 'B4']);

// Use the NBR (A, B) to compute (A - B) / (A + B)
var nbr = clipimagem.normalizedDifference(['B5', 'B7']);

var evi = clipimagem.expression(
'2.5 * (nir - red) / (nir + 6 * red - 7.5 * blue + 1)',
{
red: clipimagem.select('B4'),    // 620-670nm, RED
nir: clipimagem.select('B5'),    // 841-876nm, NIR
blue: clipimagem.select('B2')    // 459-479nm, BLUE
});

var savi = clipimagem.expression(
'2.0 * (nir - red) / (nir + red + 1.0)',
{
red: clipimagem.select('B4'),    // 620-670nm, RED
nir: clipimagem.select('B5'),    // 841-876nm, NIR
});

// Make a palette: a list of hex strings.
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
'74A901', '66A000', '529400', '3E8601', '207401', '056201',
'004C00', '023B01', '012E01', '011D01', '011301'];

Map.addLayer(ndvi, {min:0, max:1, palette: palette}, 'NDVI');
Map.addLayer(nbr, {min:0, max:1, palette: palette}, 'NBR');
Map.addLayer(evi, {min:0, max:1, palette: palette}, 'EVI');
Map.addLayer(savi, {min:0, max:1, palette: palette}, 'SAVI');


You will have to make a long addition to your script to extract not from the mosaic, but from a collection for each of your indices.

Then you reduce the images with .reduceregion() and add it as a property to a feature.

After that, you create a collection of the feature so that it can be exported to a csv.

//////////////////
// Export index results as a timeseries
/////////////////

/////////////////////////////////////////////////
// Create Clip collection function
//////////////////////////////////////////////
var clipToShp = function(image){
var clipped = image.clip(shp)
return clipped
}

// clip all images to this shp
var clippedCollection = collection.map(clipToShp)

// Create NDVI of collection function
var ndviOfCollection = function(image){
var ndviOfImage = image.normalizedDifference(['B5', 'B4']);
return ndviOfImage.copyProperties(image)

}

// create a collection of the NDVI
var ndviCollection = clippedCollection.map(ndviOfCollection)

// Create NBR of collection function
var nbrOfCollection = function(image){
var nbrOfImage = image.normalizedDifference(['B5', 'B7']);

return nbrOfImage.copyProperties(image)

}

// create a collection of the NBR
var nbrCollection = clippedCollection.map(nbrOfCollection)

// Create EVI of collection function
var eviOfCollection = function(image){
var eviOfImage = image.expression(
'2.5 * (nir - red) / (nir + 6 * red - 7.5 * blue + 1)',
{
red: image.select('B4'),    // 620-670nm, RED
nir: image.select('B5'),    // 841-876nm, NIR
blue: image.select('B2')    // 459-479nm, BLUE
});

return eviOfImage.copyProperties(image)

}

// create a collection of the EVI
var eviCollection = clippedCollection.map(eviOfCollection)

// Create SAVI of collection function
var saviOfCollection = function(image){
var saviOfImage = image.expression(
'2.0 * (nir - red) / (nir + red + 1.0)',
{
red: image.select('B4'),    // 620-670nm, RED
nir: image.select('B5'),    // 841-876nm, NIR
});

return saviOfImage.copyProperties(image)

}

// create a collection of the SAVI
var saviCollection = clippedCollection.map(saviOfCollection)

// create a feature so we can iterate through it later
var fet = ee.Feature(shp)

// add the NDVItimeseries to the SHP

var newf = ee.Feature(feature)
var featureNDVI = ee.Number(img.reduceRegion(ee.Reducer.mean(),shp))
var theDate = img.get("DATE_ACQUIRED")//.format("Y-M-D");
var ndviDate = ee.String("NDVI_").cat(theDate)

return ee.Feature(newf.set(ndviDate,featureNDVI));
}

// add the NBRtimeseries to the SHP

var newf = ee.Feature(feature)
var featureNBR = ee.Number(img.reduceRegion(ee.Reducer.mean(),shp))
var theDate = img.get("DATE_ACQUIRED")
var nbrDate = ee.String("NBR_").cat(theDate)

return ee.Feature(newf.set(nbrDate,featureNBR));
}

// add the EVI timeseries to the SHP

var newf = ee.Feature(feature)
var featureEVI = ee.Number(img.reduceRegion(ee.Reducer.mean(),shp))
var theDate = img.get("DATE_ACQUIRED")
var eviDate = ee.String("EVI_").cat(theDate)

return ee.Feature(newf.set(eviDate,featureEVI));
}

// add the SAVI timeseries to the SHP

var newf = ee.Feature(feature)
var featureSAVI = ee.Number(img.reduceRegion(ee.Reducer.mean(),shp))
var theDate = img.get("DATE_ACQUIRED")
var saviDate = ee.String("SAVI_").cat(theDate)

return ee.Feature(newf.set(saviDate,featureSAVI));
}

//Make a collection of the features
var featureCollectionNDVI = ee.FeatureCollection([
featNDVI])//,
var featureCollectionNBR = ee.FeatureCollection([
featNBR])
var featureCollectionEVI = ee.FeatureCollection([
featEVI])
var featureCollectionSAVI = ee.FeatureCollection([
featSAVI])

// Export Indices
Export.table.toDrive({
collection: featureCollectionNDVI,
description: "NDVI_Export",
folder:"Time_Series",
fileFormat:"CSV"
})
Export.table.toDrive({
collection: featureCollectionNBR,
description: "NBR_Export",
folder:"Time_Series",
fileFormat:"CSV"
})
Export.table.toDrive({
collection: featureCollectionEVI,
description: "EVI_Export",
folder:"Time_Series",
fileFormat:"CSV"
})
Export.table.toDrive({
collection: featureCollectionSAVI,
description: "SAVI_Export",
folder:"Time_Series",
fileFormat:"CSV"
})


======================

# EDIT

Ah, I missed something.

How can I create a time series analysis (vegetation indices) of a particular shape?

When testing it, as I don't have access to your "table" I just drew a polygon, and used that as "shp". But I just noticed that your "table" is actually a Feature Collection.

If it is just one polygon that you have in your collection, you can change your early code to this.

var shp = ee.FeatureCollection(table).first().geometry();


Edit code above to change to a geometry

If it is actually a collection, you will have to modify the functions to be mapped to a collection, rather than a feature.

• Thank you so much, Sean. :) Oct 10, 2019 at 11:55
• when exporting the table the following error arose: Error: Unable to use a collection in an algorithm that requires a feature or image.... Oct 10, 2019 at 12:15
• Sorry, as I do not master the idiom generated a confusion. Oct 11, 2019 at 17:06
• No worries, your mastery of English is much better than my non-existent Portuguese! Did the solution work? Oct 11, 2019 at 18:10
• No, I should study the tool further. replace what you suggested var shp = ee.FeatureCollection (table) .first (); However, the following errors arose: ImageCollection (Error) Feature, argument 'geometry': Invalid type. Expected: Geometry. Current: Feature. Image (Error) Feature, argument 'geometry': Invalid type. Expected: Geometry. Current: Feature. shp.draw is not a function Oct 11, 2019 at 18:18