2

I have used the following function to calculate the area of an area of interest (AOI) of a classification using landsat8 images. This counts the area in square meters of the classification for a given polygon.

var areaChart = ui.Chart.image.byClass({
  image: ee.Image.pixelArea().addBands(lista_imagenes[0]),
  classBand: 'classification', 
  region: geometry,
  scale: 30,
  reducer: ee.Reducer.sum()
});

The problem is that the band of classification of landsat8 is just one (classification band). And the layer I am using has three layers (it is call year of loss).

There is any way to count the classes of the layer given a polygon using a similar question?

Here the code: https://code.earthengine.google.com/495ed315756b7181b4570546be82e2f4

1 Answer 1

0

I just found the way to solve the problem, everything is in the following link (google documentation).

https://developers.google.com/earth-engine/tutorial_forest_03a

Here is the relevant part (with .reduceRegion()):

// Load country boundaries from LSIB.
var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');
// Get a feature collection with just the Congo feature.
var congo = countries.filter(ee.Filter.eq('country_co', 'CF'));

// Get the loss image.
// This dataset is updated yearly, so we get the latest version.
var gfc2017 = ee.Image('UMD/hansen/global_forest_change_2017_v1_5');
var lossImage = gfc2017.select(['loss']);
var lossAreaImage = lossImage.multiply(ee.Image.pixelArea());

var lossYear = gfc2017.select(['lossyear']);
var lossByYear = lossAreaImage.addBands(lossYear).reduceRegion({
  reducer: ee.Reducer.sum().group({
    groupField: 1
    }),
  geometry: congo,
  scale: 30,
  maxPixels: 1e9
});
print(lossByYear);

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.