I am trying to get annual forest loss using the Hansen dataset in Google Earth to get a video. I have added the yearly loss image to the map to try to see if by 2018 it matched the main "loss" layer but it doesn't (Red are annual loss images and yellowish is the total loss layer). I think I am not doing the mask correctly but I haven't figured out why.

Here's my code:

var GUA_Pet = ee.FeatureCollection("users/andrealiralo/GUA_PET");
Map.centerObject(selected, 8);

// Collection
var gfc2018 = ee.Image('UMD/hansen/global_forest_change_2018_v1_6').clipToCollection(selected);

var prj = gfc2018.projection();
var scale = prj.nominalScale();

var treeCover = gfc2018.select(['treecover2000']);
var treeLoss = gfc2018.select(['loss']);
var lossyear = gfc2018.select(['lossyear']);

var treeLoss = treeLoss.mask(treeLoss);
var treeGain = treeGain.mask(treeGain);
var lossyear = lossyear.mask(lossyear);

Map.addLayer(treeCover, {palette: ['000000', '#37c756'], max: 100}, 
'Forest Cover 2000');
Map.addLayer(treeLoss, {palette: ['#cbd71d']}, 'Loss');

// %%%%%% ANNUAL LOSS %%%%%%%%%%%
var years = ee.List.sequence(01, 18).getInfo();
var annual_loss = years.map(function(year){
  var mask_treeLoss_yy = lossyear.eq(year); 
  var treeLoss_yy = treeLoss.updateMask(mask_treeLoss_yy); 

  Map.addLayer(treeLoss_yy, {palette: ['FF0000']}, 'Loss Year 

  var treeLoss_yy_proj = treeLoss_yy.reproject(prj.atScale(scale))

  return treeLoss_yy_proj

enter image description here The video doesn't work, something to do with the projection that also haven't solved but the layers do show up.

  • Welcome to GIS SE. AS a new user, please take the Tour. Programming questions are required to have code in the question body (not just a link), representing the snippet that reproduces the problem, with a clear description of the error or other problem (since you are referencing appearance, a screenshot would be appropriate). – Vince Apr 26 '20 at 16:46

If you reproject() the change image upfront, you'll get the expected results:

var gfc2018 = ee.Image('UMD/hansen/global_forest_change_2018_v1_6').clipToCollection(selected)
  .reproject('EPSG:4326', null, 30)

Now, why that is needed, I don't know. I'd be very happy to have someone else chip in on that. Here's a simpler script reproducing this effect. It looks like lossyear isn't set for all loss. But if you reproject() or zoom-in to native scale, things look as expected.

var change = ee.Image('UMD/hansen/global_forest_change_2018_v1_6')
  // .reproject('EPSG:4326', null, 30)

var loss = change.select('loss').selfMask()
var lossyear = change.select('lossyear').selfMask()


Map.addLayer(loss, {palette: 'yellow'}, 'loss')
Map.addLayer(lossyear, {palette: 'red'}, 'lossyear')
Map.setCenter(-89.832, 16.594, 7)


  • Thanks a lot! I did see that when zooming in "lossyear" changed but I thought it was a resolution issue. – an1234 Apr 27 '20 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.