0

I am trying to use Hansen forest change dataset to identify the forest loss area across years for all states of India. I have a "lossYear band" where each pixel in the lossYear band contain values from 0 to 18 indicating the year in which the loss occurred.I want to use a grouped reducer, specifying the band index of the grouping band (1) so the pixel areas will be summed and grouped according to the value in the lossYear band. This works well for a single geometry but how do i do the same for multiple polygons. Check code below. I am trying to recreate this lab ( https://www.geospatialecology.com/emm_lab_7/) for multiple features/states.

my code is as follows. It throws an error stating "unrecognized arguments"

var gfc2021 = ee.Image('UMD/hansen/global_forest_change_2021_v1_9');
var treeCover = gfc2021.select(['treecover2000']);
var lossImage = gfc2021.select(['loss']);
var gainImage = gfc2021.select(['gain']);

var level0 = ee.FeatureCollection("FAO/GAUL/2015/level0");
var level1 = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level1");

var India = level0.filter(ee.Filter.eq('ADM0_CODE',115));
var IndianStates = level1.filter(ee.Filter.eq('ADM0_CODE',115));

// Add the tree cover layer in green.
Map.addLayer(treeCover.updateMask(treeCover),
    {palette: ['000000', '00FF00'], max: 100}, 'Forest Cover');

// Add the loss layer in red.
Map.addLayer(lossImage.updateMask(lossImage),
            {palette: ['FF0000']}, 'Loss');

// Add the gain layer in blue.
Map.addLayer(gainImage.updateMask(gainImage),
            {palette: ['0000FF']}, 'Gain');
            
// Load country boundaries from LSIB.
var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');
// Get a feature collection with just the Malaysia feature. Country codes here: https://en.wikipedia.org/wiki/List_of_FIPS_country_codes#I
var malay = countries.filter(ee.Filter.eq('country_co', 'MY'));

// Get the loss image.
// This dataset is updated yearly, so we get the latest version.

var lossAreaImage = lossImage.multiply(ee.Image.pixelArea());

var lossYear = gfc2021.select(['lossyear']);
var lossByYear = lossAreaImage.addBands(lossYear).reduceRegions({
  collection:IndianStates,
  reducer: ee.Reducer.sum().group({
    groupField: 1
    }),
  scale: 30,
  maxPixels: 1e9
});
//print(lossByYear);

1 Answer 1

1

As the error message says, reduceRegions doesn't have a maxPixels argument. Just remove it.

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.