Using an example from Google Developers (Grouped Reductions and Zonal Statistics), I was able to write a script that calculates burned area within land cover classes of a national forest... link to full code. I added a .map()
function that allows the analysis to be calculated for every image in the collection so that I can get area burned each year.
// USE A GROUPED SUM REDUCER FOR EVERY YEAR IN THE LANDSAT COLLECTION
// RETURNS A FEATURE COLLECTION WITH ANNUAL BURNED AREA (HECTARES) FOR EACH LANDCOVER CLASS WITHIN THE AOI
var Landsat_Annual_Burn_Hectares_by_LC_ANF = SE_FireHistory.map(function(image) {
var year = image.get('year')
// CONVERT IMAGE TO PIXEL AREA IN HECTARES
var burnedArea = ee.Image.pixelArea().divide(10000).updateMask(image.neq(0))
// ADD EVT BAND
burnedArea = burnedArea.addBands(EVT)
// SAMPLE EACH ANNUAL RASTER WITHIN EVERY FIRE REGION TO OBTAIN SUM OF HECTARES FOR EACH YEAR
var sums = burnedArea.reduceRegion({
reducer: ee.Reducer.sum().group({
groupField: 1,
groupName: 'code',
}),
// WANT TO LOOP IN DIFFERENT GEOMETRIES HERE
geometry: ANF.geometry(),
scale: 30,
maxPixels: 1e8
})
var asList = ee.List(sums.get('groups')).map(function (pair) {
return ee.Feature(null, pair).set('year',year);
});
var outFc = ee.FeatureCollection(asList)
return outFc
}).flatten();
Now I want to loop (map) in a FeatureCollection (federal land boundaries) so that I can get these results for every feature, and then merge the results into a singular variable with each record containing landcover, year, sum of hectares, and name of boundary. I have gotten this far, but I am struggling to figure out how to map in the FeatureCollection and get the results in a format for export.
Any ideas?