Add geodesic option for measure

This commit is contained in:
Bart van den Eijnden
2015-02-10 13:01:22 +01:00
parent 776ffa925f
commit c5c24f209a
5 changed files with 85 additions and 3 deletions

View File

@@ -57,6 +57,36 @@ ol.Sphere.prototype.cosineDistance = function(c1, c2) {
};
/**
* Returns the geodesic area for a list of coordinates.
*
* [Reference](http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409)
* Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for
* Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion
* Laboratory, Pasadena, CA, June 2007
*
* @param {Array.<ol.Coordinate>} coordinates List of coordinates of a linear
* ring. If the ring is oriented clockwise, the area will be positive,
* otherwise it will be negative.
* @return {number} Area.
* @api
*/
ol.Sphere.prototype.geodesicArea = function(coordinates) {
var area = 0, len = coordinates.length;
var x1 = coordinates[len - 1][0];
var y1 = coordinates[len - 1][1];
for (var i = 0; i < len; i++) {
var x2 = coordinates[i][0], y2 = coordinates[i][1];
area += goog.math.toRadians(x2 - x1) *
(2 + Math.sin(goog.math.toRadians(y1)) +
Math.sin(goog.math.toRadians(y2)));
x1 = x2;
y1 = y2;
}
return area * this.radius * this.radius / 2.0;
};
/**
* Returns the distance of c3 from the great circle path defined by c1 and c2.
*
@@ -110,6 +140,7 @@ ol.Sphere.prototype.finalBearing = function(c1, c2) {
* @param {ol.Coordinate} c1 Coordinate 1.
* @param {ol.Coordinate} c2 Coordinate 2.
* @return {number} Haversine distance.
* @api
*/
ol.Sphere.prototype.haversineDistance = function(c1, c2) {
var lat1 = goog.math.toRadians(c1[1]);