# Measuring the distance if terrain is ON

**URL:** <https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057>\
**Category:** CesiumJS\
**Created:** [August 30, 2021, 7:25am UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057 "2021-08-30T07:25:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashi](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/shashi/32/3649_2.png) [@Shashi](https://community.cesium.com/u/Shashi)\
**Post date:** [August 30, 2021, 7:25am UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057/1 "2021-08-30T07:25:25Z")

</div>

Dear Team,  
I’m trying to measure the distance of the given two points it provides the correct result but if the terrain is on then the length should be changed in hilly area’s but still, it’s providing the same distance. Is there any other way to get the distance between two points if the terrain is on? My code is given below:-

var startPoint = Cesium.Cartographic.fromDegrees(  
cartesianStartNew[0].trim(),  
cartesianStartNew[1].trim(),  
positions[0].height  
);  
var endPoint = Cesium.Cartographic.fromDegrees(  
cartesianEndNew[0].trim(),  
cartesianEndNew[1].trim(),  
positions[1].height  
);  
var surfacedistance = new Cesium.EllipsoidGeodesic(startPoint, endPoint);  
Math.round(surfacedistance.surfaceDistance) + ’ meter’;

Thanks In advance

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [August 31, 2021, 1:00am UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057/2 "2021-08-31T01:00:25Z")

</div>

@Shashi

Based on the information that you’ve provided, it seems like you are looking for the distance between two points on a terrain. Is that correct? If so, I recommend using Cesium ion SDK.

> **[Cesium ion SDK](https://cesium.com/platform/cesiumjs/ion-sdk/)**
>
> The Cesium ion SDK extends the open source CesiumJS visualization engine with tools like sensor geometries and visibility analytics. Measure distance and areas, perform line of sight, viewshed, and visibility analysis, and include ready-to-use UI...

Cesium ion SDK has a measurement toolkit that can be used for your application. To the best of my knowledge, CesiumJS does not support the feature that you are looking for. **Do other community members have suggestions or a potential workaround?**

-Sam

---

<div class="post-metadata">

**Author:** ![Shashi](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/shashi/32/3649_2.png) [@Shashi](https://community.cesium.com/u/Shashi)\
**Post date:** [August 31, 2021, 5:08am UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057/3 "2021-08-31T05:08:19Z")

</div>

Thanks, but I guess Cesium ion SDK is paid. Is there any open source way to achieve this task in cesium?

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [August 31, 2021, 2:56pm UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057/4 "2021-08-31T14:56:33Z")

</div>

@Shashi

That’s correct, Cesium ion SDK is not free. As I mentioned above, I do not think that there is a simple way to achieve this functionality in CesiumJS.

One workaround might be to string together multiple lines that are set on the surface of the terrain and add up their length. Thus you would loop through all `startPoint` and `endPoint` values for each line and add them to a `totalSurfaceDistance` variable.

```auto
var totalSurfaceDistance = 0;

...

//some sort of loop
  totalSurfaceDistance += new Cesium.EllipsoidGeodesic(startPoint, endPoint);

```

Let me know if you have any other questions or concerns. I am curious to hear your thoughts.

-Sam

---

<div class="post-metadata">

**Author:** ![Shashi](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/shashi/32/3649_2.png) [@Shashi](https://community.cesium.com/u/Shashi)\
**Post date:** [September 3, 2021, 6:42am UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057/5 "2021-09-03T06:42:39Z")

</div>

@sam.rothstein  
but I’ve only two points (it creating a big line in hilly area) and it’s not possible to iterate it.  
Thanks

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [September 7, 2021, 5:54pm UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057/6 "2021-09-07T17:54:23Z")

</div>

@Shashi

One idea is to interpolate between the two points that you already have. For each point that you add using linear interpolation, you can update its altitude based upon your terrain data.

[Linear interpolation - Wikipedia](https://en.wikipedia.org/wiki/Linear_interpolation#:~:text=In%20mathematics%2C%20linear%20interpolation%20is,set%20of%20known%20data%20points).

Next, you can measure and add the distance between each pair of points. This would yield a much more accurate measurement. In addition, you can always increase the number of sample points to produce a more accurate result. This is just one solution, **input from the community would be welcomed!**

-Sam

---

<div class="post-metadata">

**Author:** ![Shashi](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/shashi/32/3649_2.png) [@Shashi](https://community.cesium.com/u/Shashi)\
**Post date:** [September 8, 2021, 4:31am UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057/7 "2021-09-08T04:31:37Z")

</div>

@sam.rothstein  
Thanks for your suggestion. Definitely, I’ll try and let u know.

---

<div class="post-metadata">

**Author:** ![sam.rothstein](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sam.rothstein/32/6584_2.png) [@sam.rothstein](https://community.cesium.com/u/sam.rothstein)\
**Post date:** [September 8, 2021, 4:14pm UTC](https://community.cesium.com/t/measuring-the-distance-if-terrain-is-on/15057/8 "2021-09-08T16:14:55Z")

</div>

@Shashi

Great - keep me posted!

-Sam
