1

After classify using randomForest my image

var imagemClassificada = addBands2018.select(bands).classify(classificadorTreinado)

I would like to calculate the area for each class, vegetation and pasture.

var area_classifyed = imagemClassificada.multiply(ee.Image.pixelArea())
                      .reduceRegion(ee.Reducer.sum(),VEGETACAO,30,null,null,false,1e13)
                      .get('constant')
print('VEGETATION AREA: ', ee.Number(area_classifyed).divide(1e6))

Focus that I use the FeatureCollection of 'VEGETACAO' to calculate this.

But, after all, I get some error:

Provided visualization parameters are not an object: geometry in , line 3515

This is the correct form to calculate the area em Earth Engine? HERE goes my code

1

The error you get comes from line 2 in your code. You defined a name as input for the visualization parameters. It should be:

Map.addLayer(geom,{},'geometry');

You can calculate the area of each class in the image using a grouped reducer. Each group will then get a group number (namely, the number of the class it has on the classified image) and the associated reducer output (which is the summed area). I increased the scale parameter to increase speed of the calculations.

// get the surface covered by each classified tree
var area_classifyed = ee.Image.pixelArea().divide(1e6).addBands(imagemClassificada).reduceRegion({
  reducer: ee.Reducer.sum().group(1, 'group'),
  geometry: geom,
  scale: 1000,
  maxPixels: 10e10
});
var outputReducers = ee.List(area_classifyed.get('groups'));
print('area of each class',outputReducers);
print('area of study site',geom.area().divide(1e6));

link script

  • Thanks for really help me! – Lilian Guimarães Apr 4 at 11:38
  • the measurement value is m²? – Lilian Guimarães Apr 4 at 12:30
  • The value returned for each class is quite different than expected in reality. To test, I count the pixel values for each class, using the .count () method. In this way the values are closer to the expected (multiplying by the size value of the LANDSAT area, to which I multiplied by 0.09 x 10000). I believe that this way you taught me, the calculation is not correct because you stop using ".multiply" before using "ee.Image.pixelArea ()". [link] (code.earthengine.google.com/af32aee683516ac3243671098b07779b) goes the code – Lilian Guimarães Apr 4 at 16:28
  • if you devide by 1e6 (which I did in my example because that's in your question), the area is in km². – Kuik Apr 5 at 9:26

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.