I am trying to export the loss pixels from the Hansen/UMD dataset for each year from 2001-2014, for a region. I hope to obtain a stack of 13 rasters (one for each year), with a pixel having 0 or 1 in each of those rasters. My intent is then to run some sort of trend analysis of the loss 2001-2014.
As of now I have the following code, which loads the lossYear band and the geography in the form of a fusion table, reduces the lossYear image to the geography and iterates across the years 1-14.
// Load Hansen tree cover
var gfcImage = ee.Image('UMD/hansen/global_forest_change_2015');
var lossYear = gfcImage.select(['lossyear']);
var scale = 100
//Sequence of years for which we need to extract loss
var years = ee.List.sequence(1, 14) //2001 to 2014 based on v1.2 of UMD dataset
// Load India border
var statesIndia = ee.FeatureCollection('ft:13fekwKFyNB2IIEgpdN156LdWpMcXohQzZ3kjzQ');
Map.setCenter(78.9629,20.5937)
var addVar = function(feature) {
// function to iterate over the sequence of years
var addVarYear = function(year, feat) {
// cast var
year = ee.Number(year).toInt()
feat = ee.Feature(feat)
// actual year to write as property
var actual_year = ee.Number(2000).add(year)
// filter year:
// 1st: get mask
var filtered = lossYear.select("lossyear").eq(year)
// 2nd: apply mask
filtered = lossYear.updateMask(filtered)
// reduce variables over the feature
var reduc = filtered.reduceRegion({
geometry: feature.geometry(),
reducer: ee.Reducer.sum(),
scale: scale
})
// get results
var loss = ee.Number(reduc.get(lossYear))
// set names
var nameloss = ee.String("loss_").cat(actual_year)
// alternative 2: always set property
// set properties to the feature
return feat.set(nameloss, loss)
}
// iterate over the sequence
var newfeat = ee.Feature(years.iterate(addVarYear, feature))
// return feature with new properties
return newfeat
}
// Map over the FeatureCollection
var lossIndiastack = statesIndia.map(addVar);
Map.addLayer(lossIndiastack, {}, "lossIndiastack")
But I get the error lossIndiastack: Layer error: String: Unable to convert object to string. And then I need to figure out how to export the stack.
Can anyone help me figure out the error and provide a solution?