I want to have NDVI values of landsat time series as feature collection to export the values as long format table in CSV. I use the Hansen Global Forest Change data set and the Landsat 7 time series. The Global Forest Change data set is transformed to a feature collection to specify the area of interest. The Landsat 7 time series is used to get the NDVI values over time.
After transforming landsat NDVI time series into a feature collection, no NDVI values appear. Transforming the time series into triplets only 'image ID' and 'timeMillis' appear. I already checked data type (both now int16) and projection (both EPSG:32638).
I would be grateful for any help. Is there anything I missed?
var lossImage = ee.Image('UMD/hansen/global_forest_change_2017_v1_5')
.select('lossyear')
.clip(geometry);
var datamask = ee.Image('UMD/hansen/global_forest_change_2017_v1_5')
.select('datamask')
.clip(geometry);
// specifying int16 and EPSG equivalent to landsat
var noloss = lossImage
.updateMask(lossImage.eq(0).and(datamask.eq(1)))
.int16()
.reproject('EPSG:32638', null, 30);
// create feat. collection to reduce regions of Landsat time series
var noloss_v = noloss.reduceToVectors({
reducer: ee.Reducer.countEvery(),
geometry: geometry,
scale: scale
});
//// functions for Landsat
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B4', 'B3'])
.rename('NDVI').int16();
return image.addBands(ndvi);
};
var LS7 = ee.ImageCollection('LANDSAT/LE07/C01/T1_RT_TOA')
.filterBounds(geometry)
.filterDate('2005-01-01', '2015-12-31')
.map(addNDVI)
.select('NDVI');
//// Export LS NDVI
var triplets = LS7.map(function(image) {
return image.reduceRegions({
collection: noloss_v.select('system:index'),
reducer: ee.Reducer.mean().setOutputs(image.bandNames()),
scale: 30,
}).map(function(feature) {
return feature.set({
'imageID': image.id(),
'timeMillis': image.get('system:time_start')
});});
}).flatten();
I found the missing command: After reducing one has to filter the 0 values using ".filter(ee.Filter.neq('NDVI', null))"
var triplets = LS7.map(function(image){
return image.reduceRegions({
collection: noloss_v.select('system:index'),
reducer: ee.Reducer.mean().setOutputs(image.bandNames()),
scale: 30,
}).filter(ee.Filter.neq('NDVI', null))
.map(function(feature) {
return feature.set({
'imageID': image.id(),
'timeMillis': image.get('system:time_start')
});
});
}).flatten();