1

I am new to Google Earth Enginge and I struggle to bring together two images in Google Earth Engine to get the areas which are in both images and the areas which are only part of one image to show forest cover change (loss, gain, no change).

My code so far which seems to at least display what I want by stacking the images above each other:

var treeCanopyCoverVis = {
  min: 0.0,
  max: 100.0,
  palette: ['ffffff', 'afce56', '5f9c00', '0e6a00', '003800'],
};

var forest2000 = ee.ImageCollection('NASA/MEASURES/GFCC/TC/v3')
  .filterDate('2000-01-01', '2000-12-31')
  .select('tree_canopy_cover')
  .reduce(ee.Reducer.mean());

var forest2000_ab60 = forest2000.gt(60).selfMask();
Map.addLayer(forest2000_ab60, {palette: '#d80078'}, 'Loss');

var forest2015 = ee.ImageCollection('NASA/MEASURES/GFCC/TC/v3')
  .filterDate('2015-01-01', '2015-12-31')
  .select('tree_canopy_cover')
  .reduce(ee.Reducer.mean());

var forest2015_ab60 = forest2015.gt(60).selfMask();
Map.addLayer(forest2015_ab60, {palette: '#ebb13a'}, 'Gain');

// var loss = forest2015_ab60.intersection(forest2000_ab60);

print(forest2015_ab60);
print(forest2000_ab60);

var remain = forest2015_ab60.and(forest2000_ab60);
Map.addLayer(remain, {palette: '#746d75'}, 'Remain');

With this code the gain still includes the remain part and the loss part also still includes the remain part. I need kind of the subtraction. All functions I now tried result in errors. I appreciate any help!

How my current result looks:

enter image description here

Saskia
  • 23
  • 4

1 Answers1

0

I could somehow solve it with try and error. The code:

var forest2000 = ee.ImageCollection('NASA/MEASURES/GFCC/TC/v3')
  .filterDate('2000-01-01', '2000-12-31')
  .select('tree_canopy_cover')
  .reduce(ee.Reducer.mean());

var forest2015 = ee.ImageCollection('NASA/MEASURES/GFCC/TC/v3')
  .filterDate('2015-01-01', '2015-12-31')
  .select('tree_canopy_cover')
  .reduce(ee.Reducer.median());

var gain = forest2000.lt(60).and(forest2015.gt(60));
Map.addLayer(gain.selfMask(), {palette: '#ebb13a'}, 'gain');

var loss = forest2000.gt(60).and(forest2015.lt(60));
Map.addLayer(loss.selfMask(), {palette: '#d80078'}, 'loss');

var nochange = forest2000.gt(60).and(forest2015.gt(60));
Map.addLayer(nochange.selfMask(), {palette: '#746d75'}, 'no change');
Saskia
  • 23
  • 4