1

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?

1
  • Just use reduceRegions instead of trying to map reduceRegion on your own. Oct 30, 2021 at 12:42

1 Answer 1

1

I found out a solution mapping your original SE_FireHistory Image Collection as list. As your Fedlands_SE Feature Collection has 316 elements, most of them outside the area of interest, for greatly reducing the computation time, I implemented a function to intersect these Feature Collection with EVT geometry. Resulting Feature Collection had only 41 features and processing time was reduced widely.

This last Feature Collection was used for obtaining all relevant NAMES in ROI and it was the basis for mapping and to get All_Burn_Hectares_by_LC_ANF. An extract of code can be observed as follows. Full code here.

var All_Burn_Hectares_by_LC_ANF = NAMES.map(function (ele){

  // DEFINE A BOUNDARY FOR GROUPED REDUCTIONS
  var ANF = Fedlands_SE.filterMetadata('ORIG_NAME','equals', ele);
  //Map.addLayer(ANF,{}, ee.String(NAMES));

  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

  // 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_list.map(function (image) {
  var year = ee.Image(image).get('year');
  var idx = ee.Image(image).get('system:index');
  // CONVERT IMAGE TO PIXEL AREA IN HECTARES
  var burnedArea = ee.Image.pixelArea().divide(10000).updateMask(ee.Image(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',
  }),
  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, 'system:index': idx, 'id': idx});
  });
  
  var outFc = ee.FeatureCollection(asList);
  return asList;
  }).flatten();

  return Landsat_Annual_Burn_Hectares_by_LC_ANF;

}).flatten();

print (All_Burn_Hectares_by_LC_ANF);

 Export.table.toDrive({
   collection: ee.FeatureCollection(All_Burn_Hectares_by_LC_ANF),
   description:'Landsat_Annual_Burn_Hectares_by_LC_ANF',
   folder: 'GEE_Downloads',
   fileFormat: 'CSV'
 });

After running link code in GEE code editor, it was printed in Console Tab 3619 features for ROI. Running task produced a CSV file with desired structure (3619 records). Part of 3619 records can be observed with LibreOffice Calc in following image.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.