大地坐标系和空间直角坐标系的转换

大地坐标系转空间直角坐标系

import math
A_ALIS = 6378137
B_ALIS = 6356752.3142

E = math.sqrt(A_ALIS * A_ALIS - B_ALIS * B_ALIS) / A_ALIS

def transform_latlonhei2xyz(lon, lat, h):
    """ 大地坐标系 转 空间直角坐标系 """
    lon, lat, h = math.radians(float(lon)), math.radians(float(lat)), float(h)

    W = math.sqrt(1 - E * E * math.sin(lat) * math.sin(lat))
    N = A_ALIS / W

    x = (N + h) * math.cos(lat) * math.cos(lon)
    y = (N + h) * math.cos(lat) * math.sin(lon)
    z = (N * (1 - E * E) + h) * math.sin(lat)

    return x, y, z

print(transform_latlonhei2xyz(lon=121.4533008922, lat=31.1720088176, h=15.069))
# (-2850172.518796192, 4659579.331978275, 3282233.397176004)

  空间直角坐标系转大地坐标系

import math
A_ALIS = 6378137
B_ALIS = 6356752.3142

E2 = (A_ALIS * A_ALIS - B_ALIS * B_ALIS) / (B_ALIS * B_ALIS)

def transform_xyz2lonlathei(x, y, z):
    lon = math.degrees(math.atan2(y, x))

    S = math.atan2(z * A_ALIS, math.sqrt(x * x + y * y) * B_ALIS)

    lat = math.atan2(z + E2 * B_ALIS * math.pow(math.sin(S), 3),
                     (math.sqrt(x * x + y * y) - E * E * A_ALIS * math.pow(math.cos(S), 3)))

    W = math.sqrt(1 - E * E * math.sin(lat) * math.sin(lat))
    N = A_ALIS / W
    hei = math.sqrt(x * x + y * y) / math.cos(lat) - N

    lat = math.degrees(lat)
    return lon, lat, hei


    print(transform_xyz2lonlathei(x=-2850172.518796192, y=4659579.331978275, z=3282233.397176004))
#(121.4533008922, 31.1720088176, 15.06900000013411)

 

posted @ 2020-03-15 16:13  百变小超  阅读(3713)  评论(1编辑  收藏  举报