I have a shapefile that has 1500 points. I am trying to extract 1-year time-series NDVI values from Sentinel 2_SR for each point and export it to CSV with NDVI values date-wise and existing UID column from the shapefile. This is what my code looks like:
// Load the shapefile asset
var shapefile = ee.FeatureCollection('projects/ee-tilok-research/assets/CI_1500');
// Load Sentinel-2 SR image collection
var sentinel = ee.ImageCollection('COPERNICUS/S2_SR');
// Filter by date and region
var filtered = sentinel.filterDate('2022-05-01', '2023-05-31')
.filterBounds(shapefile);
// Define a cloud mask function
var cloudMask = function(image) {
var qa = image.select('QA60');
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
};
map.addLayer(shapefile);
// Apply the cloud mask function
var masked = filtered.map(cloudMask);
// Define a NDVI function
var ndvi = function(image) {
return image.normalizedDifference(['B8', 'B4']).rename('NDVI');
};
// Apply the NDVI function
var withNDVI = masked.map(ndvi);
// Reduce the collection to a single image or a time series
// For example, you can use mean, median, max, min, etc.
var reduced = withNDVI.mean();
// Export the NDVI values as a CSV file
// Join the NDVI values with the existing attributes of the shapefile
var joined = ee.Join.saveAll('ndvi').apply({
primary: shapefile,
secondary: reduced.reduceRegions({
collection: shapefile,
reducer: ee.Reducer.first(),
scale: 10 // change this according to your needs
}),
condition: ee.Filter.equals({
leftField: '.geo',
rightField: '.geo'
})
});
// Export the joined feature collection to Google Drive
Export.table.toDrive({
collection: joined,
description: 'ndvi_values', // change this according to your needs
folder: 'your_folder_name', // change this according to your needs
// selectors: ['your_attribute_1', 'your_attribute_2', ..., 'ndvi'] // change this according to your needs
});
I get an error at the end Error: Internal error. (Error code: 13) Please help me out
var reduced = withNDVI.mean().clip(shapefile)
.