当多边形的点是经纬度时计算多边形的面积:哪个函数更准确?

发布于 2024-09-12 00:36:51 字数 2049 浏览 1 评论 0原文

我正在尝试找到一种在 Flex 3 站点中使用经纬度坐标来计算多边形面积的方法。 Google Maps for Flash 小组中的 Hong007 很酷,发布了以下功能:

private function GetPolygonArea (polygon : Polygon):Number 
        { 
            var nVer : int = polygon.getOuterVertexCount(); 
            var sz : Number =0; 
            var s : Number =0; 
            var x : Number =0; 
            var y0 : Number =0; 
            var y1 : Number =0; 
            var Maplatlng:LatLng; 
            if (nVer>=3){ 
               for (var i:int=0; i<nVer; i++){ 
                   Maplatlng = polygon.getOuterVertex(i); 
                   x = Maplatlng.lng(); 
                   if (i>0){ 
                      Maplatlng = polygon.getOuterVertex(i-1); 
                      y0 = Maplatlng.lat(); 
                   } 
                   else{ 
                      Maplatlng = polygon.getOuterVertex(nVer-1); 
                      y0 = Maplatlng.lat(); 
                   }; 
                   if (i<(nVer-1)){ 
                      Maplatlng = polygon.getOuterVertex(i+1); 
                      y1 = Maplatlng.lat(); 
                   } 
                   else{ 
                      Maplatlng = polygon.getOuterVertex(0); 
                      y1 = Maplatlng.lat(); 
                   }; 
                   s = x * (y0-y1); 
                   sz+=s; 
               }; 
               //경위도시 1도의 m값을 곱한다(대략 면적 환산) 
               Maplatlng = polygon.getOuterVertex(0); 
               var Maplatlng1:LatLng = new 
com.google.maps.LatLng(Maplatlng.lat()+1, Maplatlng.lng()+1); 
               var TempDISTANCE:Number = 
Maplatlng.distanceFrom(Maplatlng1) / Math.sqrt(2); 
               return Math.abs((sz/2.0) * Math.pow(TempDISTANCE, 2)); 
            }; 
            return 0.0; 
        }

我也在 http://www.freemaptools.com/area-calculator.htm

这些函数产生的结果略有不同。我正在尝试找出哪一个更准确。看起来 hong007 的函数产生的结果平均略大于 freemaptools 的函数。不过,我不知道哪一个更准确。有什么建议吗?

I'm trying to find a way to calculate the area of a polygon using lat long coordinates in a Flex 3 site. Hong007 on Google Maps for Flash group was cool enough to post the following function:

private function GetPolygonArea (polygon : Polygon):Number 
        { 
            var nVer : int = polygon.getOuterVertexCount(); 
            var sz : Number =0; 
            var s : Number =0; 
            var x : Number =0; 
            var y0 : Number =0; 
            var y1 : Number =0; 
            var Maplatlng:LatLng; 
            if (nVer>=3){ 
               for (var i:int=0; i<nVer; i++){ 
                   Maplatlng = polygon.getOuterVertex(i); 
                   x = Maplatlng.lng(); 
                   if (i>0){ 
                      Maplatlng = polygon.getOuterVertex(i-1); 
                      y0 = Maplatlng.lat(); 
                   } 
                   else{ 
                      Maplatlng = polygon.getOuterVertex(nVer-1); 
                      y0 = Maplatlng.lat(); 
                   }; 
                   if (i<(nVer-1)){ 
                      Maplatlng = polygon.getOuterVertex(i+1); 
                      y1 = Maplatlng.lat(); 
                   } 
                   else{ 
                      Maplatlng = polygon.getOuterVertex(0); 
                      y1 = Maplatlng.lat(); 
                   }; 
                   s = x * (y0-y1); 
                   sz+=s; 
               }; 
               //경위도시 1도의 m값을 곱한다(대략 면적 환산) 
               Maplatlng = polygon.getOuterVertex(0); 
               var Maplatlng1:LatLng = new 
com.google.maps.LatLng(Maplatlng.lat()+1, Maplatlng.lng()+1); 
               var TempDISTANCE:Number = 
Maplatlng.distanceFrom(Maplatlng1) / Math.sqrt(2); 
               return Math.abs((sz/2.0) * Math.pow(TempDISTANCE, 2)); 
            }; 
            return 0.0; 
        }

I was also playing around with the area calculator at http://www.freemaptools.com/area-calculator.htm .

These functions produce slightly different results. I'm trying to figure out which one is more accurate. It seems that hong007's function produces results that are on average slightly larger than freemaptools' function. However, I don't know which one is more accurate. Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话里做英雄 2024-09-19 00:36:51

我向这个算法添加了一些字符串。
对于谷歌地图实验,我发现了这个数字:

are = area-(area*0.2187);

它适用于最大(比例= 5米)和最小(500公里)缩放级别。

I added some string to this algorithm.
For google maps experimentally I found this numbers:

are = area-(area*0.2187);

and it works for me for maximum (scale = 5 meters) and minimum (500 km) zoom levels.

可是我不能没有你 2024-09-19 00:36:51

这里实现的方法非常快速而且肮脏。它做出了一些可能导致错误结果的假设。

首先要知道的是,纬度/经度空间相对于地面测量距离的缩放比例不均匀。这意味着长度为一米的向量在纬度/经度空间中具有不同的长度,具体取决于向量是否大致指向东西向或南北向。此外,纬度/长轴映射到地面单位之间的差异大小会根据您在地球上的位置而变化(两极的差异比赤道的差异大得多。)

上面的算法做了一个非常快速和肮脏的工作解决此问题的方法是根据为单位直角三角形的斜边计算的距离生成比例值。这试图基本上平均地球上该点的两个纬度/长轴的比例。

这有几个问题。如果多边形非常大(多个地理单元),则此平均比例值将关闭,因为它仅针对 0 顶点周围的局部地理单元进行计算。其次,平均尺度近似确实非常粗糙,如果您的多边形在一个维度上变化很大,而在另一个维度上变化不大(沿着一个轴定向的长瘦多边形),那么平均比例近似会显着崩溃。这是因为比例将被计算为两个轴比例的平均值,但由于顶点的分布,其中一个轴的影响应该很小。

我没有查看其他面积计算器,但我猜如果您发现差异,则该代码是不太准确的版本。

The method implemented here is pretty quick and dirty. It makes a couple of assumptions that can lead to incorrect results.

The first thing to know is that Lat/Long space is non-uniformly scaled with respect to measured distance on the ground. This means that a vector of length one meter has a different length in lat/long space depending on if the vector is pointing roughly east-west or north-south. Also, the magnitude of the difference between how the lat/long axes map to ground units changes depending on where you are on the globe (it's much more different at the poles than at the equator.)

The algorithm above does a very quick and dirty workaround for this, which is to generate a scale value based on the distance calculated for the hypotenuse of a unit right triangle. This tries to basically average the scales of the two lat/long axes for that point on the globe.

There are a couple of problems with this. If the polygon is very large (multiple geocells), then this average scale value will be off because it's only calculated for the local geocell around the 0 vertex. Secondly, the average scale approximation is really very coarse and will break down significantly if you have polygons that vary greatly in one dimension but not the other (a long skinny polygon oriented along one of the axes). This is because the scale will be computed as an average of the scale of the two axes but one of the axes should have very little influence because of the distribution of the vertices.

I didn't look at the other area calculator but I would guess if you're seeing discrepancies that this code is the less accurate version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文