1

Context: I'm trying to calculate forest cover for each districts in a province. I used the reducer function (frequency histogram) on a raster, using a feature collection object as its "cookie cutter".

Problem: The function works perfectly fine, but it spits out the output for the whole feature collection, and does not disaggregate it by features (the number is for the whole province, but what I need is the breakdown for each districts).

Here's the code that I used. Is there any way to use the reducer function and make the output disaggregated?

// IMPORT DATASETS
var aceh = ee.FeatureCollection("users/putraditama/AdministrativeBoundaries/Prov_Aceh") // Aceh boundary from asset
var districts = ee.FeatureCollection("users/putraditama/AdministrativeBoundaries/idn_adm2_2020");
var margono = ee.Image("users/putraditama/Margono_resized_reproject");

var acehdistricts = (districts)
            .filter(ee.Filter.eq("province","Aceh"));
            
// TEST ZONAL 
var acehstats = margono.reduceRegion({
  reducer: ee.Reducer.frequencyHistogram(),
  geometry: acehdistricts,
  // scale: 45,
  maxPixels: 1e15
});

print(acehstats)
Map.addLayer(acehdistricts, {}, 'Aceh')

1 Answer 1

1

This is simple: use reduceRegions instead of reduceRegion.

var acehstats = margono.reduceRegion({
  reducer: ee.Reducer.frequencyHistogram(),
  collection: acehdistricts,
});

The result will be a FeatureCollection where each feature has the reducer's outputs added as properties.

1
  • Well now I feel silly. That works flawlessly! Thank you! Commented Oct 5, 2021 at 3:27

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.