I am doing supervised classification of 5 different classes, I tried the code suggested in GEE tutorial but I can't able to understand the way they did. I am attaching my code here. Could someone guide me how to calculate the area of different classes? And I want the area of my study region only it is attached as a n asset (tri).

Can we extract our study region (tri - shapefile) from the Landsat image (mosaic)?

Here is the link to my map https://code.earthengine.google.com/037ea5a6e8240d4d292f0149e1fb996e

Here is my code:

// filter image classification
var image= ee.Image(ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')

print (image);

var Trivandrum = ee.Image ('LANDSAT/LC08/C01/T1_SR/LC08_144054_20140126');
var Trivandrum1 = ee.Image ('LANDSAT/LC08/C01/T1_SR/LC08_143054_20150122');

var mosaic = ee.ImageCollection.fromImages([Trivandrum,Trivandrum1]).mosaic();
var composite = {
  bands: ['B2','B3','B4'],
  gamma: 1,
  max: 0.80,
  min: 0.04


var newfc = urban.merge(agriculture).merge(waterbodies).merge(wetland_coastal).merge(forest);
print(newfc, 'newfc');

// Select the bands to be used in training
var bands = ['B2', 'B3', 'B4', 'B5','B6','B7'];

// Sample the input imagery to get a FeatureCollection of training data.
var training = mosaic.select(bands).sampleRegions({
  collection: newfc,
  properties: ['landcover'],
  scale: 30  // should reflect the scale of your imagery, the scale is 30 meters
var trained = ee.Classifier.cart().train(training, 'landcover', bands);

// Classify the image with the same bands used for training.
var classified_ = mosaic.select(bands).classify(trained);

var palette = [
  'FF0000', // urban
  '008000', // agriculture
  '0000FF', //  water bodies
  'E3BC1E',   //coastal areas
  '1EE363', // forest 


Map.setCenter(76.98244, 8.4686, 11); 

Map.addLayer (mosaic, composite); 
Map.addLayer (classified_, {min: 0, max: 5, palette: palette}, 'Land Use Classification');

var geometry = ee.Geometry.Polygon(
          [[[76.2593, 8.8932],
          [76.4076, 8.0402],
          [77.314, 8.915],
          [77.4897, 8.2686]]]);

  image: classified_,
  description: 'Trivandrum_mosaic',
  scale: 30,
  region: geometry,
  crs: 'EPSG:4326',
  folder: 'GEE',
  maxPixels: 10000000000000

closed as too broad by Andre Silva, xunilk, Vince, Kadir Şahbaz, Erik Mar 25 at 12:16

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


You can add the following to the end of your code. You'll need to define geometry to be your ROI and ensure that it overlaps the classified image:

var options = {
  lineWidth: 1,
  pointSize: 2,
  hAxis: {title: 'Classes'},
  vAxis: {title: 'Area m^2'},
  title: 'Area by class',
  series: {
    0: { color: 'red'},
    1: { color: 'green'},
    2: { color: 'blue'}

var areaChart = ui.Chart.image.byClass({
  image: ee.Image.pixelArea().addBands(classified),
  classBand: 'classification', 
  region: geometry,
  scale: 30,
  reducer: ee.Reducer.sum()
  .setSeriesNames(['urban', 'vegetation', 'water']);

Not the answer you're looking for? Browse other questions tagged or ask your own question.