You will need to define a list of years you are interested in, and map over that list to get a mean NDVI image for every year. Then use reduceRegion
on every image to obtain the mean NDVI value in the geometry. Export the resulting image collection as a table.
// Load collection and geometry
var Cambodia = geometry;
var collection = ee.ImageCollection('LANDSAT/LE07/C01/T1_32DAY_NDVI').select('NDVI');
// Declare years of interest
var years = ee.List.sequence(2000, 2010);
// Map a function to select data within the year and apply mean reducer
var byYear = ee.ImageCollection.fromImages(
years.map(function(y) {
var image = collection.filter(ee.Filter.calendarRange(y, y, 'year'))
.mean();
// get the mean value for each year
var meanDictionary = image.reduceRegion({ // use reduce region for single geometry
geometry: Cambodia,
reducer: ee.Reducer.mean(),
scale: 30,
});
//set data to image
return image.set(meanDictionary)
// add time information to image
.set('year', y,'system:time_start', ee.Date.fromYMD(y,1,1).millis())
})
);
// to test code printing, increase the scale or decrease size goemetry
// print(byYear)
// export the image collection as a table (CSV)
Export.table.toDrive(byYear,"NDVI","NDVI","NDVI_Cambodia");
link code
-- EDIT --
user requested the code for featurecollections:
// Map a function to select data within the year and apply mean reducer
var byYear = ee.FeatureCollection(years.map(function(y) {
var image = collection.filter(ee.Filter.calendarRange(y, y, 'year'))
.mean();
// get the mean value for each year
var newFC = image.reduceRegions({
// use reduceRegion for single geometry
// use reduceRegions for multiple features
collection: Cambodia,
reducer: ee.Reducer.mean(),
scale: 30,
tileScale : 1, // increase tileScale if running out of computation or export
}) // NOTE THAT THIS RETURNS A FEATURE COLLECTION, thus we map over the features to add date
.map(function(feat){
return feat.set('year', y,'system:time_start', ee.Date.fromYMD(y,1,1).millis());
});
// now we return the featurecollection, not the image
return newFC;
})
).flatten(); // flatten() the feature collection of feature collections
link code