I would like to know if it is possible to calculate the area resulting from a classification. he been reviewing some sections, I found this

Calculating areas of different classes in Google Earth Engine?

but I can't understand the approach very well

// Traemos una imagen
var imagen = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")


var REAL = {
  bands: ['B4', 'B3', 'B2'],
  min: 0,
  max: 2000

var sorteo = imagen.sort('CLOUD_COVER');
var sorteada = ee.Image(sorteo.first());

var image = sorteada.clip(geometry);

// NDVI de la imagen 2018 usando expresiones
var ndsi = image.expression("(G - NIR) / (G + NIR)",{
  "G": image.select("B3"),
  "NIR": image.select("B6")

var pal_ndsi = {
  min: 0,
  max: 1,
  palette: ["#1F73EE","#41D3F4","#E2FA33","#FF0000"]

Map.addLayer(image,REAL, 'sorteada');
Map.addLayer(ndsi,pal_ndsi, 'NDSI');


var feature_hielo = ee.Feature(hielo).set({class:0});
var feature_nubes = ee.Feature(nubes).set({class:1});
var feature_suelo = ee.Feature(suelo).set({class:2});
var feature_vegetacion = ee.Feature(vegetacion).set({class:3});
var feature_agua = ee.Feature(agua).set({class:4});

var fc = ee.FeatureCollection([feature_hielo,feature_nubes,feature_suelo,feature_vegetacion,feature_agua]);

var training = image.sampleRegions({
  collection: fc,
  properties: ['class'],
  scale: 30

// Con la función ee.Classifier.svm("Opciones de clasificador") se inicia el clasificador
// Es una Máquina de Soporte Vectorial (svm)
// Pero se pueden usar otras
// Las opciones están por defecto

// var classifier = ee.Classifier.svm();
// var classifier = ee.Classifier.naiveBayes();
//var classifier = ee.Classifier.minimumDistance();
var classifier = ee.Classifier.randomForest(30);

var S2Bands = ['B2','B3','B4'];

var trained = classifier.train(training, 'class', S2Bands);

var classified = image.classify(trained);

var pal = ["#FFFFFF","#AFABAB","#E2B407","#7EF03D","#6C88E6"];

var area = ee.Image.pixelArea().divide(10000);


Map.addLayer(classified, {min: 0, max: 4,palette: pal}, 'Clasificacion');
  • That is the pixels count converted to area units – Oscar Aug 8 at 2:33
  • But is it applicable to my case? – Cristian Urbano Aug 8 at 4:02

Your Answer

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

Browse other questions tagged or ask your own question.