简体   繁体   English

从GPS坐标获取区域

[英]Getting area from GPS coordinates

So, I've got a method that returns the area of a shape defined by its points (given in CCW or CW order, it doesn't really matter). 因此,我有一个方法可以返回由其点定义的形状区域(按CCW或CW顺序,这并不重要)。 I tested it with some shapes and it seems to be working. 我用一些形状对其进行了测试,它似乎可以正常工作。

The problem is, I want to use this method with GPS coordinates, and I want to return the result in m² or km², but that's definitly not what happens. 问题是,我想将此方法与GPS坐标一起使用,并且我想以m²或km²为单位返回结果,但是绝对不会发生这种情况。 In fact, I don't even know in which unit the result is when I use this method with that kind of coordinates. 实际上,我什至不知道将这种方法与那种坐标一起使用时的结果是哪个单位。

So the question is, how to convert the result I have into m² or km² ? 所以问题是,如何将我得到的结果转换为m²或km²? I tried some things, but either it does not work or it's inaccurate. 我尝试了一些方法,但是它不起作用或不正确。

Here's my method, if you want to check : 这是我的方法,如果您要检查:

public static double getArea(List<Vector2D> points) {

    double firstSum = 0, secondSum = 0;

    for (int i = 0 ; i < points.size()-1 ; i++) {
        firstSum += points.get(i).x * points.get(i+1).y;
        secondSum += points.get(i).y * points.get(i+1).x;
    }
    firstSum += points.get( points.size()-1 ).x * points.get(0).y;
    secondSum += points.get( points.size()-1 ).y * points.get(0).x;

    return Math.abs((firstSum-secondSum)/2);

}

( Vector2D is the class I use for points, with x as the latitude and y as the longitude) Vector2D是我用于点的类,其中x为纬度, y为经度)

The problem is that you're not taking the (approximately) spherical nature of the Earth into account. 问题在于您没有考虑地球的(近似)球形性质。 For a start, you need to take into account the radius of the Earth - you could have the same list of latitude and longitude on a smaller (or bigger) planet, but the radius would be different, and consequently the area would be different too. 首先,您需要考虑地球的半径-在较小(或较大)的行星上可以具有相同的纬度和经度列表,但是半径会有所不同,因此面积也将有所不同。

You can use the approach in this question . 您可以在此问题中使用该方法。 It's trivial to convert that to Java: 将其转换为Java很简单:

public static double CalculatePolygonArea(List<Vector2D> coordinates)
{
    double area = 0;

    if (coordinates.size() > 2)
    {
        for (int i = 0; i < coordinates.size()-1; i++)
        {
            Vector2D p1, p2;
            p1 = coordinates.get(i);
            p2 = coordinates.get(i + 1);
            area += Math.toRadians(p2.x - p1.x) * (2 + Math.sin(Math.toRadians(p1.y))
               + Math.sin(Math.toRadians(p2.y)));

        }
        area = area * R * R / 2;
    }

    return Math.abs(area);
}

(assuming Vector2D.x is the longitude and Vector2D.y is the latitude). (假设Vector2D.x是经度, Vector2D.y是纬度)。

R is the radius of the Earth. R是地球的半径。 Use a value in the unit you want the area result to be in (eg 6_371_000 metres for square metres, 6_371 km for square km, 3_959 miles for square miles...) 在您要面积结果使用的单位中使用一个值(例如,6_371_000米为平方米,6_371 km为平方公里,3_959英里为平方英里...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Primefaces地理编码从备用Bean获取0.0、0.0 gps坐标 - Primefaces geocode getting 0.0, 0.0 gps coordinates from backing bean 通过添加度量距离来获取新的GPS坐标 - Getting new GPS coordinates by adding metric distances 从Java中的设备获取位置坐标(不是基于IP更像GPS或单元信号) - Getting location coordinates from device like iPhone in Java (not based on IP more like GPS or cell signal) 从1套坐标和距离计算新的GPS坐标? - Calculate new gps coordinates from 1 set of coordinates and distance? 如何将GPS服务中的坐标转换为文本文件? - How do I get coordinates from a GPS service into a text file? 使用Overlay连接从Android中的数据库获取的GPS坐标 - Connecting GPS coordinates taken from a database in Android using Overlay 如何从 GPS 坐标获取道路名称或街道名称? - How to get road name or street name from GPS coordinates? 如何从多个轨道中选择GPS坐标区域? - How to select a region of GPS coordinates from multiple tracks? GPS坐标没有正确存储在数据库中从android到php [关闭] - GPS coordinates not properly stored in database from android to php [CLOSE] 如何从两个GPS坐标计算方向的角度 - How to calculate the angle of the direction from two GPS coordinates
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM