Python pyproj convert ecef to lla

后端 未结 3 1831
夕颜
夕颜 2021-02-04 12:51

I want to convert x/y/z-ECEF positions to lla (lat/lon/alt) using WGS84 in python with pyproj but it seems like the conversion fails.

Example code is here:



        
相关标签:
3条回答
  • 2021-02-04 13:29

    I tested it with my own self-made coordinate transformation program and have to say the correct order is:

    lon, lat, alt = pyproj.transform(ecef, lla, x, y, z, radians=True)
    

    I think when the designed the library they prefered to think about the longitude as the x-axis and latitude as the y-axis, so they returned it in that order.

    I prefer to use degree, so it is easier for me to read it:

    lon, lat, alt = pyproj.transform(ecef, lla, x, y, z, radians=False)
    print lat, lon, alt
    

    There the ouput is:

    -24.8872207779 82.2128095674 -1069542.17232
    

    I changed the z value to get a more reasonable value which is placed 'near' the surface:

    x= 652954.1006
    y = 4774619.7919
    z =-4167647.7937
    

    Then I get:

    -41.0445318235 82.2128095674 2274.39966936
    

    You can also see that only the latitude value is changing and the longitude is independent of the z-value. This is due to the fact that the z-axis is pointing to the north-pole.

    If you want to read more about how this transformation is done look at this short description: https://en.wikipedia.org/wiki/Geographic_coordinate_conversion#From_geodetic_to_ECEF_coordinates

    0 讨论(0)
  • 2021-02-04 13:30

    Latest pyproj version style

    import pyproj
    
    transformer = pyproj.Transformer.from_crs(
        {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'},
        {"proj":'latlong', "ellps":'WGS84', "datum":'WGS84'},
        )
    x = 652954.1006
    y = 4774619.7919
    z = -2217647.7937
    lon1, lat1, alt1 = transformer.transform(x,y,z,radians=False)
    print (lat1, lon1, alt1 )
    

    You got -24.887220848803032 82.2128095673836 -1069542.1692923503

    0 讨论(0)
  • 2021-02-04 13:54
    lon, lat, alt = pyproj.transform(ecef, lla, x, y, z, radians=True)
    

    Should be :

    lat, lon, alt = pyproj.transform(ecef, lla, x, y, z, radians=True)
    

    Since lla = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84') specify the latlong order

    0 讨论(0)
提交回复
热议问题