Compute EVI using Expressions in Google Earth Engine

SHARE:

Master expressions in Google Earth Engine to perform pixel-wise calculations and build custom remote sensing analyses.

Google Earth Engine (GEE) is a powerful platform for processing and analyzing geospatial data at a planetary scale. A core component of GEE's functionality is the ability to use expressions. Expressions allow you to perform complex calculations on image pixels, enabling a wide range of remote sensing analyses. This article will guide you through the use of expressions in Google Earth Engine, providing a practical example of how they can be used to calculate a vegetation index.

EVI  Expression in Google Earth Engine using Modis


What This Script Does in Google Earth Engine

This Google Earth Engine script demonstrates how to use the expression() function to calculate the Enhanced Vegetation Index (EVI) from MODIS surface reflectance data. The expression() function allows you to define a mathematical formula using band names as variables. The script loads a MODIS image, applies a scaling factor, and then uses an expression to compute EVI. This example showcases the flexibility and power of GEE's expression capabilities for performing custom calculations on image data.

GEE Code Sample

// Compute Enhanced Vegetation Index (EVI) over the MODIS MOD09GA product
// using an expression.

// Load a MODIS image and apply the scaling factor.
var img = ee.Image('MODIS/006/MOD09GA/2012_03_09').multiply(0.0001);

// Compute EVI using an expression.  The second argument is a map from
// variable name to band name in the input image.
var evi = img.expression(
    '2.5 * (nir - red) / (nir + 6 * red - 7.5 * blue + 1)',
    {
        red: img.select('sur_refl_b01'),    // 620-670nm, RED
        nir: img.select('sur_refl_b02'),    // 841-876nm, NIR
        blue: img.select('sur_refl_b03')     // 459-479nm, BLUE
    });

// Center the map.
Map.setCenter(-94.84497, 39.01918, 8);

// Display the input image and the EVI computed from it.
Map.addLayer(img.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03']),
            {min: 0, max: 0.2}, 'MODIS bands 1/4/3');
Map.addLayer(evi, {min: 0, max: 1}, 'EVI');

Step-by-Step Explanation: Using the Expression Function

Here's a breakdown of how the expression() function is used in this code:

  1. Load the Image:

    var img = ee.Image('MODIS/006/MOD09GA/2012_03_09').multiply(0.0001);

    This line loads a MODIS image and applies a scaling factor. The result is stored in the img variable, which is an ee.Image object. This image will be used as the input for the expression.

  2. Define the Expression:

    '2.5 * (nir - red) / (nir + 6 * red - 7.5 * blue + 1)'

    This is a string that represents the mathematical formula for calculating EVI. Note that instead of using band names directly, it uses the variables red, nir, and blue. These variables will be mapped to actual band values in the next step.

  3. Map Variables to Bands:

    {
        red: img.select('sur_refl_b01'), // 620-670nm, RED
        nir: img.select('sur_refl_b02'), // 841-876nm, NIR
        blue: img.select('sur_refl_b03') // 459-479nm, BLUE
    }

    This JavaScript object is the second argument to the expression() function. It creates a mapping between the variables used in the expression string (red, nir, blue) and the corresponding bands in the img image. For example, red: img.select('sur_refl_b01') tells GEE to get the values from the 'sur_refl_b01' band of the img image and use those values whenever the variable red is encountered in the expression.

  4. Calculate EVI:

    var evi = img.expression(..., ...);

    The img.expression() function takes the expression string and the variable mapping as input. It then performs the calculation for each pixel in the img image, using the specified bands. The result is a new ee.Image where each pixel contains the calculated EVI value. This new image is stored in the evi variable.

Applications

