1

I would like to export as csv of NDVI time series for different points. I currently have a code that can print a chart, then click download the data from chart. Is there a better way to do so as I do not necessarily need to open a chart?

What I have now is a code to print a chart for one location, then I could download...I would like to have an automatic way so that I will not need to download from chart.

var point = ee.Geometry.Point([-100, 50]);

var LS8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
var FieldLS8 = LS8.filterBounds(point).filterDate('1995-01-01', '2018-12-31').sort('CLOUD_COVER')

var cloudlessNDVI_LS8 = FieldLS8.map(function(image) {
  var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
  var mask = cloud.lte(50);
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
  return image.addBands(ndvi).updateMask(mask);
});

print(ui.Chart.image.series({
  imageCollection: cloudlessNDVI_LS8.select('NDVI'),
  region: point,
  reducer: ee.Reducer.first(),
  scale: 30
}).setOptions({title: 'LS8: Meadow Cloud-masked NDVI over time'}));
陈见聪
  • 101
  • 1
  • 4

1 Answers1

3

You can do it with the .getRegion command. It outputs an Array with all the values overlapping your geometry, so you can use multipoint geometries as well.

The difficulty is in exporting it, since only FeatureCollections can be exported. That's why you need to convert it to a FeatureCollection to export it.

var points = ee.Geometry.MultiPoint(
        [[16.5, 11.3],
         [20.9, -14.5]]);

var LS8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
var FieldLS8 = LS8.filterBounds(points).filterDate('1995-01-01', '2018-12-31').sort('CLOUD_COVER')

var cloudlessNDVI_LS8 = FieldLS8.map(function(image) {
  var cloud = ee.Algorithms.Landsat.simpleCloudScore(image).select('cloud');
  var mask = cloud.lte(50);
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
  return image.addBands(ndvi).updateMask(mask);
});

var poiArray = cloudlessNDVI_LS8.select('NDVI').getRegion(points, 30);

var names = poiArray.get(0)
var values = poiArray.slice(1)

var exportFC = ee.FeatureCollection(
  values.map(function(values){
    return ee.Feature(null, ee.Dictionary.fromLists(names, ee.List(values)))
  })
)

var sortedFC = exportFC.sort('id')

print(sortedFC)

Export.table.toDrive(sortedFC)

You will get an Array with the lon/lat of the point as an identifier, which you could group your graphs by.

JonasV
  • 792
  • 5
  • 16