I am trying export NDVI result to CSV file for 35 shapefiles farmers in Earth Engine. But it did not work. I tried find any solution from internet. How can I solve this problem?
var Akdarya = ee.FeatureCollection("users/xodjayevshovkat/Akdarya_GEE_35");
//Define a geometry.
Map.addLayer(Akdarya);
// Make the geometry a feature collection.
// Import S2 image collection.
var S2 = ee.ImageCollection('COPERNICUS/S2')
// Filter collection.
.filterDate('2018-05-01','2018-09-30')
.filterBounds(Akdarya)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 20);
// Define a cloud masking function.
var maskcloud1 = function(image) {
var QA60 = image.select(['QA60']);
return image.updateMask(QA60.lt(1))
};
//
// Define an index function (return only NDVI).
var NDVI = function(image) {
return image.expression(
'(NIR - RED) / (NIR + RED)',
{
'NIR': image.select('B8'),
'RED': image.select('B4'),
}).rename('NDVI').copyProperties(image, image.propertyNames());
};
// Apply the cloud mask function.
var NDVIcol = S2.map(maskcloud1)
// Apply the NDVI transformation.
.map(NDVI);
// Calculate the per-pixel median/mean NDVI for all images in collection.
var NDVImed = NDVIcol.mean();
// Define vis params.
var NDVIvis = {min: -0.001, max: 0.9, palette: 'FFFFFF, CE7E45, DF923D, F1B555, FCD163, 99B718, 74A901, 66A000, 529400,' +
'3E8601, 207401, 056201, 004C00, 023B01, 012E01, 011D01, 011301'};
//
// create a collection of the NDVI
var NDVIclip = NDVImed.clipToCollection(Akdarya)
// get the mean value for the region from each image
var ts = S2.map(function(image){
var date = image.get("DATE_ACQUIRED")//.format("Y-M-D");
var mean = image.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: Akdarya,
scale: 30
});
// and return a feature with 'null' geometry with properties (dictionary)
return ee.Feature(null, {'mean': mean.get('NDVI'),
'date': date})
});
// Export a .csv table of date, mean NDVI for watershed
Export.table.toDrive({
collection: ts,
description: 'NDVI',
fileFormat: 'CSV'
});
'''