使用纬度和经度计算多边形面积

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));
    }
}

这篇关于使用纬度和经度计算多边形面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用纬度和经度计算多边形面积

基础教程推荐