围绕一个长点画一个正方形

问题描述 投票:4回答:1

我试图在地球表面的某个点周围画一个正方形。

我正在使用从herehere检索到的信息,最终想出了这个: -

        // Converting degrees to radians
        double latInDecimals = (Math.PI / 180) * latitude;
        double longInDecimals = (Math.PI / 180) * longitude;

        List<string> lstStrCoords = new List<string>();

        double changeInLat;
        double changeInLong;
        double lineOfLat;      

        // Calculating change in latitude for square of side 
        changeInLong = (side / 1000) * (360.0 / 40075);

        // Calculating length of longitude at that point of latitude
        lineOfLat = Math.Cos(longitude) * 40075;

        // Calculating change in longitude for square of side 'side'
        changeInLat = (side / 1000) * (360.0 / lineOfLat);

        // Converting changes into radians
        changeInLat = changeInLat * (Math.PI / 180);
        changeInLong = changeInLong * (Math.PI / 180);


        double nLat = changeInLat * (Math.Sqrt(2) / 2);
        double nLong = changeInLong * (Math.Sqrt(2) / 2);

        double coordLat1 = latInDecimals + nLat;
        double coordLong1 = longInDecimals + nLong;

        double coordLat2 = latInDecimals + nLat;
        double coordLong2 = longInDecimals - nLong;

        double coordLat3 = latInDecimals - nLat;
        double coordLong3 = longInDecimals - nLong;

        double coordLat4 = latInDecimals - nLat;
        double coordLong4 = longInDecimals + nLong;

        // Converting coords back to degrees

        coordLat1 = coordLat1 * (180 / Math.PI);
        coordLat2 = coordLat2 * (180 / Math.PI);
        coordLat3 = coordLat3 * (180 / Math.PI);
        coordLat4 = coordLat4 * (180 / Math.PI);

        coordLong1 = coordLong1 * (180 / Math.PI);
        coordLong2 = coordLong2 * (180 / Math.PI);
        coordLong3 = coordLong3 * (180 / Math.PI);
        coordLong4 = coordLong4 * (180 / Math.PI);

现在即使这样可行,我从连接它们得到的多边形是一个矩形。

我对我的代码有什么问题感到困惑。

c# geometry polygon
1个回答
4
投票

除非球座位于赤道上,否则球体上一个纬度和经度的矩形长度不同于km。它朝着两极走得更窄。如果你想让双面都相同,你必须进行修正

longitudinal_length = latitudinal_length / cos(latitude)

所以你需要将你的方形的纵向长度除以cos(latitude)

现在,你的广场可能仍然是弯曲的,但这取决于地图的投射方式,这是一个完全不同的故事。您需要知道Google使用的投影公式进行更正。

您可能会发现更复杂的公式,考虑到地球不是一个完美的球体这一事实,但我认为这应该足以满足您的位置标记。另请注意,您将在+/- 90度处获得零除。因此,在杆上放置一个矩形需要另一种方法。

enter image description here 来自:IBM Knowledge Center / Geographic coordinate system /图4.网格上位置之间的不同尺寸

© www.soinside.com 2019 - 2024. All rights reserved.