我想将NDVI时间序列的csv导出为不同点。我目前有一个可以打印图表的代码,然后单击从图表下载数据。有没有一种更好的方法,因为我不一定需要打开图表?
我现在拥有的是一个代码,可以在一个位置打印图表,然后可以下载...我希望有一种自动方式,这样就无需从图表中下载。
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'}));
您可以使用.getRegion
命令来完成。它输出一个数组,其中所有值与您的几何图形重叠,因此您也可以使用多点几何图形。
困难在于导出它,因为只能导出FeatureCollections。这就是为什么您需要将其转换为FeatureCollection以便将其导出。
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)
您将获得一个以点的经度/纬度为标识符的数组,您可以根据该数组对图形进行分组。