首页 / C# / c# – 使用纬度和经度计算多边形区域
c# – 使用纬度和经度计算多边形区域
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 使用纬度和经度计算多边形区域,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2144字,纯文字阅读大概需要4分钟。
内容图文
![c# – 使用纬度和经度计算多边形区域](/upload/InfoBanner/zyjiaocheng/782/8c033c5f0a0447d9b668319a27f7d9bb.jpg)
我正在使用我在这篇文章中找到的解决方案:
Polygon area calculation using Latitude and Longitude generated from Cartesian space and a world file
有些不对劲,因为我得到的价值并不真实.例如,我们知道一个足球场应该有大约5,300.00平方米,对吗?但计算结果为5,759,154.21.
这是代码:
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;
}
这可能有什么不对?有帮助吗?
解决方法:
你正在使用的面积计算是完全错误的….: – /
我使用Google的Android Maps Utils中的SphericalUtil.ComputeSignedArea方法.
注意:Google的Java代码是在Apache License Version 2.0下,我将其转换为C#.
在我的一个应用程序中查找该足球场,我得到:4,461,不是实际的5,531,但使用谷歌地图照片并不坏…
这里只是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));
}
}
内容总结
以上是互联网集市为您收集整理的c# – 使用纬度和经度计算多边形区域全部内容,希望文章能够帮你解决c# – 使用纬度和经度计算多边形区域所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。