Polygon area calculation using Latitude and Longitude(使用纬度和经度计算多边形面积)
问题描述
我正在使用我在这篇文章中找到的解决方案:
出了点问题,因为我得到的值不是真实的.例如,我们知道一个足球场应该有大约 5,300.00 平方米,对吧?但计算结果为 5,759,154.21.
这是代码:
private static double CalculatePolygonArea(IList坐标){双面积 = 0;如果(坐标.计数 > 2){for (var i = 0; i <坐标.Count - 1; i++){位置 p1 = 坐标[i];位置 p2 = 坐标[i + 1];面积 += (ConvertToRadian(p2.Longitude) - ConvertToRadian(p1.Longitude)) * (2 + Math.Sin(ConvertToRadian(p1.Latitude)) + Math.Sin(ConvertToRadian(p2.Latitude)));}面积 = 面积 * 6378137 * 6378137/2;}返回 Math.Abs(面积);}私有静态双 ConvertToRadian(双输入){返回输入 * Math.PI/180;}
这里有什么问题?有什么帮助吗?
你使用的面积计算完全错误.... :-/
我使用
这里只是ComputeSignedArea
:
公共静态类 SphericalUtil{常量双 EARTH_RADIUS = 6371009;静态双ToRadians(双输入){返回输入/180.0 * Math.PI;}public static double ComputeSignedArea(IList 路径){返回 ComputeSignedArea(路径,EARTH_RADIUS);}static double ComputeSignedArea(IList 路径,双半径){int size = path.Count;if (size < 3) { return 0;}双倍总数 = 0;var prev = 路径[大小 - 1];双 prevTanLat = Math.Tan((Math.PI/2 - ToRadians(prev.Latitude))/2);双 prevLng = ToRadians(prev.Longitude);foreach(路径中的变量点){双 tanLat = Math.Tan((Math.PI/2 - ToRadians(point.Latitude))/2);双 lng = ToRadians(point.Longitude);总计 += PolarTriangleArea(tanLat, lng, prevTanLat, prevLng);上一页TanLat = tanLat;prevLng = lng;}返回总*(半径*半径);}静态双 PolarTriangleArea(双 tan1,双 lng1,双 tan2,双 lng2){双 deltaLng = lng1 - lng2;双 t = tan1 * tan2;返回 2 * Math.Atan2(t * Math.Sin(deltaLng), 1 + t * Math.Cos(deltaLng));}}
I am using a solution I've found in this post: Polygon area calculation using Latitude and Longitude generated from Cartesian space and a world file
There is something wrong because the values I am getting are not real. For example we know a football field should have around 5,300.00 square meters, right? but the calculation is giving 5,759,154.21.
This is the code:
private static double CalculatePolygonArea(IList<Position> coordinates)
{
double area = 0;
if (coordinates.Count > 2)
{
for (var i = 0; i < coordinates.Count - 1; i++)
{
Position p1 = coordinates[i];
Position p2 = coordinates[i + 1];
area += (ConvertToRadian(p2.Longitude) - ConvertToRadian(p1.Longitude)) * (2 + Math.Sin(ConvertToRadian(p1.Latitude)) + Math.Sin(ConvertToRadian(p2.Latitude)));
}
area = area * 6378137 * 6378137 / 2;
}
return Math.Abs(area);
}
private static double ConvertToRadian(double input)
{
return input * Math.PI / 180;
}
What can be wrong here? Any help?
The area calculation you are using is just plain wrong.... :-/
I use the SphericalUtil.ComputeSignedArea
method from Google's Android Maps Utils.
Note: Google's Java code for that is under Apache License Version 2.0, and I converted it to C#.
Looking up that football field up in one of my apps, I get: 4,461, not quite the actual 5,531 but not bad for using Google Map photos...
Here is just the ComputeSignedArea
:
public static class SphericalUtil
{
const double EARTH_RADIUS = 6371009;
static double ToRadians(double input)
{
return input / 180.0 * Math.PI;
}
public static double ComputeSignedArea(IList<LatLng> path)
{
return ComputeSignedArea(path, EARTH_RADIUS);
}
static double ComputeSignedArea(IList<LatLng> path, double radius)
{
int size = path.Count;
if (size < 3) { return 0; }
double total = 0;
var prev = path[size - 1];
double prevTanLat = Math.Tan((Math.PI / 2 - ToRadians(prev.Latitude)) / 2);
double prevLng = ToRadians(prev.Longitude);
foreach (var point in path)
{
double tanLat = Math.Tan((Math.PI / 2 - ToRadians(point.Latitude)) / 2);
double lng = ToRadians(point.Longitude);
total += PolarTriangleArea(tanLat, lng, prevTanLat, prevLng);
prevTanLat = tanLat;
prevLng = lng;
}
return total * (radius * radius);
}
static double PolarTriangleArea(double tan1, double lng1, double tan2, double lng2)
{
double deltaLng = lng1 - lng2;
double t = tan1 * tan2;
return 2 * Math.Atan2(t * Math.Sin(deltaLng), 1 + t * Math.Cos(deltaLng));
}
}
这篇关于使用纬度和经度计算多边形面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用纬度和经度计算多边形面积
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01