# 3D surface area with Google Earth Engine

I have my region of interest as a polygon. When I calculate the surface area I get a '2D value' (ie as if it was a flat surface). The problem is, the region is quite full of hills, so the real surface area would be significantly different because all the slopes make my 2D value a serious underestimation.

I thought I could download DEM, clip it to my polygon, and then calculate the real, 3D surface area from it. How can I do this? I've seen this question but for other tools (eg using QGIS and ArcGis).

But I want to do everything entirely in Python (or JavaScript) without installing QGIS.

Can you suggest a way to do this using Google Earth Engine?

## 1 Answer

Earth Engine does not support 3D geometry calculations, but you could use `ee.Terrain.slope` to get the slope at each pixel (computed from the differences with adjacent pixels in a DEM) and then divide the “flat” pixel areas by the cosine of the slope angle, which will compensate for the flattening.

Here's a quick demo based on editing the Earth Engine “Hillshade” example code

``````function radians(img) {
return img.toFloat().multiply(Math.PI).divide(180);
}

var slope = ee.Terrain.slope(ee.Image('CGIAR/SRTM90_V4'));

var adjustedArea = ee.Image.pixelArea().divide(radians(slope).cos());

Map.setCenter(-121.767, 46.852, 11);
Map.addLayer(slope, {min: 0, max: 90}, "Slope");
Map.addLayer(adjustedArea, {min: 0, max: 10000}, "Surface Area");

print("Projected area (m²):", ee.Image.pixelArea().reduceRegion({
reducer: ee.Reducer.sum(),
geometry: roi,
scale: 50,
}).get("area"));
print("Surface area (m²):", adjustedArea.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: roi,
scale: 50,
}).get("area"));
``````

https://code.earthengine.google.com/5f43d2c9afdddbde2e6f6be0a1ecabb5

I haven't confirmed that this produces an accurate result. And, of course, just like the length of a coastline, the answer will get bigger the finer the scale you compute it at.