How to generate Histogram in Google Earth Engine?

Learning is fun and Google Earth Engine has made it more fun. Today, we will learn how to generate histogram in the Google Earth Engine.

Data Overview

The Global Multi-resolution Terrain Elevation Data 2010 (GMTED2010) dataset contains elevation data for the globe collected from various sources. The version of the dataset available here is Breakline Emphasis, 7.5 arc-seconds resolution. Breakline emphasis maintains the critical topographic features (streams or ridges) within the landscape by maintaining any minimum elevation or maximum elevation value on a breakline that passes within the specified analysis window. More details are available in the dataset report.

The primary source dataset for GMTED2010 is NGA’s SRTM Digital Terrain Elevation Data (DTED®, (void-filled) 1-arc-second data. For the geographic areas outside the SRTM coverage area and to fill in remaining holes in the SRTM data, the following sources were used: non-SRTM DTED®, Canadian Digital Elevation Data (CDED) at two resolutions, Satellite Pour l’Observation de la Terre (SPOT 5) Reference3D, National Elevation Dataset (NED) for the continental United States and Alaska, GEODATA 9 second digital elevation model (DEM) for Australia, an Antarctica satellite radar and laser altimeter DEM, and a Greenland satellite radar altimeter DEM.

This dataset replaces the GTOPO30 Elevation Model.

Here is the code:

// Select your country
var countries = ee.FeatureCollection("ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw")
var country_name = ['Nepal']
//var country_name = ['Kenya']
var country = countries.filter(ee.Filter.inList('Country', country_name));
Map.centerObject(country,7);  //Zoom to Study area
var image = ee.Image().toByte()
    //.paint(roi, 'fill') // Get color from property named 'fill'
    .paint(country, 2, 2); // Outline using color 3, width 5.
// Create a custom elevation palette from hex strings.
var elevationPalette = ['061E84','0DF83B', '1BB747','286107', 'F90B04', 'E6694D','EAB01E','F07B0E','CFCCCC','F7F9F9','F9F8F8'];
// Use these visualization parameters, customized by location.
var visParams = {min: -0, max: 7000, palette: elevationPalette};

// Plot a histogram of elevation

// Load a global elevation image.
//var elev = ee.Image('USGS/GMTED2010')

var elev = ee.Image('CGIAR/SRTM90_V4');
// Add the elevation to the map.
Map.addLayer(elev,  {}, 'elevation b/w');    
Elevation Map of Nepal.

Now add Histogram

// Generate the histogram data.  
var histogram = ui.Chart.image.histogram({
  image: elev,
  region: country,
  scale: 200,
  minBucketWidth: 300
  title: 'Histogram of Elevation (in meters) in '+country_name


Map.addLayer(elev.clip(country), visParams, 'Elevation Map of '+country_name);
//Map.setCenter(-107, 39, 6);

 /************************ Title ****************************/
    'Elevation Map of '+country_name,
      fontWeight: 'bold', 
      //fontColors: 'red',
      BackgroundColor: '09B3EC',
      //.paint(roi, 'fill')
      fontSize: '14px'}));
Histogram of Elevation (in meters) in Nepal.

%d bloggers like this: