[GIS] Why does Pyproj fail converting lon lat alt to ECEF

pyprojpythonwgs84

I'm trying to convert a WGS84 lon, lat and alt to ECEF and Pyproj is giving me really weird results. My code is simply:

lon, lat, alt = 49.74761271, -113.2179781, 0
ecef = pyproj.Proj(proj='geocent', ellps='WGS84', datum='WGS84')
lla = pyproj.Proj(proj='latlong', ellps='WGS84', datum='WGS84')    
x, y, z = pyproj.transform(lla, ecef, lon, lat, alt, radians=False)
print x, y, z

which prints

inf inf 0.0

Does anyone know what is wrong?

If I implement it myself it works:

def lla_to_ecef_alt(lat, lon, alt):
    rad = np.float64(6378137.0)        # Radius of the Earth (in meters)
    f = np.float64(1.0/298.257223563)  # Flattening factor WGS84 Model
    np.cosLat = np.cos(lat)
    np.sinLat = np.sin(lat)
    FF     = (1.0-f)**2
    C      = 1/np.sqrt(np.cosLat**2 + FF * np.sinLat**2)
    S      = C * FF

    x = (rad * C + alt)*np.cosLat * np.cos(lon)
    y = (rad * C + alt)*np.cosLat * np.sin(lon)
    z = (rad * S + alt)*np.sinLat
    return x, y, z

What's the difference between them?

Best Answer

Probably because in

lon, lat, alt = 49.74761271, -113.2179781, 0

a lat of -113.2179781 is outside the valid bounds of -90 to 90.