0

I am attempting to calculate the area of 5 different classes in my classified map. GEE tutorials showed me a method (https://developers.google.com/earth-engine/tutorial_forest_03#calculating-pixel-areas), however I struggled to apply it because I dont understand how to select a specific class before using .reduceRegion to calculate area because the example is quite different to my map.

Can someone guide me through how to calculate area, whether using the same method, or another?

Here's the link to my map: https://code.earthengine.google.com/1171bdeecd776800b334a49f60d5d443

Here is my code

var image=ee.Image('LANDSAT/LC08/C01/T1_SR/LC08_169062_20180205');

//define parameters

var green = image.select('B3');
var swi = image.select('B6');
var mndwi = green.subtract(swi).divide(green.add(swi)).rename('MNDWI');

var mndwipara = {min: 0, max: 0.7, palette: ['white', 'blue']};


Map.addLayer(mndwi, mndwipara, 'MNDWI');


//apply threshold to select only positive pixels 
var lake_mask= mndwi.gt(0);
Map.addLayer(lake_mask);


//classification attempt - scum
var scum=image.expression(
'(nir)*0 + (nir < 0.018)*1', {
'nir': image.select('B5'),
'red': image.select ('B4'),
'green': image.select('B3'),
});

//classification attempt - sediment
var sediment=image.expression(
'(nir)*0 + (nir > 0.018 && red > green && green/nir < 1.3 && red/green> 
nir/red)*1', {
'nir': image.select('B5'),
'red': image.select ('B4'),
'green': image.select('B3'),
 });

//classification attempt - lowbiomass
var lowbiomass=image.expression(
'(nir)*0 + (nir > 0.018 && red < green && green > 0.065 && nir < red)*1', {
'nir': image.select('B5'),
'red': image.select ('B4'),
'green': image.select('B3'),
 });


//classification attempt-scum
var scum=image.expression(
'(nir)*0 + (nir > 0.018 && red < green && green > 0.065 && nir > red && nir/red > 4.07)*1', {
'nir': image.select('B5'),
'red': image.select ('B4'),
'green': image.select('B3'),
 });

//classifcation attempt bleached scum
var bleached_scum=image.expression(
'(nir)*0 + (nir > 0.018 && red > green && green/nir > 1.3 && green > 0.065)*1', {
'nir': image.select('B5'),
'red': image.select ('B4'),
'green': image.select('B3'),
});

//classification attempt - microphytobenthos
var microphytobenthos=image.expression(
'(nir)*0 + (nir > 0.018 && red > green && green/nir < 1.3 && red/green< nir/red)*1', {
'nir': image.select('B5'),
'red': image.select ('B4'),
'green': image.select('B3'),
 });

//classification attempt - highbiomass
var highbiomass=image.expression(
'(nir)*0 + (nir > 0.018 && red < green && green > 0.065 && nir > red && nir/red < 4.07)*1', {
 'nir': image.select('B5'),
 'red': image.select ('B4'),
'green': image.select('B3'),
 });

/*
lake = 1
scum = 2
bleached_scum = 3
microphytobenthos = 4
highbiomass = 5
sediment

*/


var lake_mask_ = ee.Image(1).mask(lake_mask).toInt();
var scum_ = ee.Image(2).mask(lake_mask.mask(scum)).toInt();
var bleached_scum_ = 
ee.Image(3).mask(lake_mask.mask(bleached_scum)).toInt();
var microphytobenthos_ = 
ee.Image(4).mask(lake_mask.mask(microphytobenthos)).toInt();
var biomass_ = ee.Image(5).mask(lake_mask.mask(highbiomass)).toInt();

 var test = ee.ImageCollection([lake_mask_,scum_,bleached_scum_,microphytobenthos_,biomass_,]);

 var test = test.reduce(ee.Reducer.max());

 print(test);  
 Map.addLayer(test,{min: 1, max: 5, palette: ['0000FF', 
 '1BCFFF','66ff33','F4FF0B','FA0007']},'Classification');
2

Assuming all categories are 'inside' the water mask, I'd something like

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

lake_mask = lake_mask.updateMask(lake_mask)

var lake_mask_ = lake_mask.multiply(area).select([0],['lake']);
var scum_ = lake_mask.updateMask(scum).multiply(area).select([0],['scum']);
var bleached_scum_ = lake_mask.updateMask(bleached_scum).multiply(area).select([0],['bleached_scum']);
var microphytobenthos_ = lake_mask.updateMask(microphytobenthos).multiply(area).select([0],['microphytobenthos']);
var biomass_ = lake_mask.updateMask(highbiomass).multiply(area).select([0],['highbiomass']);

var area_image = lake_mask_.addBands(scum_)
                     .addBands(bleached_scum_)
                     .addBands(microphytobenthos_)
                     .addBands(biomass_)

var areas = area_image.reduceRegion({
  reducer:ee.Reducer.sum(),
  geometry: image.geometry(),
  scale: 30,
  maxPixels:1e13
})
print(areas)

Area is expressed in hectares (dividing pixel area by 10000)

  • Because there is another lake next to mine, which the classification automatically is imposed on, are the pixels for that second counted within the area? If so, is there a way to find the area specifically for my one lake? Thanks in advance – Isaaqm Mar 20 '18 at 10:46
  • Create a Feature containing only the area you want to get the data from, and then change the geometry param of reduceRegion for that Feature's geometry (customfeature.geometry()) – Rodrigo E. Principe Mar 20 '18 at 11:04
  • when i combine the area of the different classes (680km), it is greater than the overall area(380km). Do you know how to correct this? code.earthengine.google.com/6fec6f9208d132a3f1e974217fe7cfe0 – Isaaqm Mar 29 '18 at 15:43
  • @Isaaqm, I've seen your issue in another question you asked, but when I added every class separately did not match the classification, so it was a bit of work and didn't have much time to analyse, next week I could. – Rodrigo E. Principe Mar 29 '18 at 16:43
  • I managed to solve the problem so no need, but thank you for trying! – Isaaqm Mar 30 '18 at 11:01

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.