Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def ecef2ned(x, y, z, lat0, lon0, h0, ell=EarthEllipsoid(), deg=True):
e, n, u = ecef2enu(x, y, z, lat0, lon0, h0, ell, deg=deg)
return n, e, -u
def ecef2enu(x, y, z, lat0, lon0, h0, ell=EarthEllipsoid(), deg=True):
x0, y0, z0 = geodetic2ecef(lat0, lon0, h0, ell, deg=deg)
return _uvw2enu(x - x0, y - y0, z - z0, lat0, lon0, deg=deg)
def ecef2geodetic(x, y=None, z=None, ell=EarthEllipsoid(), deg=True):
if y is None:
x, y, z = _depack(x)
"""Algorithm is based on
http://www.astro.uni.torun.pl/~kb/Papers/geod/Geod-BG.htm
This algorithm provides a converging solution to the latitude
equation
in terms of the parametric or reduced latitude form (v)
This algorithm provides a uniform solution over all latitudes as it
does
not involve division by cos(phi) or sin(phi)
"""
ea = ell.a
eb = ell.b
rad = hypot(x, y)
# Constant required for Latitude equation
rho = arctan2(eb * z, ea * rad)
def geodetic2aer(lat, lon, h, lat0, lon0, h0, ell=EarthEllipsoid(), deg=True):
e, n, u = geodetic2enu(lat, lon, h, lat0, lon0, h0, ell, deg=deg)
return enu2aer(e, n, u, deg=deg)
def geodetic2enu(lat, lon, h, lat0, lon0, h0, ell=EarthEllipsoid(), deg=True):
x1, y1, z1 = geodetic2ecef(lat, lon, h, ell, deg=deg)
x2, y2, z2 = geodetic2ecef(lat0, lon0, h0, ell, deg=deg)
dx = x1 - x2
dy = y1 - y2
dz = z1 - z2
return _uvw2enu(dx, dy, dz, lat0, lon0, deg=deg)
def ned2geodetic(n, e, d, lat0, lon0, h0, ell=EarthEllipsoid(), deg=True):
x, y, z = enu2ecef(e, n, -d, lat0, lon0, h0, ell, deg=deg)
return ecef2geodetic(x, y, z, ell, deg=deg)
def enu2ecef(e1, n1, u1, lat0, lon0, alt0, ell=EarthEllipsoid(), deg=True):
x0, y0, z0 = geodetic2ecef(lat0, lon0, alt0, ell, deg=deg)
dx, dy, dz = _enu2uvw(e1, n1, u1, lat0, lon0, deg=deg)
return x0 + dx, y0 + dy, z0 + dz
def ned2ecef(n, e, d, lat0, lon0, h0, ell=EarthEllipsoid(), deg=True):
return enu2ecef(e, n, -d, lat0, lon0, h0, ell, deg=deg)
def aer2ecef(az, el, srange, lat0, lon0, alt0, ell=EarthEllipsoid(), deg=True):
"""
Input: az,el; lat0,lon0 [degrees] srange, alt0 [meters]
output: ECEF x,y,z [meters]
if you specify NaN for srange, return value z will be NaN
"""
# Origin of the local system in geocentric coordinates.
x0, y0, z0 = geodetic2ecef(lat0, lon0, alt0, ell, deg=deg)
# Convert Local Spherical AER to ENU
e1, n1, u1 = aer2enu(az, el, srange, deg=deg)
# Rotating ENU to ECEF
dx, dy, dz = _enu2uvw(e1, n1, u1, lat0, lon0, deg=deg)
# Origin + offset from origin equals position in ECEF
return x0 + dx, y0 + dy, z0 + dz