Using Hansen Global Forest Change Data to determine Forest Cover, Forest Gain, and Forest Loss (Study Area: Malaysia)

Forest change, especially forest loss, has become one of the major issues of the globe. There are several studies based on the global forest change. This tutorial uses  Hansen et al. (2013) Global Forest Change dataset available in Google Earth Engine data catalog to determine the Forest Cover, Forest Gain, and Forest Loss in Malaysia.

About Data

The Hansen et al. (2013) Global Forest Change dataset is the global forest change data at 30 meters resolution between 2000 and 2014. This data is available in Google Earth Engine data catalog for public use. This data is provided by University of Maryland, Department of Geography.

In this tutorial, we will learn how to determine Forest Cover, Forest Gain, and Forest Loss in Malaysia. This code is originally published in Google Earth Engine Tutorial. The code was modified as per the requirements of this tutorial. Learn more about Global Forest Change here:

Here is the code:

// source: https://developers.google.com/earth-engine/tutorial_forest_03
// Simple ImageCollection preview via animated GIF.
var countries = ee.FeatureCollection("ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw")
var country_name = ['Malaysia']
var country = countries.filter(ee.Filter.inList('Country', country_name));
Map.centerObject(country,5);  //Zoom to Study area

// Load the data and select the bands of interest.
var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015');
var lossImage = gfc2014.select(['loss']);
var gainImage = gfc2014.select(['gain']);

// Use the and() method to create the lossAndGain image.
var gainAndLoss = gainImage.and(lossImage);

// Show the loss and gain image.
//Map.addLayer(gainAndLoss.updateMask(gainAndLoss), {palette: 'FF00FF'}, 'Gain and Loss', false);

// Displaying forest, loss, gain, and pixels where both loss and gain occur.
var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015');
var lossImage = gfc2014.select(['loss']);
var gainImage = gfc2014.select(['gain']);
var treeCover = gfc2014.select(['treecover2000']);

// Use the and() method to create the lossAndGain image.
var gainAndLoss = gainImage.and(lossImage);

// Add the tree cover layer in green.
Map.addLayer(treeCover.updateMask(treeCover).clip(country),
    {palette: ['000000', '00FF00'], max: 100}, 'Forest Cover');

// Add the loss layer in red.
Map.addLayer(lossImage.updateMask(lossImage).clip(country),
    {palette: ['FF0000']}, 'Loss');

// Add the gain layer in blue.
Map.addLayer(gainImage.updateMask(gainImage).clip(country),
    {palette: ['0000FF']}, 'Gain');

// Show the loss and gain image.
Map.addLayer(gainAndLoss.updateMask(gainAndLoss),
    {palette: 'FF00FF'}, 'Gain and Loss', false);
    
//Quantifying Forest Change in a Region of Interest
// Get the forest loss image.
var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015');
var lossImage = gfc2014.select(['loss']);

// Sum the values of forest loss pixels in the Congo Republic.https://maps.gstatic.com/mapfiles/mv/imgs8.png
var stats = lossImage.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: country,
  scale: 30,
  maxPixels: 3e9
});
print(stats);
print('pixels representing loss: ', stats.get('loss'));

// //Calculating Pixel Areas
// Get the forest loss image.
var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015');
var lossImage = gfc2014.select(['loss']);
var areaImage = lossImage.multiply(ee.Image.pixelArea());

// Sum the values of forest loss pixels
var stats = areaImage.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: country,
  scale: 30,
  maxPixels: 1e9
});
print('pixels representing loss: ', stats.get('loss'), 'square meters');

// Get the loss image.
var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015');
var lossIn2012 = gfc2014.select(['lossyear']).eq(12);
var areaImage = lossIn2012.multiply(ee.Image.pixelArea());

// Calculate the area of loss pixels
var stats = areaImage.reduceRegion({
  reducer: ee.Reducer.sum(),
  geometry: country.geometry(),
  scale: 30,
  maxPixels: 1e9
});
print(
  'Area lost in '+ country_name,
  stats.get('lossyear'),
  'square meters'
);

var image = ee.Image().toByte()
    //.paint(country, 'fill') // Get color from property named 'fill'
    .paint(country, 1, 2); // Outline using color 3, width 5.
    
Map.addLayer(image, {palette: ['FE230D', '000000', '000000', '000000'], max: 0.5, opacity: 0.5,},"Boundary of "+country_name);

