在Python中将XYZ坐标转换为经纬度

在Python中将XYZ坐标转换为经纬度,python,mapping,satellite,Python,Mapping,Satellite,我有一些以公里为单位的XYZ坐标(使用wgs获得),原点在地球的中心,有可能把它转换成纬度和经度吗 另外:如何在python中快速完成这项工作 这里的问题正好相反:基于@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)) 你就是这样做的。考虑到两个半径。基

我有一些以公里为单位的XYZ坐标(使用wgs获得),原点在地球的中心,有可能把它转换成纬度和经度吗

另外:如何在python中快速完成这项工作


这里的问题正好相反:

基于@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))

你就是这样做的。考虑到两个半径。基于: 并进行了验证

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)

谢谢,但它还是给了我不正确的数据。可能是因为wgs认为地球是一个椭球体,有什么想法吗?当然是它的
np.acsin
np.arctan2
是的。我刚才把它修好了