You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gall立体投影地图经纬度转x/y坐标的问题与修正方案

Gall立体投影经纬度转坐标问题解决过程

问题背景

我有一张采用Gall立体投影的世界地图,与该投影的标准示例完全一致。我尝试用该投影的公式实现经纬度(lat/lng)到x/y坐标的转换,初始JavaScript实现代码如下:

function latLngToGallXY(lat: number, lng: number): { x: number; y: number } {
  const mapWidth = 1024
  const R = mapWidth / (2 * Math.PI)

  // 将经纬度转换为弧度,适配三角函数计算
  const latRad = (lat * Math.PI) / 180
  const lngRad = (lng * Math.PI) / 180

  // 应用Gall立体投影公式
  const x = R * lngRad + 512
  const y = -1 * 2 * R * Math.tan(latRad / 2) + 512

  return { x, y }
}

问题现象

转换(0,0)、(10,10)……(80,80)这类坐标时,X轴计算结果正确,但Y轴的增长速度比预期慢约20%。我尝试过另一组投影公式,也没能解决问题。将标准示例地图叠加到我的地图上后,确认投影形态完全一致,因此问题出在坐标计算逻辑上。

中间尝试的错误公式

我试过一组投影公式,但X轴和Y轴的计算结果均不正确:

const x = (R * lngRad) / Math.sqrt(2) + 512
const y = -1 * R * (1 + Math.sqrt(2) / 2) * Math.tan(latRad / 2) + 512

最终正确实现

最终发现需要对Y轴的计算结果乘以Math.sqrt(2),简化后的正确公式如下:

const mapWidth = 1024
const R = mapWidth / (2 * Math.PI)

const latRad = lat * (Math.PI / 180)
const lngRad = lng * (Math.PI / 180)

const x = R * lngRad + 512
const y = -R * (Math.sqrt(2) + 1) * Math.tan(latRad / 2) + 512

内容的提问来源于stack exchange,提问作者Nikolay Dyankov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 11:26:28