1

I have a feature collection of sub-districts in sub-Saharan Africa:

var Africa = ee.FeatureCollection
('users/salem043/Africa_Districts').select("ADM3");


I'm also using the Global Forest Change data:

var gfc2014 = ee.Image('UMD/hansen/global_forest_change_2015').clip(Africa);

I am trying to produce annual estimates of square meters of forest cover loss by subdistrict. The following code worked when I did this for countries, not subdistricts:


//Identifies the year in which the pixel transitioned
var lossYear = gfc2014.select(['lossyear']);

var lossByYear = lossAreaImage.addBands(lossYear) 
  .reduceRegions({ 
  reducer: ee.Reducer.sum().group({groupField: 1}),
  collection: Africa, 
  scale: 30
});


var addGroups = function(feature) {
  var statsFormatted = ee.List(feature.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());

  return feature.set(statsDictionary);
};

print("Final forest loss df", lossByYear.map(addGroups).limit(10))
lossByYear = lossByYear.map(addGroups)

But when I run it for the subdistricts, there are many missing observations. The code should produce thirteen new variables for each subdistrict: forest loss in 2001, 2002, 2003, ...2014. But the number of new variables produced varies across sub-districts! For some, only a few year variables are produced, while for others, we're a lot closer to having a complete panel.

Is this a missing data issue? Should I assume forest loss is zero in those years for those subdistricts where no variable is produced?

Moreover, when I exported this data, only two year forest loss variables exported: 2013 and 2014.

Code in GEE is here.

1 Answer 1

2

When exporting, GEE will sample the properties present for the first feature and will only export that properties (except system properties). You can manually change the properties in the selectors argument of Export.table.toDrive. If you print the first feature, you will see the properties present:

print(lossByYear.first().propertyNames())

For you case, when there would be no forest loss, I guess the loss of area in that year should be 0. Subsequently, I think it is most straightforward to first make a featureCollection Africa with all properties set to zero. Then apply you function and years with forest loss will be overwritten:

// preset all properties to 0
var keys = ee.List.sequence(0,14,1).map(function(year){
  return ee.Number(year).format("20%02d");
});
var preSetPropsAfrica = Africa.map(function(feat){
  return feat.set(ee.Dictionary.fromLists(keys,ee.List.repeat(0,15)));
});

Now run with this featureCollection exactly what you did and all properties in all feature will have a value. Printing a subset seems to work, please let me know if exporting works for you! Link code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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