I'm working with Dynamic World and am building functions that calculate zonal statistics of different land cover properties over time. In the code below, I have a binary image called for_2017 which is equal to 1 if the pixel is forested, else zero. I want to take the mean for each tile in tiles, a feature collection where each feature has 1 degree resolution.
function zonalStatMaker(mapObj) {
//Calculate zonal stats
var zonalStat = tiles.map(function(feature) {
return feature.set(mapObj.reduceRegion({
reducer: 'mean',
geometry: feature.geometry(),
scale: 10,
maxPixels: 1e9
}));
});
//Rename variable
var zonalStat = zonalStat.map(function(feat){
return ee.Feature(feat.geometry(), {
mapObj: feat.get('constant'),
});
});
return zonalStat;
}
var tiles = zonalStatMaker(for_2017);
print(tiles.limit(1));
I believe the image reducer component is working fine. But I want the property (the mean forest 2017 variable) stored in tiles to be the same name as the mapObj object. When I tried this code, the function named the property "mapObj".
Full code here.