I am trying to compute the total forest loss based on the Hansen dataset in Google Earth Engine.
I would like to know the total number of pixels lost per polygon of a shapefile imported as a feature collection.
The code runs and the tasks appear on the task tab, but when I run it I get an error:
Error: Feature, argument 'metadata': Invalid type. Expected: Dictionary. Actual: FeatureCollection.
This is my code:
var table = ee.FeatureCollection("users/alejandrofeged/Colombian-map");
Map.addLayer(table,{},"Colombia")
var image = ee.Image("UMD/hansen/global_forest_change_2017_v1_5")
.clipToCollection(table);
var lossImage = image.select(['loss']);
Map.addLayer(lossImage.updateMask(lossImage),
{palette: ['FF0000']}, 'Loss');
Export.image.toDrive({
image: lossImage,
description: 'GFW-2000-2017',
scale: 30,
region: table,
maxPixels: 8813288590
});
var means = lossImage.reduceRegions({
collection: table,
reducer: ee.Reducer.sum(),
scale: 30,
});
// Print the first feature, to illustrate the result.
print(ee.Feature(means.first()));
var feature = ee.Feature(null, means);
// Wrap the Feature in a FeatureCollection for export.
var forestloss = ee.FeatureCollection([feature]);
// Export the FeatureCollection.
Export.table.toDrive({
collection: forestloss,
description: 'forestloss',
fileFormat: 'CSV'
});