I am new in google earth engine, i am trying to plot the time series NDVI value and images as well, i found a script and i tried to modified but its not working properly. Below is the code
its giving error that, Error generating chart: The image collection is empty
.
I just changed here the var geometry, and i imported the KML file using fusion table and paste the link here. How to display the statistics graph and images also for selected region
//Import GEE Feature Collection (My AOI kml)
var geometry = ee.FeatureCollection('ft:19HmlYA6D2W-soGuCJGOvdEutyTNdZFK1tUFz2JAM');
// Create image collection of S-2 imagery for the perdiod 2016-2019
var S2 = ee.ImageCollection('COPERNICUS/S2')
//filter start and end date
.filterDate('2016-02-01', '2019-02-28')
//filter according to drawn boundary
.filterBounds(geometry);
// Function to mask cloud from built-in quality band
// information on cloud
var maskcloud1 = function(image) {
var QA60 = image.select(['QA60']);
return image.updateMask(QA60.lt(1));
};
// Function to calculate and add an NDVI band
var addNDVI = function(image) {
return image.addBands(image.normalizedDifference(['B8', 'B4']));
};
// Add NDVI band to image collection
var S2 = S2.map(addNDVI);
// Extract NDVI band and create NDVI median composite image
var NDVI = S2.select(['nd']);
var NDVImed = NDVI.median(); //I just changed the name of this variable ;)
// Create palettes for display of NDVI
var ndvi_pal = ['#d73027', '#f46d43', '#fdae61', '#fee08b', '#d9ef8b',
'#a6d96a'];
// Create a time series chart.
var plotNDVI = ui.Chart.image.seriesByRegion(S2, geometry,ee.Reducer.mean(),
'nd',500,'system:time_start', 'system:index')
.setChartType('LineChart').setOptions({
title: 'NDVI short-term time series',
hAxis: {title: 'Date'},
vAxis: {title: 'NDVI'}
});
// Display.
print(plotNDVI);
// Display NDVI results on map
Map.addLayer(NDVImed.clip(geometry), {min:-0.5, max:0.9, palette: ndvi_pal}, 'NDVI');