# Calculating area on a globe

**URL:** <https://community.cesium.com/t/calculating-area-on-a-globe/886>\
**Category:** CesiumJS\
**Created:** [December 19, 2013, 9:05pm UTC](https://community.cesium.com/t/calculating-area-on-a-globe/886 "2013-12-19T21:05:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lydia\_Lei](https://avatars.discourse-cdn.com/v4/letter/l/ee59a6/32.png) [@Lydia\_Lei](https://community.cesium.com/u/Lydia_Lei)\
**Post date:** [December 19, 2013, 9:05pm UTC](https://community.cesium.com/t/calculating-area-on-a-globe/886/1 "2013-12-19T21:05:11Z")

</div>

Hi,

Does Cesium have a method to calculate the area of a polygon or shape on the surface of the earth? I know how to do it on a 2D plane, but what about 3D? When a user places a shape on the map (either using polyline or polygon), I want to be able to show the perimeter and area of each shape.

Thanks for your help!  
Lydia

---

<div class="post-metadata">

**Author:** ![patrick](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/patrick/32/2045_2.png) [@patrick](https://community.cesium.com/u/patrick)\
**Post date:** [December 20, 2013, 4:19pm UTC](https://community.cesium.com/t/calculating-area-on-a-globe/886/2 "2013-12-20T16:19:00Z")

</div>

Lydia,

Cesium doesn’t have a function to do this, but the Polygon used for visualization divides the polygon in small triangles that approximate the curvature of Earth (based on the granularity input). You could sum up the area of all the triangles.

See createGeometryFromPositions in [PolygonGeometry.js](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/PolygonGeometry.js).

Patrick

---

<div class="post-metadata">

**Author:** ![Lydia\_Lei](https://avatars.discourse-cdn.com/v4/letter/l/ee59a6/32.png) [@Lydia\_Lei](https://community.cesium.com/u/Lydia_Lei)\
**Post date:** [January 7, 2014, 5:40pm UTC](https://community.cesium.com/t/calculating-area-on-a-globe/886/3 "2014-01-07T17:40:48Z")

</div>

Thanks, Patrick. I will look into this solution.

Do you know if Cesium will be implementing any type of area calculation in the near future? I am also looking to calculate the area of rectangles, squares, circles, etc. on the surface of the earth.

Thanks,  
Lydia

---

<div class="post-metadata">

**Author:** ![patrick](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/patrick/32/2045_2.png) [@patrick](https://community.cesium.com/u/patrick)\
**Post date:** [January 7, 2014, 6:10pm UTC](https://community.cesium.com/t/calculating-area-on-a-globe/886/4 "2014-01-07T18:10:32Z")

</div>

Lydia - we don’t have plans to do this soon. However, the method I suggested will work for all regions on the globe.

Patrick

---

<div class="post-metadata">

**Author:** ![David\_Whipps](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/david_whipps/32/3522_2.png) [@David\_Whipps](https://community.cesium.com/u/David_Whipps)\
**Post date:** [September 7, 2016, 2:11pm UTC](https://community.cesium.com/t/calculating-area-on-a-globe/886/5 "2016-09-07T14:11:38Z")

</div>

Hey All,

I just worked on this myself and used the following. (It’s rough, but gives a pretty good approximation.)

// Get the polygon from your “entity”  
var polygon = theEntity.polygon;

var hierarchy = polygon.hierarchy.\_value;

// “indices” here defines an array, elements of which defines the indice of a vector

// defining one corner of a triangle. Add up the areas of those triangles to get  
// an approximate area for the polygon

var indices = Cesium.PolygonPipeline.triangulate(hierarchy.positions, hierarchy.holes);

var area = 0; // In square kilometers

for (var i = 0; i \< indices.length; i += 3) {

var vector1 = hierarchy.positions[indices[i]];

var vector2 = hierarchy.positions[indices[i+1]];

var vector3 = hierarchy.positions[indices[i+2]];

// These vectors define the sides of a parallelogram (double the size of the triangle)

var vectorC = Cesium.Cartesian3.subtract(vector2, vector1, new Cesium.Cartesian3());

var vectorD = Cesium.Cartesian3.subtract(vector3, vector1, new Cesium.Cartesian3());

// Area of parallelogram is the cross product of the vectors defining its sides

var areaVector = Cesium.Cartesian3.cross(vectorC, vectorD, new Cesium.Cartesian3());

// Area of the triangle is just half the area of the parallelogram, add it to the sum.

area += Cesium.Cartesian3.magnitude(areaVector)/2.0;

}

``

Hope that helps.

- Dave
