GeometryUtil.geodesicArea() 返回大量值
GeometryUtil.geodesicArea() returning massive values
我正在使用 GeometryUtil.geodesicArea 函数将弹出窗口绑定到我的多边形,其中包含有关多边形区域的信息。在这里,粘贴 straight from the code:
geodesicArea: function (latLngs) {
var pointsCount = latLngs.length,
area = 0.0,
d2r = Math.PI / 180,
p1, p2;
if (pointsCount > 2) {
for (var i = 0; i < pointsCount; i++) {
p1 = latLngs[i];
p2 = latLngs[(i + 1) % pointsCount];
area += ((p2.lng - p1.lng) * d2r) *
(2 + Math.sin(p1.lat * d2r) + Math.sin(p2.lat * d2r));
}
area = area * 6378137.0 * 6378137.0 / 2.0;
}
return Math.abs(area);
}
当我使用这些坐标在加拿大萨斯喀彻温省的大致区域上绘制一个矩形时:
0: {lat: 49.06465160956338, lng: -110.00904901708327}
1: {lat: 59.94790491663552, lng: -110.00904901708327}
2: {lat: 59.94790491663552, lng: -101.6155500597509}
3: {lat: 49.06465160956338, lng: -101.6155500597509}
roughly 651,900 sq km, it is returning 30610232650154772. If this number is , it is to equal to roughly 30 billion square kilometers, which is well beyond the surface area of the entire earth,除非我遗漏了一些关于返回数字的含义的信息。
这个测地面积函数是计算什么的?我应该使用其他 way/function 来获取多边形的面积吗?
这是我正在使用的代码以及逐行计算的值
您忘记了
中的括号
面积 + = (p2.lng - p1.lng * d2r) *
需要:
面积 + = ((p2.lng - p1.lng) * d2r) *
只需使用 Heron 的公式和 L.GeometryUtil.length() 即可实现:
Heron's formula
我正在使用 GeometryUtil.geodesicArea 函数将弹出窗口绑定到我的多边形,其中包含有关多边形区域的信息。在这里,粘贴 straight from the code:
geodesicArea: function (latLngs) {
var pointsCount = latLngs.length,
area = 0.0,
d2r = Math.PI / 180,
p1, p2;
if (pointsCount > 2) {
for (var i = 0; i < pointsCount; i++) {
p1 = latLngs[i];
p2 = latLngs[(i + 1) % pointsCount];
area += ((p2.lng - p1.lng) * d2r) *
(2 + Math.sin(p1.lat * d2r) + Math.sin(p2.lat * d2r));
}
area = area * 6378137.0 * 6378137.0 / 2.0;
}
return Math.abs(area);
}
当我使用这些坐标在加拿大萨斯喀彻温省的大致区域上绘制一个矩形时:
0: {lat: 49.06465160956338, lng: -110.00904901708327}
1: {lat: 59.94790491663552, lng: -110.00904901708327}
2: {lat: 59.94790491663552, lng: -101.6155500597509}
3: {lat: 49.06465160956338, lng: -101.6155500597509}
roughly 651,900 sq km, it is returning 30610232650154772. If this number is
这个测地面积函数是计算什么的?我应该使用其他 way/function 来获取多边形的面积吗?
这是我正在使用的代码以及逐行计算的值
您忘记了
中的括号面积 + = (p2.lng - p1.lng * d2r) *
需要:
面积 + = ((p2.lng - p1.lng) * d2r) *
只需使用 Heron 的公式和 L.GeometryUtil.length() 即可实现: Heron's formula