I have problem with generating charts in GEE. I am trying to calculate NDVI for more than 100 Shapefiles (FeatureCollection
) and export the results to a chart and CSV file. I got an error:
Error generating chart: Collection query aborted after accumulating over 5000 elements
How can I revise my code to avoid this error?
// Define a geometry.
var Akdarya = ee.FeatureCollection("users/xodjayevshovkat/Akdarya_GEE_35");
// Make the geometry a feature collection.
// Import S2 image collection.
var S2 = ee.ImageCollection('COPERNICUS/S2')
// Filter collection.
.filterDate('2018-01-01','2018-12-31')
.filterBounds(Akdarya)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 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 NDRE for all images in collection.
var NDVImed = NDVIcol.median();
// Define vis params.
var NDVIvis = {
palette: ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b', '#a6d96a'],
min: -0.5,
max: 0.9};
// Plot a time series of
var plotNDVI = ui.Chart.image.seriesByRegion({
imageCollection:NDVIcol,
regions: Akdarya,
reducer: ee.Reducer.mean(),
//scale: 1000,
xProperty: 'system:time_start',
seriesProperty: 'system:index'})
.setChartType('LineChart').setOptions({
title: 'NDVI Akdarya 2018',
hAxis: {title: 'Date'},
vAxis: {title: 'NDVI'},
});
// Display the results.
print(plotNDVI);
Map.addLayer(NDVImed.clipToCollection(Akdarya), NDVIvis, 'NDVI');