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

时间:2012-12-13 14:10:35

标签: c# geometry polygon

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

我正在使用从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);

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

enter image description here

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

1 个答案:

答案 0 :(得分:4)

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

longitudinal_length = latitudinal_length / cos(latitude)

因此,您需要将平方的纵向长度除以cos(latitude)

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

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

enter image description here
发件人:IBM Knowledge Center / Geographic coordinate system /图4.刻度上位置的不同尺寸

相关问题