1

I have an ImageCollection derived from the MCD64A1.006 MODIS Burned Area Monthly Global 500m dataset available in Google Earth Engine. I've clipped it to the boundary of a national forest in California:

Burned pixels within National Forest boundary

My goal is to count the number of red pixels within the boundaries of that national forest shapefile and then the total number of pixels within the shapefile to calculate the proportion of area burned. I've tried using code from a previous project, excerpted below, that would allow me to count each burned pixel with a system:index property, which they all have:

var burnStat = burnedSGSB.reduceRegions({
  collection: SGSB,
  reducer: ee.Reducer.countEvery().group({
    groupName: 'system:index',
  }),
  scale: 500
});

I suspect this has something to do with there being many images associated with that given pixel, but: What is the correct reducer needed to derive my target information, and what is preventing the above code from working?

Link to the full code is here: https://code.earthengine.google.com/52917210ff19b3f6c300ce7d295e2261

1

Here is a working example:

// Load Butte County, CA.
var butteCo = ee.Feature(ee.FeatureCollection("TIGER/2016/Counties")
  .filter(ee.Filter.eq('COUNTYNS', '01675842'))
  .first());

// Load burned area image.
var modisBurn = ee.Image("MODIS/006/MCD64A1/2018_11_01")
  .select('BurnDate')
  .clip(butteCo);

// Display county and burn area on Map.
Map.addLayer(butteCo, null, 'Butte County, CA');
Map.addLayer(modisBurn.gt(0), {min: 0, max: 1, palette: 'red'}, 'Burn');

// Get projection and scale information.
var proj = modisBurn.projection();
var scale = proj.nominalScale();
print('Projection', proj);
print('Scale (m)', scale);

// Get the area of Butte county.
var butteCoArea = butteCo.area(1);
print('Butte Co area (m^2)', butteCoArea);

// Count all of the valid pixels in the MODIS burn layer.
var burnNdict = modisBurn.reduceRegion({
  reducer: ee.Reducer.count(),
  geometry: butteCo.geometry(),
  scale: scale,
  crs: proj});

// Calculate percent of Butte Co burned for selected MCD64A1 period.
var burnPixelsN = burnNdict.getNumber('BurnDate');
var burnPixelsArea = burnPixelsN.multiply(scale.pow(2));
var burnAreaPrct = burnPixelsArea.divide(butteCoArea).multiply(100);
print('Percent of Butte County burned:', burnAreaPrct);

Code Editor script: https://code.earthengine.google.com/5f60e7d41e3e2e42ac69bac6bae77cd3

reduceRegion(s) is an Image method, so you must either filter the MODIS collection to a single image or reduce the collection by a statistic. To count pixels, use the ee.Reducer.count() reducer.

1
  • This is perfect--thank you!
    – Michael
    Nov 9 '19 at 23:57

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.