in metropolis/utils/geo.py [0:0]
def ecef_from_lla(lat, lon, alt):
"""
Compute ECEF XYZ from latitude, longitude and altitude.
All using the WGS84 model.
Altitude is the distance to the WGS84 ellipsoid.
Check results here http://www.oc.nps.edu/oc2902w/coord/llhxyz.htm
>>> lat, lon, alt = 10, 20, 30
>>> x, y, z = ecef_from_lla(lat, lon, alt)
>>> np.allclose(lla_from_ecef(x,y,z), [lat, lon, alt])
True
"""
a2 = WGS84_a ** 2
b2 = WGS84_b ** 2
lat = np.radians(lat)
lon = np.radians(lon)
L = 1.0 / np.sqrt(a2 * np.cos(lat) ** 2 + b2 * np.sin(lat) ** 2)
x = (a2 * L + alt) * np.cos(lat) * np.cos(lon)
y = (a2 * L + alt) * np.cos(lat) * np.sin(lon)
z = (b2 * L + alt) * np.sin(lat)
return x, y, z