【问题标题】:Calculate Y position from latitude in degrees on mercator projection在墨卡托投影上从纬度计算 Y 位置(以度为单位)
【发布时间】:2013-12-28 14:54:08
【问题描述】:

在给定纬度的情况下,我正在尝试使用墨卡托投影来计算地图上的 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),但没有一个对我有用。我可能在做一些愚蠢的事情,但我不知道是什么。谁能拯救我的理智?

【问题讨论】:

  • 很抱歉进行了多次编辑。我创建了答案的发布版本。

标签: c# .net mapping latitude-longitude


【解决方案1】:
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);
}

更多信息:

Wikipedia

Same question

Same question 2

【讨论】:

  • 您关于缩放的评论对我来说毫无意义。你能澄清一下吗?一旦我知道最大和最小纬度,我如何使用它来根据 mapHeight 进行调整?
  • 非常感谢。我已经看过你所有的链接答案,但没有一个解释足以让我得到这个工作。您的修改帮助我理解了这一点。
  • @spanks,看看我的新编辑。 MinLatitudeInDegrees 和 MaxLatitudeInDegrees 是您的常量。您应该使用此 const 计算 minY 和 maxY 并在 CalculateY 中使用结果。 CalculateY 返回 [0, maxHeight] 中的值
猜你喜欢
  • 1970-01-01
  • 2012-12-29
  • 1970-01-01
  • 2012-07-04
  • 1970-01-01
  • 2023-03-30
  • 2011-01-07
  • 2023-04-06
  • 2021-04-28
相关资源
最近更新 更多