如何插入纬度和经度坐标

时间:2016-05-18 12:34:34

标签: c# math geometry coordinates

我需要找到位于一条线上的一组两个坐标之间的插值点。 我想到的伪C#代码就是:

private static List<Coordinate> SampleLine(Coordinate start, Coordinate end, int Samples)
    {

        List<Coordinate> LineStringSample = new List<Coordinate>();
        // Calculate equal interval between two points 
        var diff_X = start.X - end.X; //latitudes
        var diff_Y = start.Y - end.Y; //longitudes
        var length = Math.Sqrt(diff_X * diff_X + diff_Y * diff_Y);
        var interval_X = diff_X / length;
        var interval_Y = diff_Y / length;

        Coordinate last = start;
        for (int i = 1; i <= Samples; i++)
        {
            LineStringSample.Add(new Coordinate(start.X + interval_X * i, start.Y + interval_Y * i));
        }
    }

例如start = (49.13512,6.4321) end = (49.13515,6.4333) Samples=1000,其中基本上是纬度和经度坐标。 我需要知道这是插入折线的两个坐标点的正确方法,还是有其他方法可以做到这一点?

1 个答案:

答案 0 :(得分:1)

这种插​​值不精确,当坐标差异增大时,误差会增加。它可能仍然适合像你的例子那样的小行。

更好的方法 - 在大圆弧处找到插值点。在{中间点'部分查看here

Formula:
 a = sin((1−f)⋅δ) / sin δ
 b = sin(f⋅δ) / sin δ
 x = a ⋅ cos φ1 ⋅ cos λ1 + b ⋅ cos φ2 ⋅ cos λ2
 y = a ⋅ cos φ1 ⋅ sin λ1 + b ⋅ cos φ2 ⋅ sin λ2
 z = a ⋅ sin φ1 + b ⋅ sin φ2
 φi = atan2(z, √x² + y²)
 λi = atan2(y, x) 
where   

f is fraction along great circle route (f=0 is point 1, f=1 is point 2),
δ is the angular distance d/R between the two points.
相关问题