0

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.

1 Answer 1

0

Specify the name you want on the reducer via setOutputs and skip the renaming step.

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.