[GIS] Exporting Time Series Data using Google Earth Engine and JavaScript

google-earth-enginejavascript

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
    .filterMetadata('CLOUD_COVER','less_than',3)
    .filterDate('2015-01-01','2019-09-17')
    .filterBounds(shp));


// ADICIONANDO AS IMAGENS CLIPADAS NO CONSOLE DIREITO

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

// MOSAICO E CLIP DA IMAGEM

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

// ADICIONANDO AS IMAGENS CLIPADAS NO CONSOLE DIREITO

print("Imagens Cor verdadeira: ", clipimagem);

//------------------ 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
    });


// ADICIONANDO LAYER AO MAPA

// 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(shp.draw({color: 'ffffff', strokeWidth: 5}), {},'Parque Estadual do Cantão');
Map.addLayer(clipimagem, {bands:'B5,B4,B3'}, 'FALSA COR');
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');

Best Answer

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 addPropNDVI = function(img, feature){

  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));
}


var featNDVI = ee.Feature(ndviCollection.iterate(addPropNDVI, fet));




// add the NBRtimeseries to the SHP
var addPropNBR = function(img, feature){

  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));
}



var featNBR = ee.Feature(nbrCollection.iterate(addPropNBR, fet));


// add the EVI timeseries to the SHP
var addPropEVI = function(img, feature){

  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));
}


var featEVI = ee.Feature(eviCollection.iterate(addPropEVI, fet));

// add the SAVI timeseries to the SHP
var addPropSAVI = function(img, feature){

  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));
}


var featSAVI = ee.Feature(saviCollection.iterate(addPropSAVI, fet));


//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.

In your question you mention:

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.

Related Question