//Export Image
Export.image (treeCover, 'Forest_Cover', {region: country, fileFormat: 'PNG',maxPixels: 1206250905});
Export.image (lossImage, 'Forest_Loss', {region: country, maxPixels: 1206250905});
Export.image (gainImage, 'Forest_Gain', {region: country, maxPixels: 1206250905});


// Calculating Yearly Forest Loss
// Get the loss image.
// This dataset is updated yearly, so we get the latest version.
var gfc2017 = ee.Image('UMD/hansen/global_forest_change_2017_v1_5');
var lossImage = gfc2017.select(['loss']);
var lossAreaImage = lossImage.multiply(ee.Image.pixelArea());

var lossYear = gfc2017.select(['lossyear']);
var lossByYear = lossAreaImage.addBands(lossYear).reduceRegion({
  reducer: ee.Reducer.sum().group({
    groupField: 1
    }),
  geometry: country,
  scale: 30,
  maxPixels: 1e9
});
print(lossByYear);
// Notice that we are using the format() method to convert the year values from 0-14 to 2000-2014.
var statsFormatted = ee.List(lossByYear.get('groups'))
  .map(function(el) {
    var d = ee.Dictionary(el);
    return [ee.Number(d.get('group')).format("20%02d"), d.get('sum')];
  });
var statsDictionary = ee.Dictionary(statsFormatted.flatten());
print(statsDictionary);

//Making a chart
var chart = ui.Chart.array.values({
  array: statsDictionary.values(),
  axis: 0,
  xLabels: statsDictionary.keys()
}).setChartType('ColumnChart')
  .setOptions({
    title: 'Yearly Forest Loss',
    hAxis: {title: 'Year', format: '####'},
    vAxis: {title: 'Area (square meters)'},
    legend: { position: "none" },
    lineWidth: 1,
    pointSize: 3
  });
print(chart);
// Map.add(chart);



Map.add(ui.Label(
    'Forest Cover Map- ' +country_name,
    {
      fontWeight: 'bold', 
      //fontColors: 'red',
      BackgroundColor: '#FF0000',
      //.paint(roi, 'fill')
      fontSize: '14px'}));
      
// /************************ legend ****************************/
    
var names = ['Forest Cover', 'Forest Gained', 'Forest Lost'];
var values = [ '1', '2', '3' ];
var legendPalette = ['346A0A','0F3ADA','F8200B' ];

// set position of panel
var legend = ui.Panel({style: {position: 'bottom-center',padding: '8px 15px'}});
 
// Create legend title
var legendTitle = ui.Label({value: 'Forest Gain and Loss',
  style: {fontWeight: 'bold',fontSize: '18px', margin: '0 0 4px 0',padding: '0' }
});
 
// Add the title to the panel
legend.add(legendTitle);
var makeRow = function(color, name) {
 // Create the label that is actually the colored box.
  var colorBox = ui.Label({
    style: {
      backgroundColor: '#' + color,
      // Use padding to give the box height and width.
      padding: '8px',
      margin: '0 0 4px 0'
    }
  });

  // Create the label filled with the description text.
  var description = ui.Label({
    value: name,
    style: {margin: '0 0 4px 6px'}
  });

  // return the panel
  return ui.Panel({
    widgets: [colorBox, description],
    layout: ui.Panel.Layout.Flow('horizontal')
  });
};
 
// Add color and and names.
for (var i = 0; i < 3; i++) {
  legend.add(makeRow(legendPalette[i], names[i]));
  }  

// Add the legend to the map.
Map.add(legend);
Forest Cover Map – Malaysia

General Findings:

pixels representing loss: 63350380.768627495
pixels representing loss: 56507470944.91421 square meters 
Area lost in Malaysia: 6277731599.9299 square meters 
Yearly Forest Loss Chart (Malaysia)

Citations:

  • Hansen, M. C., P. V. Potapov, R. Moore, M. Hancher, S. A. Turubanova, A. Tyukavina, D. Thau, S. V. Stehman, S. J. Goetz, T. R. Loveland, A. Kommareddy, A. Egorov, L. Chini, C. O. Justice, and J. R. G. Townshend. 2013. “High-Resolution Global Maps of 21st-Century Forest Cover Change.” Science 342 (15 November): 850–53. Data available on-line at: http://earthenginepartners.appspot.com/science-2013-global-forest.

Leave a Reply

%d bloggers like this: