I want to extract for each point of my shapefile the NDVI and the related time-series charts but I cannot understand how to extract values.
This is the code
// load the S2 dataset
var S2 = ee.ImageCollection('COPERNICUS/S2')
.filterDate("2015-01-01", "2021-12-31")
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10));
// S2.limit(10).aside(print)
// load S2_CLOUD_PROBABILITY dataset
var S2_CLOUD_PROBABILITY = ee.ImageCollection('COPERNICUS/S2_CLOUD_PROBABILITY');
// Join S2_summer2018 and S2_CLOUD_PROBABILITY
var S2withCloudMask = ee.Join.saveFirst('cloud_mask').apply({
primary: S2,
secondary: S2_CLOUD_PROBABILITY,
condition: ee.Filter.equals({leftField: 'system:index', rightField: 'system:index'})
});
S2withCloudMask = ee.ImageCollection(S2withCloudMask);
// S2withCloudMask.first().aside(print)
// define a function to mask-out clouds from each image
var maskClouds = function(img) {
var clouds = ee.Image(img.get('cloud_mask')).select('probability');
var isNotCloud = clouds.lt(20);
return img.mask(isNotCloud);
};
// // use the maskClouds function
var S2_cloudsMasked = S2withCloudMask.map(maskClouds);
// add NDVI
// var addNDVI = function(image) {
function addNDVI(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename('ndvi');
return image.addBands(ndvi);
}
// Map the function over the collection
var S2_cloudsMasked_ndvi = S2_cloudsMasked.map(addNDVI);
// S2_cloudsMasked_ndvi.limit(5).aside(print);
// visualize the time series
var chart = ui.Chart.image.series({
imageCollection: S2_cloudsMasked_ndvi.select('ndvi'),
region: geometry,
reducer: ee.Reducer.mean(),
scale: 20
}).setOptions({
lineWidth: 1,
title: 'NDVI Time Series',
interpolateNulls: true,
vAxis: {title: 'NDVI'},
hAxis: {title: '', format: 'YYYY-MMM'}// ,
// explorer: {}
// explorer: {axis: 'horizontal'} // or 'vertical'
});
print(chart);
// // Map.addLayer(geometry);
// Map.centerObject(geometry, 15);
// ```