I am working with the Hansen Global Forest Change loss year layer. This raster tells us the year a 30m pixel transitioned to zero forest cover (2000-2014), if relevant (otherwise zero).
I am producing zonal statistics over tiles and am trying to get the within-tile count of pixels that transitioned in 2001, 2002, 2003, ...2014. These counts must be stored as separate properties (ex: count_2001 = x, count_2002=y.
I can execute this over my tiles year-by-year using a remap function and then counting the non-NA values using a reducer function. For example, for 2001:
var gfcLoss2001 = gfcLossYearMasked
.remap([1], [1], null);
//Need to change band name so future bands do not overwrite each other
var gfcLoss2001Clean = gfcLoss2001.select(
['remapped'], ['loss2001']);
var loss2001 = tiles.map(function(feature) {
return feature.set(gfcLoss2001Clean.reduceRegion({
reducer: 'count',
geometry: feature.geometry(),
scale: 100,
}));
});
I am trying to transform this into a function that I can feed a vector of dates [2001, 2002, ...] and corresponding reference numbers [1, 2, 3] (where 1=2001 in the raster) that can execute this code over the 13 years. The main challenge I encounter is with variable naming. We need to give the generated properties (counts) unique names, but I don't know how to incorporate this into GEE.
If you have alternative strategies for producing these zonal stats, please let me know as well.