嗨,我在计算Bing地图中的多边形面积时遇到问题。我正在使用此代码来计算面积。
public static double PolygonArea(LocationCollection points, double resolution)
{
int n = points.Count;
var partialSum = 0.0;
var sum = 0.0;
for (int i = 0; i < n - 1; i++)
{
partialSum = (points[i].Longitude * points[i + 1].Latitude) -
(points[i + 1].Longitude * points[i].Latitude);
sum += partialSum;
}
var area = 0.5 * sum / Math.Pow(resolution, 2);
area = Math.Abs(area);
return area;
}
这是解决方法
public static double Resolution(double latitude, double zoomLevel)
{
double groundResolution = Math.Cos(latitude * Math.PI / 180) *
2 * Math.PI * EARTH_RADIUS_METERS / (256 * Math.Pow(2, zoomLevel));
return groundResolution;
}
如何在m ^ 2中转换它?
EDIT1:我尝试了您的答案,但我注意到如果更改缩放级别,该区域也会更改。
我试图从另一个角度来解释我的问题。我必须移植使用此算法来计算面积的iOS应用
-(long double)calcArea :(CLLocationCoordinate2D*) pastureCordinates :(long) count {
long double area = 0.0;
long double scale = 0.0;
for (int cnt = 1; cnt < count; cnt++) {
area += (MKMapPointForCoordinate(pastureCordinates[cnt - 1]).x)
* (MKMapPointForCoordinate(pastureCordinates[cnt]).y)
- (MKMapPointForCoordinate(pastureCordinates[cnt]).x)
* (MKMapPointForCoordinate(pastureCordinates[cnt - 1]).y);
}
area += (MKMapPointForCoordinate(pastureCordinates[count - 1]).x)
* (MKMapPointForCoordinate(pastureCordinates[0]).y)
- (MKMapPointForCoordinate(pastureCordinates[0]).x)
* (MKMapPointForCoordinate(pastureCordinates[count - 1]).y);
scale = MKMapPointsPerMeterAtLatitude(pastureCordinates[count -1].latitude);
area = (area / (long double)2) / pow(scale,2);
area = fabsl(area);
return area;
}
我使用了以下功能:https : //msdn.microsoft.com/zh-cn/library/bb259689.aspx计算比例尺,地面分辨率,但结果与iOS解决方案相比有所不同。
好的,我研究了一些代码,并组合了一个简单的方法,该方法可以相当准确地计算面积,而不必使用真正深入的空间数学。
private double CalculateArea(LocationCollection locs)
{
double area = 0;
for (var i = 0; i < locs.Count - 1; i++)
{
area += Math.Atan(
Math.Tan(Math.PI / 180 * (locs[i + 1].Longitude - locs[i].Longitude) / 2) *
Math.Sin(Math.PI / 180 * (locs[i + 1].Latitude + locs[i].Latitude) / 2) /
Math.Cos(Math.PI / 180 * (locs[i + 1].Latitude - locs[i].Latitude) / 2));
}
if (area < 0)
{
area *= -1;
}
return area * 2 * Math.Pow(6378137.0, 2);
}
通过对各种多边形进行测试并将其与SQL中的计算区域进行比较,我发现在更糟的情况下,使用可笑的大多边形时,差异约为0.673%。当对尺寸约为0.5平方公里的多边形进行测试时,差异约为0.06%。请注意,此方法返回以平方米为单位的面积。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句