0

I have an NDVI collection wich I have created from the combination of different collections Landsat5 and 7.

How can I exctract the NDVI values of the centroids of each pixel, of each image from my collection and store them in a csv file, with their coordinates?

Example code:

var lst5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
    .filterDate('1984-10-01', '2011-10-01')
    .map(maskL57SR)
var lst7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
    .filterDate('2011-10-01', '2013-04-07')
    .map(maskL57SR)
var all = ee.ImageCollection(lst5.merge(lst7));

var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['NIR', 'RED']).rename('NDVI');
  return image.addBands(ndvi);
};


all = all.map(addNDVI)
  • Welcome to GIS.SE. What have you tried so far? Anything interesting turned up while googling and now you're stuck? – Erik Jan 17 at 13:43
  • Hi @Erik. I found this post ( gis.stackexchange.com/questions/278533/…) but still is confusing for me. No idea how to do this, that is why I posted the question. – foo Jan 17 at 13:49
  • This is much better, a simple question. It's not fully reproducible but close, maskL57SR function is not present in the code (I'd remove it since it has no relation with the question). You have other problems though. NIR and RED are not images bands, so addNDVI will not work that way. – Rodrigo E. Principe Jan 17 at 14:10
0

The main function to do this is ee.Image.reduceRegion.

// Define the point
var coords = [-71, -43]
var p = ee.Geometry.Point(coords);

Map.addLayer(p)

var lst5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
    .filterDate('1984-10-01', '2011-10-01')
var lst7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_SR')
    .filterDate('2011-10-01', '2013-04-07')
var all = ee.ImageCollection(lst5.merge(lst7));

var addNDVI = function(image) {
  var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
  return image.addBands(ndvi);
};

// remove 'limit' to compute the whole collection
all = all.map(addNDVI).filterBounds(p).limit(10)

// convert collection to list
var all_list = all.toList(all.size())

// map over collection
all_list = all_list.map(function(img){
  img = ee.Image(img)
  // get image values for point
  var values = img.reduceRegion({
    reducer: ee.Reducer.first(),
    geometry: p,
    scale: 30
  })
  // return as a Feature with no coordinates and values as properties
  return ee.Feature(null, values.set('img_id', img.id()))
})

// Create a FeatureCollection for exporting
var collection = ee.FeatureCollection(all_list)
print(collection)

// Export
Export.table.toDrive({
  collection: collection,
  folder: 'NAME OF FOLDER', 
  fileNamePrefix: 'NAME OF FILE', 
  fileFormat: 'CSV',
})

link

  • Thank you @Rodrigo E. Principe. I will try to ask better questions! Regarding your answer, if I do not want to extract the values of one point but for all the pixels withing my boundary, then (according to your example), I will use as a geometry my polygon/boundary? – foo Jan 18 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.