Calculate NDVI and export

Published on May 19, 2020 | Bikesh Bade | 1624 Views

Normalized Difference Vegetation Index (NDVI) quantifies vegetation by measuring the difference between near-infrared (which vegetation strongly reflects) and red light (which vegetation absorbs).


You can export images, map tiles, tables, and videos from Earth Engine. The exports can be sent to your Google Drive account, to Google Cloud Storage, or to a new Earth Engine asset.


Step 1: Import two sentinel-2 images


var s2 = ee.ImageCollection('COPERNICUS/S2')
                  .filterDate('2019-01-01', '2019-12-30')
                  .filter('CLOUDY_PIXEL_PERCENTAGE', 20))
                  .filterBounds(studyArea); //choose your own study Area



Step 2: Calculate the NDVI


//  Normalized difference vegetation index (NDVI)
function getNDVI (image) {
    var ndvi = image.normalizedDifference(['B8','B4']).rename("ndvi");
    image = image.addBands(ndvi);
    return image;



Step 3: Add images to the map


//create composite with reducer median
s2 = s2.median();

//get NDVI
s2 = getNDVI(s2).clip(studyArea);

//select NDVI layer 
var s2NDVI ='ndvi');

//get infromation of the images

// visualization
var ndviVis = {
  min: 0.0,
  max: 0.8,
  palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'

var rgbVis = {
  min: 0.0,
  max: 0.3,
  bands: ['B4', 'B3', 'B2'],

//add to map
Map.centerObject(studyArea, 9);
Map.addLayer(s2, rgbVis, 'Sentinel');
Map.addLayer(s2NDVI, ndviVis, 'NDVI');



Step 4: Export


  image: s2NDVI,
  description: 'NDVI',
  region: studyArea,


Get the code in the link


Adnane Labbaci

How can you export the result directly to your computer, not to your drive

  • May 31, 2020 |

Leave your comment