Expressions in Google Earth Engine are incredibly versatile and can be applied to a wide range of applications, including:

  • Vegetation Index Calculation: As demonstrated in the example, expressions can be used to calculate various vegetation indices (e.g., NDVI, EVI, SAVI) from multispectral imagery.
  • Band Arithmetic: Perform basic arithmetic operations (addition, subtraction, multiplication, division) between different bands of an image.
  • Image Transformation: Apply mathematical functions (e.g., logarithms, exponentials, trigonometric functions) to image pixel values.
  • Unit Conversion: Convert pixel values from one unit to another (e.g., from digital numbers to physical units like reflectance or temperature).
  • Spectral Analysis: Combine spectral bands to highlight specific features or materials.
  • Custom Indices: Create custom indices tailored to specific applications or research questions.
  • Data Masking: Use conditional statements within expressions to mask out unwanted pixels (e.g., clouds, water).

Visualization Example

To visualize the result of the expression (the EVI calculation):

  1. Run the provided script in the Google Earth Engine Code Editor.
  2. Observe the EVI layer overlaid on the map. The EVI values, derived from the expression, will be displayed with a color gradient representing vegetation health.
  3. Take a screenshot of the EVI visualization in the Code Editor.
  4. Upload this screenshot to your Blogger post, ensuring you add descriptive alt text.
Example of EVI visualization derived from a GEE expression

Example of EVI visualization derived from a GEE expression.


Notes

  • Scaling Factors: It's crucial to apply any necessary scaling factors to the input bands before using them in an expression, as shown in the example.
  • Band Names: Pay close attention to band names and ensure they match the names used in the img.select() function.
  • Data Types: Be mindful of data types. Expressions typically work with numerical data.
  • Error Handling: GEE will report errors in your expression if there are syntax errors or invalid operations.
  • Complex Expressions: You can create very complex expressions with multiple operations and functions, but keep them organized for readability.
  • EE Functions in Expressions: While many basic mathematical operators are available, some Earth Engine functions may not be directly usable within an expression.

📚 References



Prepared by: Jamal Chaaouan | GEE Academy @ GeoJamal.com

COMMENTS

Name

CHIRPS,1,Climate,1,Cloud masking,1,DEM,1,EVI,3,Export,2,Fire forest,1,Forest,1,GEE,1,GEE Academy,3,GEE script,1,Image analysis,6,JRC,1,Landsat,1,LST,1,MODIS,4,NDVI,5,NOAA,1,remote sensing,2,Sentinel,2,Sentinel-2,1,Snow,1,SRTM,3,temperature,1,time series,1,vegetation index,3,VIIRS,1,
ltr
item
GEE Academy: Compute EVI using Expressions in Google Earth Engine
Compute EVI using Expressions in Google Earth Engine
Master expressions in Google Earth Engine to perform pixel-wise calculations and build custom remote sensing analyses.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwPh_kX4Gq6eIzVAod02zHbJr1I2TSepqWXqMx2h6AvrJ_st6_166bh9IHWM00BCBvNYTLysgZiXEwaNHFL5fzF7KnLZHFom-e57ZrPG6qa68dr3Kaj7ecSK_RrRAMnnSwIpuxNM68a14y6lgyvTXNqMzqP0mfNn-5m4Tk45SeVkmwCbjsBSLo38Ol710/w640-h326/EVI-MODIS-GEE-GEOJAMAL-SCRIPT.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwPh_kX4Gq6eIzVAod02zHbJr1I2TSepqWXqMx2h6AvrJ_st6_166bh9IHWM00BCBvNYTLysgZiXEwaNHFL5fzF7KnLZHFom-e57ZrPG6qa68dr3Kaj7ecSK_RrRAMnnSwIpuxNM68a14y6lgyvTXNqMzqP0mfNn-5m4Tk45SeVkmwCbjsBSLo38Ol710/s72-w640-c-h326/EVI-MODIS-GEE-GEOJAMAL-SCRIPT.png
GEE Academy
https://gee.geojamal.com/2025/04/compute-evi-using-expressions-in-google.html
https://gee.geojamal.com/
https://gee.geojamal.com/
https://gee.geojamal.com/2025/04/compute-evi-using-expressions-in-google.html
true
3421025227311197355
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content