我有一个 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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)