1

Is this possible to get 30 years of greenest pixel, NDVI annual mean and median data for a particular coordinate without changing the dates manually for every single year?

Currently, I am using the following code and manually changing the annual time frame to get the value. And how to export this data set in.csv file.

var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');
var spatialFiltered = l8.filterBounds(point);
print('spatialFiltered', spatialFiltered);
var temporalFiltered = spatialFiltered.filterDate('2015-01-01', '2015-12-31');
print('temporalFiltered', temporalFiltered);
var sorted = temporalFiltered.sort('CLOUD_COVER');
var scene = sorted.first();

// Get the least cloudy image for 2015.

var image = ee.Image(
    l8.filterBounds(point)
        .filterDate('2015-01-01', '2015-12-31')
        .sort('CLOUD_COVER')
        .first()
);

// (NDVI).

var nir = image.select('B5');
var red = image.select('B4');
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');

//the result.

Map.centerObject(image, 9);
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(ndvi, ndviParams, 'NDVI image');
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
shekhar
  • 11
  • 2

1 Answers1

0

You can use the mapping function to calculate the annual NDVI as the Image Collection. Here's how you can do it using Google Earth Engine.

var point = ee.Geometry.Point([-122.44210030630455, 37.73518696319849]);
Map.centerObject(point, 9);

var l8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA');

var years = ee.List.sequence(2013, 2019);

var leastCloudIC = ee.ImageCollection(years.map(function (y) {
    return ee.Image(
        l8.filterBounds(point)
          .filterDate(ee.Date.fromYMD(ee.Number(y), 01, 01), 
                      ee.Date.fromYMD(ee.Number(y), 12, 31))
          .sort('CLOUD_COVER').first()
    );
}));

var annualNDVI = leastCloudIC.map(function (img) {
    return img.normalizedDifference(['B5', 'B4']).rename('NDVI').set('system:time_start', img.get('system:time_start'));
});

var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
var ndvi2015 = annualNDVI.filterDate('2015-01-01', '2015-12-31').first();
Map.addLayer(annualNDVI.filterDate('2015-01-01', '2015-12-31').first(), ndviParams, 'ndvi 2015');

Here's the GEE script for the same.

Biplov Bhandari
  • 390
  • 3
  • 18
  • It worked for me, but is there any possible code to calculate annual median data? And how to export that data into .csv file – shekhar Dec 06 '19 at 01:52