Volume calculation

hello,

I want calculate volume of a polygon drawn upon terrain (reference image is attached).

Is there is any way to achieve this.

I’m using Cesium 1.50

1 Like

The image you uploaded looks like a flat polygon draped over terrain, so I think there isn’t any volume per se to measure there.

In any case, I don’t believe CesiumJS currently has any built in tools to do that. I was looking at Turfjs (http://turfjs.org/) which has a lot of useful tools but I’m not sure if it has anything for that particular case either.

You might try to compute this yourself by approximating the area and multiplying by the height, perhaps.

Hi,

Also interested in this feature.

Are there any updates, since more than two years have passed?

Thanks,

Hugo

You can do it by finding all coordinates within the polygon as a grid, then sampleHeightMostDetailed() of all of them (at some resolution of sensibility). There’s a max to min height of volume inside the perimeter (height at your polygon edges). It’s not going to be quick, but it’s certainly possible. I’m sure a bit of searching will get you some options, like this starting point;

Cheers,

Alex

Hi @Alexander_Johannesen ,

How do you actually find the coordinates within the polygon as a grid?

Cheers,
Hiroshi

Hiya,

Plenty of ways (there’s even Cesium intersection functions you can use), but I’ll pop here a simple implementation (public implementation) where we assume two arrays of a polygons lat and long values (where the index of each is of course the same coordinate), so our polygon is something like;

var longitudes = [ 10, 12, 14, 12, 11 ];
var latitudes = [ 34, 35, 36, 34, 33 ];

With the following function you can loop your points to see if they intersect (are inside) the above polygon;

var points = [ {longitude:11,latitude:34}, {longitude:13,latitude:35} ];

points.forEach ( point => {
   if ( pointInsidePolygon( point, longitudes, latitudes ) {
      console.log('!! point is inside!', point );
   } else {
      console.log('point is outside',point );
   }
});

pointInsidePolygon(point, vX, vY) {
    // ray-casting algorithm http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
    var x = point.longitude, y = point.latitude;
    var inside = false;
    for (var i = 0, j = vX.length - 1; i < vX.length; j = i++) {
      var xi = vX[i], yi = vY[i];
      var xj = vX[j], yj = vY[j];

      var intersect = ((yi >= y) != (yj >= y))
        && (x <= (xj - xi) * (y - yi) / (yj - yi) + xi);
      if (intersect) {
        inside = !inside;
      }
    }

    return inside;
  }

That should be more than plenty to get you on your way.

Cheers,

Alex