• Daniel Romero-Alvarez

Google Earth Engine for vegetation indexes

Updated: Oct 31


Make sure to also check the tutorial on how to download SOILGRIDS data (chemical and physical properties of soil) using Google Earth Engine. ​​


There are plenty of tutorials on how to use this amazing tool from Google. It basically gives you the power to analyze huge amounts of satellite data in seconds thanks to their open servers. Also, it is completely free. You need, of course, an account with Google, but after that, the process to gain access to the interface is simple.

Here, my intention is to create a letter to my future self (…and potential readers) on how to implement a pipeline to obtain satellite information. This tutorial, should be seen as an update on my most popular post, the one about processing MODIS images using the MTR (MODIS reprojection tool), deprecated by NASA but potentially still in handy for non-programmers.

Let’s dive into it. First, some familiarity with GEE code editor:

GEE interface has four sections:

Section A: It has the tabs 'Scripts', 'Docs', and 'Assets'. The latter will allow you to upload shape files in your working repository. A demonstration on how to create new projects, open scripts, and upload shapefiles will be available below.

Section B: This is the main area for coding. The script available in this tutorial should be pasted in this section.

Section C: It has the tabs 'Inspector', 'Console', and 'Tasks'. In 'Console', you will be able to follow the actions of the script whenever you are PRINTING the created variables. 'Tasks' tab will be crucial to upload results to Google Drive and to follow activities such as uploading a shapefile or watching plots.

Section D: The MapViewer. Here you can see the outputs of your code in real time, whenever you are opting to visualize your variables in the corresponding map. The red arrow in the left corner of the MapViewer is pointing towards the tools to build polygons in real time. You can use these tools to clip any particular region of the map that you are interested in studying.

In the following video I am showing how to start a repository to write or paste any particular script. The video will show:

  1. Creation of a repository and a new script space.

  2. Add a polygon using the available tools.

  3. Upload a shape file and visualize it in the MapViewer.

  4. Notice that these processes involve the interaction of the four sections of GEE. Specifically, we use the 'Assets' tab (A in figure) to upload a shapefile, 'Tasks' tab to check the variable (C in figure), and finally, we manipulate it and export it to the MapViewer (B and D in the figure).

For this exercise we are going to obtain the mean EVI values for 2021 in a specific study area in Eastern Europe at 250 meters of spatial resolution. The code is fully commented and it is going to do the following:

  1. Add the study area for visualization purposes.

  2. Collect all the images from the MOD13Q1

  3. Select the bands corresponding to EVI

  4. Obtain the images corresponding to 2021

  5. Obtain the average across EVI images for 2021

  6. Visualize the information in the MapViewer

  7. Export the created layer to Google drive.

You can copy and paste the following code:


//This tutorial allows the creation of a raster layer of vegetation.

//Specifically, we are going to obtain the mean values of vegetation across 2021

//using the Enhanced Vegetation Index (EVI) from the MODIS sensor that is on board the

//TERRA and AQUA satellites.

//You can search for specific satellite products using the available catalog:


//We will use EVI version 6.0 at 250 meters of resolution:


//adding first layer for visualization purposes:

//This area was selected for a particular study and can be uploaded as shown

//in the tutorial available in the video above.

Map.addLayer (s_area, {}, 's_area', true)

print ('s_area', s_area)

//importing image collection:

//here we are uploading 520 images available for the MOD13Q1 products

var mod13q1 = ee.ImageCollection("MODIS/006/MOD13Q1")

print ('mod13q1', mod13q1)

//Each of the 520 images have multiple bands. However we are only

//interested in the EVI band. We use select to only isolate the bands of our interest

//Although we still have 520 images, each image only has one band.

var mod13q1_evi = mod13q1.select('EVI');

print ('mod13q1_evi', mod13q1_evi)

//filter image collection by time:

//We are going to obtain all the images corresponding to 2021 as we

//are looking for the average across that year. For that we use filter.Date

//and define an interval as shown.

var range_2021 = mod13q1_evi.filterDate('2021-01-01', '2021-12-19')

print ('range_2021', range_2021)

//Calculating the means of the image collection

//This process to obtain statistics across different images is called: REDUCTION

//An example of reduction procedures can be found here:


var mean2021 = range_2021.mean()

print ('mean2021', mean2021)


//parameters for visualizing any particular product in the MapViewer

//are usually available with the GEE product being analyzed

var pal = [

'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',

'74A901', '66A000', '529400', '3E8601', '207401', '056201',

'004C00', '023B01', '012E01', '011D01', '011301']

// Add image layer to the map for visualization purposes:

Map.addLayer(mean2021, {

min: 0, max: 8000, palette: pal},

'mm2021'); //change name

Map.addLayer (s_area, {}, 's_area', true)

print ('s_area', s_area)



image: mean2021, //the variable to be written

description: 'mean2021', //change name accordinglly

folder: 'Anthrax_Margarida', // Google Drive folder where the raster will be exported

region: s_area, //shapefile to clip the area to be exported. It can be a geometry as well.

scale: 1000, //resolution of the pixels in METERS, 30 means hiper resolution, 1000 = 1km

crs: 'EPSG:4326',

maxPixels: 1e12}); //maximum variables of pixels accepted

//Click RUN on the TASK section of the code editor website (C in the figure) to actually complete the upload of the //output to your specific Google Drive folder

//If the amount of pixels is too large (for example while asking for vegetation indexes worldwide,

//multiple rasters are going to be created that you might want to join using function such as

//MERGE in R. A way to effectively merge rasters in R can be read in this other tutorial.

//End of the script


Check the video, literally just copy and paste the code presented above.

This process might be seen as 'super easy, barely an inconvenience', and precisely because of that, you will be tempted to approach to this or other satellite imagery with the mythical: click-click-click-reward…However, I will encourage you to read--as always--a couple of publications and the fantastic book (recommended by Luis E. Escobar) on how to implement remote sensing in your work:



The figure depicts the average of vegetation in 2021 using the EVI as seen in the MapViewer of Google Earth Engine.

148 views0 comments