4

在给定纬度的情况下,我正在尝试使用墨卡托投影来计算地图上的 Y 位置。这是我需要的:

//mapHeight might be 600 (pixels), for example
//latitudeInDegrees ranges from -90 to 90
public double CalculateY(double mapHeight, double latitudeInDegrees)
{
    //what on earth do I do here to calculate the Y offset on the map?
    return ???;
}

我已经尝试了我在网上找到的各种东西(包括 wikipedia 和 stackoverflow),但没有一个对我有用。我可能在做一些愚蠢的事情,但我不知道是什么。谁能拯救我的理智?

4

1 回答 1

5
public double CalculateY(double mapHeight, double latitudeInDegrees)
{
    return Math.Log(Math.Tan(latitudeInDegrees / 360d * Math.PI + Math.PI / 4));
}

不要记住用 mapHeight 缩放 y(你应该知道 latitudeInDegrees 的最大值和最小值)

引用自维基百科:

在北纬或南纬 70° 以上的纬度,墨卡托投影实际上是不可用的。

您应该编写如下代码:

private double CalculateYRelative(double latitudeInDegrees)
{
    return Math.Log(Math.Tan(latitudeInDegrees / 360d * Math.PI + Math.PI / 4));
}
...
minY = CalculateYRelative(MinLatitudeInDegrees);
maxY = CalculateYRelative(MaxLatitudeInDegrees);
...
public double CalculateY(double mapHeight, double latitudeInDegrees)
{
    return mapHeight*
           (CalculateYRelative(latitudeInDegrees) - minY) / (maxY - minY);
}

了解更多信息:

维基百科

同样的问题

同问2

于 2009-10-10T19:13:21.670 回答