Adding methods for getting geodesic measures from geometries. Assuming geometries can be transformed into Geographic/WGS84, getGeodesicLength and getGeodesicArea should return reasonable 'on the ground' metrics. Use getLength and getArea for the planar metrics. r=crschmidt (closes #1819)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9248 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-04-08 23:12:24 +00:00
parent 5f335f4207
commit 08077f0f42
8 changed files with 250 additions and 44 deletions

View File

@@ -60,6 +60,35 @@ OpenLayers.Geometry.Polygon = OpenLayers.Class(
return area;
},
/**
* APIMethod: getGeodesicArea
* Calculate the approximate area of the polygon were it projected onto
* the earth.
*
* Parameters:
* projection - {<OpenLayers.Projection>} The spatial reference system
* for the geometry coordinates. If not provided, Geographic/WGS84 is
* assumed.
*
* Reference:
* 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 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409
*
* Returns:
* {float} The approximate geodesic area of the polygon in square meters.
*/
getGeodesicArea: function(projection) {
var area = 0.0;
if(this.components && (this.components.length > 0)) {
area += Math.abs(this.components[0].getGeodesicArea(projection));
for(var i=1, len=this.components.length; i<len; i++) {
area -= Math.abs(this.components[i].getGeodesicArea(projection));
}
}
return area;
},
/**
* Method: containsPoint
* Test if a point is inside a polygon. Points on a polygon edge are