我正在寻找一种精确的算法或服务,用于根据GPS坐标计算地球表面积。
我正在使用Google地图API版本3,并根据记录的坐标绘制多边形,但我认为标准的计算多边形面积的方式不会考虑到斜坡(山丘)因素。我需要针对这种情况处理等高线吗?
是否有第三方服务可以考虑斜坡因素,例如ArcGis或其他服务。
我正在寻找一种精确的算法或服务,用于根据GPS坐标计算地球表面积。
我正在使用Google地图API版本3,并根据记录的坐标绘制多边形,但我认为标准的计算多边形面积的方式不会考虑到斜坡(山丘)因素。我需要针对这种情况处理等高线吗?
是否有第三方服务可以考虑斜坡因素,例如ArcGis或其他服务。
是的,这绝对是可能的。这里有一个快速教程和示例代码:
相关部分如下:
google.maps.geometry.spherical.computeArea(yourPolygon.getPath());
官方文档:
http://code.google.com/apis/maps/documentation/javascript/reference.html#spherical
布拉德的答案
google.maps.geometry.spherical.computeArea(yourPolygon.getPath());
这是正确的,但要注意,它仅适用于不自相交的多边形。当多边形开始自相交时,事情就会变得非常糟糕。您可以使用Brad提供的链接http://geojason.info/demos/line-length-polygon-area-google-maps-v3/ 来尝试一下。只需画4-5条相交的线并开始移动顶点,面积计算肯定会出现错误。
如果您还不相信,请看这个例子:
var map;
google.maps.visualRefresh = true;
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
var mapOptions = {
center : new google.maps.LatLng(55.874, -4.287),
zoom : 16,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions)
drawExample();
}
function drawExample() {
var pathLeft = [new google.maps.LatLng(55.874, -4.292),
new google.maps.LatLng(55.875, -4.292),
new google.maps.LatLng(55.875, -4.290),
new google.maps.LatLng(55.876, -4.290),
new google.maps.LatLng(55.876, -4.291),
new google.maps.LatLng(55.874, -4.291)]
var polygonLeft = new google.maps.Polygon({
path : pathLeft,
map: map
});
var areaLeft = google.maps.geometry.spherical.computeArea(polygonLeft.getPath());
var pathRight = [new google.maps.LatLng(55.874, -4.282),
new google.maps.LatLng(55.875, -4.282),
new google.maps.LatLng(55.875, -4.280),
new google.maps.LatLng(55.8753, -4.2807),
new google.maps.LatLng(55.876, -4.281),
new google.maps.LatLng(55.874, -4.281)]
var polygonRight = new google.maps.Polygon({
path : pathRight,
map: map
});
var areaRight = google.maps.geometry.spherical.computeArea(polygonRight.getPath());
console.log("areaLeft: " + areaLeft + "\nareaRight: " + areaRight);
}
computeArea
调用未能正常工作)--请参见此处。 - Greg Sadetsky