# Surface area calculation in Google Earth Engine?

Using this code, I've extracted water extent in a Landsat median image. But how can I compute water area extent?

``````var urmia = table;

Map.centerObject(urmia);

var landsat = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(urmia)
.filterDate('2018-01-01','2019-01-01')
.filter(ee.Filter.lessThan('CLOUD_COVER',5))
.median()
.clip(urmia)
.select('B[4-5]')
.normalizedDifference(['B4','B5'])
.gt(0.2)
.rename('time2');

``````

Has Lake Urmia shrunk dramatically? In the following code, I convert all pixels above your NDWI threshold to 1 and and everything else to 0. That way you can apply a region reducer to sum all of the values in the region, which in essence is the number of "positive" pixels. If LS8 pixels are 30mx30m, multiply the sum by 30^2 to get total number of square meters, and convert to square kilometers. That leads to a calculated area of ~2477 square kilometers, which is way less than Google's reporting of 5200 square kilometers...

Edit: Updated code to implement `ee.Image.pixelArea()` rather than back-of-the-envelope math. Turns out the water-covered region is ~1956 km^2.

``````var urmia = table;

Map.centerObject(urmia);

};

var landsat = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(urmia)
.filterDate('2018-01-01','2019-01-01')
.filter(ee.Filter.lessThan('CLOUD_COVER',5))
.median()
.clip(urmia)
.select('B[4-5]')
.normalizedDifference(['B4','B5'])
.gt(0.2)
.rename('time2');

print("Landsat",landsat);

// Convert pixels with water to 1
var LS_to0 = h20.expression(
'0 * LS', {
'LS': h20
});
var LS_to1 = LS_to0.expression(
'1 + LS', {
'LS': LS_to0
});
// Visualize

// Calculate pixel area
var LS_PA = LS_to1.multiply(ee.Image.pixelArea());

// Print sum
var stats = LS_PA.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: table,
scale: 30,
maxPixels: 1e13
});

print(stats);
``````
• thanks for your help. but I think ee.image.pixelArea() is more accurate than your methodology. Have a look to this link, please: developers.google.com/earth-engine/… – Johny Astine Feb 24 '19 at 11:29
• @JohnyAstine I had no idea ee.image.pixelArea() existed! Thanks for sharing; see updated code. – JepsonNomad Feb 24 '19 at 19:29