Calculating Statistics with reduceRegion in Google Earth Engine

SHARE:

Use reduceRegion in Google Earth Engine GEE to extract the maximum elevation from SRTM data within a defined rectangle— a spatial statistics tool.

Google Earth Engine (GEE) provides powerful tools for summarizing image data over specific geographic areas. The reduceRegion function is a key tool for this, allowing you to calculate statistics like the mean, maximum, or sum of pixel values within a defined region. This article will guide you through a GEE script that demonstrates how to use reduceRegion to compute the maximum elevation value within a rectangular area using SRTM elevation data.

Google Earth Engine Script and results

What This Script Does

This Google Earth Engine script calculates the maximum elevation within a user-defined rectangular region using the reduceRegion function. It loads an SRTM elevation image, defines a rectangular geometry, and then uses reduceRegion with the ee.Reducer.max() reducer to find the highest elevation value within that rectangle. The result is printed to the console as a dictionary. The script also adds the image and the rectangle to the map for visualization.

Google Earth Engine (GEE) Code Sample


// ..The input image to reduce, in this case an SRTM elevation map.
var image = ee.Image('CGIAR/SRTM90_V4');
Map.addLayer(image);
// The region to reduce within.
var poly = ee.Geometry.Rectangle([-109.05, 41, -102.05, 37]);
Map.addLayer(poly);
// Reduce the image within the given region, using a reducer that
// computes the max pixel value.  We also specify the spatial
// resolution at which to perform the computation, in this case 200
// meters.
var max = image.reduceRegion({
  reducer: ee.Reducer.max(),
  geometry: poly,
  scale: 200
});
// Print the result (a Dictionary) to the console.
print(max);

Step-by-Step Explanation of the Google Earth Engine Code:

  1. Load the SRTM elevation image:

    var image = ee.Image('CGIAR/SRTM90_V4');

    This line loads the SRTM 90m Digital Elevation Model (DEM) into a variable named image. This image contains the elevation data that will be used for the reduction.

    Map.addLayer(image); adds the image to the map for visualization.

  2. Define the region of interest:

    var poly = ee.Geometry.Rectangle([-109.05, 41, -102.05, 37]);

    This line defines a rectangular region of interest (ROI) using the ee.Geometry.Rectangle constructor. The coordinates [-109.05, 41, -102.05, 37] specify the West, South, East, and North longitudes and latitudes of the rectangle, respectively.

    Map.addLayer(poly); adds the rectangle to the map for visualization.

  3. Reduce the image:

    var max = image.reduceRegion({ ... });

    This is the core of the script. It calls the reduceRegion method on the image to calculate a statistic within the defined region.

    • reducer: ee.Reducer.max(): This specifies the reducer to use. ee.Reducer.max() calculates the maximum pixel value within the region. Other reducers are available for calculating other statistics (e.g., ee.Reducer.mean(), ee.Reducer.sum(), ee.Reducer.min()).
    • geometry: poly: This specifies the geometry (the rectangle defined earlier) over which the reduction is performed.
    • scale: 200: This parameter defines the spatial resolution (in meters) at which the reduction is performed. In this case, the image is resampled to 200-meter pixels before the maximum value is calculated. This is important for performance and can affect the result.
  4. Print the result:

    print(max);

    The reduceRegion function returns a dictionary containing the calculated maximum value. This line prints the dictionary to the console. The dictionary key will be the name of the band (in this case, 'elevation'), and the value will be the maximum elevation within the specified rectangle.

Datasets Used

  • SRTM 90m Digital Elevation Model: (CGIAR/SRTM90_V4)
    • This dataset provides the elevation data used for the reduction.

Applications

The reduceRegion function is highly versatile and can be used in numerous applications, including:

  • Calculating zonal statistics: Extracting statistics (e.g., mean elevation, average temperature, total rainfall) for administrative zones, watersheds, or other geographic regions.
  • Summarizing land cover: Determining the proportion of different land cover types within a specific area.
  • Analyzing image collections: Calculating statistics across a time series of images for a given region.
  • Validating model results: Comparing model predictions to observed data aggregated over a region.
  • Extracting pixel values: Getting the values of specific pixels within a defined geometry.

Visualization Example

The script displays the SRTM elevation image and the rectangular region of interest on the map. The actual result (the maximum elevation value) is printed to the console. To see the result, you would need to open the console in the Google Earth Engine Code Editor.

Google Earth Engine Script and results

The results of reduceRegion are showing in the console.

Notes

  • The scale parameter is crucial. A smaller scale (higher resolution) will generally provide more accurate results but will take longer to compute.
  • The geometry parameter can be any ee.Geometry object.
  • You can use different reducers (e.g., ee.Reducer.mean(), ee.Reducer.min(), ee.Reducer.sum(), ee.Reducer.stdDev()).
  • If the input image has multiple bands, the reduceRegion function will calculate the statistic for each band.
  • For complex reductions, combine multiple reducers.

Related Articles :  



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: Calculating Statistics with reduceRegion in Google Earth Engine
Calculating Statistics with reduceRegion in Google Earth Engine
Use reduceRegion in Google Earth Engine GEE to extract the maximum elevation from SRTM data within a defined rectangle— a spatial statistics tool.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaNKzyBs_EEhk1Ev1ATQ3302RgxP30OFL_hkwFulz0tWNiF1qWFI4NXvqt10kLETRuirmJ036P79wGlmFORTA6cQwXbzMBKKQIGpmAWeN7LmyFPKD2CnbEDtGZc_yMeyj_J52aJx1sTXBJnqi8E2iNwsLzbmOh346qzS_5rqtqOUMv3mouqXOnd8bPXSU/w640-h406/REDUCEREGION-GEE-GEOJAMAL.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaNKzyBs_EEhk1Ev1ATQ3302RgxP30OFL_hkwFulz0tWNiF1qWFI4NXvqt10kLETRuirmJ036P79wGlmFORTA6cQwXbzMBKKQIGpmAWeN7LmyFPKD2CnbEDtGZc_yMeyj_J52aJx1sTXBJnqi8E2iNwsLzbmOh346qzS_5rqtqOUMv3mouqXOnd8bPXSU/s72-w640-c-h406/REDUCEREGION-GEE-GEOJAMAL.png
GEE Academy
https://gee.geojamal.com/2025/04/calculating-statistics-with.html
https://gee.geojamal.com/
https://gee.geojamal.com/
https://gee.geojamal.com/2025/04/calculating-statistics-with.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