math - 如何在墨卡托 map (JPEG) 上从 x、y 获取纬度、经度?

标签 math maps mapping latitude-longitude

我有一个 JPEG 格式的墨卡托投影图,我想知道如何将给定的 x、y 坐标与其纬度和经度相关联。我看过古德曼函数,但老实说,我不明白如何使用该函数并应用它。即,它期望什么输入?我发现的实现(JavaScript)似乎在 -PI 和 PI 之间取一个范围,但是我的 y 值(以像素为单位)与该范围之间的相关性是什么?

另外,我发现这个函数需要一个纬度并返回谷歌地图的瓦片,谷歌地图也使用墨卡托。似乎如果我知道如何反转这个函数,我就会非常接近得到我的答案。

/*<summary>Get the vertical tile number from a latitude
using Mercator projection formula</summary>*/

    private int getMercatorLatitude(double lati)
    {
        double maxlat = Math.PI;

        double lat = lati;

        if (lat > 90) lat = lat - 180;
        if (lat < -90) lat = lat + 180;

        // conversion degre=>radians
        double phi = Math.PI * lat / 180;

        double res;
        //double temp = Math.Tan(Math.PI / 4 - phi / 2);
        //res = Math.Log(temp);
        res = 0.5 * Math.Log((1 + Math.Sin(phi)) / (1 - Math.Sin(phi)));
        double maxTileY = Math.Pow(2, zoom);
        int result = (int)(((1 - res / maxlat) / 2) * (maxTileY));

        return (result);
    }

最佳答案

这是给您的一些代码...如果您需要更多解释,请告诉我。

    /// <summary>
    /// Calculates the Y-value (inverse Gudermannian function) for a latitude. 
    /// <para><see cref="http://en.wikipedia.org/wiki/Gudermannian_function"/></para>
    /// </summary>
    /// <param name="latitude">The latitude in degrees to use for calculating the Y-value.</param>
    /// <returns>The Y-value for the given latitude.</returns>
    public static double GudermannianInv(double latitude)
    {
        double sign = Math.Sign(latitude);
        double sin = Math.Sin(latitude * RADIANS_PER_DEGREE * sign);
        return sign * (Math.Log((1.0 + sin) / (1.0 - sin)) / 2.0);
    }

    /// <summary>
    /// Returns the Latitude in degrees for a given Y.
    /// </summary>
    /// <param name="y">Y is in the range of +PI to -PI.</param>
    /// <returns>Latitude in degrees.</returns>
    public static double Gudermannian(double y)
    {
        return Math.Atan(Math.Sinh(y)) * DEGREES_PER_RADIAN;
    }

关于math - 如何在墨卡托 map (JPEG) 上从 x、y 获取纬度、经度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1166059/

相关文章:

regex - 创建一个正则表达式以将两个数字相加

javascript - OpenLayers.js 使用哪些文件?

r - 绘制地理编码 : ggmap error

elasticsearch - 如何在 Elasticsearch 中获取 ignore_malformed 参数的值

json - Angular 5 Observable映射到Json数组

python-2.7 - 确定点是否在旋转矩形内(仅限标准 Python 2.7 库)

python - 为什么 Python 给出平方根的 "wrong"答案? Python 2 中的整数除法是什么?

c++ - 查找协方差矩阵的特征向量以创建 3D 包围球

ios - 如何快速在MKMapview上显示MKPinAnnotationView

java - Hibernate:在插入数据库时​​填充特定列