【问题标题】:Converting XYZ coordinates to longitutde/latitude in Python在 Python 中将 XYZ 坐标转换为经度/纬度
【发布时间】:2019-11-18 14:05:53
【问题描述】:

我有一些以千米为单位的 XYZ 坐标(使用 wgs 获得),原点位于地球中心,是否可以将其转换为纬度和经度?

另外:如何在 python 中快速做到这一点?

这里只是这个问题的反面:Converting from longitude\latitude to Cartesian coordinates

【问题讨论】:

    标签: python mapping satellite


    【解决方案1】:

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

    【讨论】:

    • 谢谢,但它仍然给我不正确的数据。可能是因为 wgs 认为地球是一个椭球体,有什么想法吗?
    • 肯定是np.acsinnp.arctan2
    • 是的。我刚刚修好了
    【解决方案2】:

    这就是你的做法。考虑到两个半径。基于: 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 1970-01-01
      • 1970-01-01
      • 2021-05-23
      • 1970-01-01
      • 2013-09-21
      • 1970-01-01
      相关资源
      最近更新 更多