简体   繁体   中英

Python pyproj convert ecef to lla

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:

import pyproj

# Example position data, should be somewhere in Germany
x = 652954.1006
y = 4774619.7919
z = -2217647.7937

ecef = pyproj.Proj(proj='geocent', ellps='WGS84', datum='WGS84')
lla = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84')
lon, lat, alt = pyproj.transform(ecef, lla, x, y, z, radians=True)

print lat, lon, alt

Can someone see where the problem is?

EDIT: By now I guess the calculations are correct, just the data I get from my receiver seems to be faulty. Can someone confirm that?

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM