【发布时间】:2019-11-18 14:05:53
【问题描述】:
我有一些以千米为单位的 XYZ 坐标(使用 wgs 获得),原点位于地球中心,是否可以将其转换为纬度和经度?
另外:如何在 python 中快速做到这一点?
这里只是这个问题的反面:Converting from longitude\latitude to Cartesian coordinates
【问题讨论】:
我有一些以千米为单位的 XYZ 坐标(使用 wgs 获得),原点位于地球中心,是否可以将其转换为纬度和经度?
另外:如何在 python 中快速做到这一点?
这里只是这个问题的反面:Converting from longitude\latitude to Cartesian coordinates
【问题讨论】:
基于@daphshez 的回答
您可以使用此代码, 此处,x、y 和 z 的单位为 Kms,R 为地球的近似直径。
import numpy as np
R = 6371
lat = np.degrees(np.arcsin(z/R))
lon = np.degrees(np.arctan2(y, x))
【讨论】:
np.acsin 和np.arctan2
这就是你的做法。考虑到两个半径。基于: https://gist.github.com/govert/1b373696c9a27ff4c72a 并经过验证。
import math
x = float(4333216) #in meters
y = float(3193635) #in meters
z = float(3375365) #in meters
a = 6378137.0 #in meters
b = 6356752.314245 #in meters
f = (a - b) / a
f_inv = 1.0 / f
e_sq = f * (2 - f)
eps = e_sq / (1.0 - e_sq)
p = math.sqrt(x * x + y * y)
q = math.atan2((z * a), (p * b))
sin_q = math.sin(q)
cos_q = math.cos(q)
sin_q_3 = sin_q * sin_q * sin_q
cos_q_3 = cos_q * cos_q * cos_q
phi = math.atan2((z + eps * b * sin_q_3), (p - e_sq * a * cos_q_3))
lam = math.atan2(y, x)
v = a / math.sqrt(1.0 - e_sq * math.sin(phi) * math.sin(phi))
h = (p / math.cos(phi)) - v
lat = math.degrees(phi)
lon = math.degrees(lam)
print(lat,lon,h)
【讨论】: