Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
lat : float
target geodetic latitude
lon : float
target geodetic longitude
h : float
target altitude above geodetic ellipsoid (meters)
based on:
You, Rey-Jer. (2000). Transformation of Cartesian to Geodetic Coordinates without Iterations.
Journal of Surveying Engineering. doi: 10.1061/(ASCE)0733-9453
"""
if ell is None:
ell = Ellipsoid()
r = sqrt(x ** 2 + y ** 2 + z ** 2)
E = sqrt(ell.semimajor_axis ** 2 - ell.semiminor_axis ** 2)
# eqn. 4a
u = sqrt(0.5 * (r ** 2 - E ** 2) + 0.5 * sqrt((r ** 2 - E ** 2) ** 2 + 4 * E ** 2 * z ** 2))
Q = hypot(x, y)
huE = hypot(u, E)
# eqn. 4b
try:
Beta = atan(huE / u * z / hypot(x, y))
except ZeroDivisionError:
def rsphere_authalic(ell: Ellipsoid = None) -> float:
"""computes the radius of the sphere with equal surface area as the ellipsoid
Parameters
----------
ell : Ellipsoid, optional
reference ellipsoid
Returns
-------
radius: float
radius of sphere
"""
if ell is None:
ell = Ellipsoid()
e = ell.eccentricity
if e > 0:
f1 = ell.semimajor_axis ** 2 / 2
f2 = (1 - e ** 2) / (2 * e)
f3 = log((1 + e) / (1 - e))
return sqrt(f1 * (1 + f2 * f3))
else:
return ell.semimajor_axis
Parameters
----------
ell : Ellipsoid, optional
reference ellipsoid
method: str, optional
"mean" or "norm"
Returns
-------
radius: float
radius of sphere
"""
if ell is None:
ell = Ellipsoid()
if method == "mean":
return (2 * ell.semimajor_axis + ell.semiminor_axis) / 3
elif method == "norm":
return (ell.semimajor_axis ** 2 * ell.semiminor_axis) ** (1 / 3)
else:
raise Exception("pymap3d.rsphere.rsphere_triaxial: method must be mean or norm")
def vdist_point(Lat1: float, Lon1: float, Lat2: float, Lon2: float, ell: Ellipsoid = None) -> typing.Tuple[float, float]:
if ell is None:
ell = Ellipsoid()
# %% Input check:
if (abs(Lat1) > 90) | (abs(Lat2) > 90):
raise ValueError("Input latitudes must be in [-90, 90] degrees.")
# %% Supply WGS84 earth ellipsoid axis lengths in meters:
a = ell.semimajor_axis
b = ell.semiminor_axis
f = ell.flattening
# %% convert inputs in degrees to radians:
lat1 = radians(Lat1)
lon1 = radians(Lon1)
lat2 = radians(Lat2)
lon2 = radians(Lon2)
# %% correct for errors at exact poles by adjusting 0.6 millimeters:
if abs(pi / 2 - abs(lat1)) < 1e-10:
lat1 = sign(lat1) * (pi / 2 - 1e-10)
def rsphere_eqavol(ell: Ellipsoid = None) -> float:
"""computes the radius of the sphere with equal volume as the ellipsoid
Parameters
----------
ell : Ellipsoid, optional
reference ellipsoid
Returns
-------
radius: float
radius of sphere
"""
if ell is None:
ell = Ellipsoid()
f = ell.flattening
return ell.semimajor_axis * (1 - f / 3 - f ** 2 / 9)
deg : bool, optional
degrees input/output (False: radians in/out)
Results
-------
lats : list of float
latitudes of points along track
lons : list of float
longitudes of points along track
Based on code posted to the GMT mailing list in Dec 1999 by Jim Levens and by Jeff Whitaker
"""
if ell is None:
ell = Ellipsoid()
if npts < 2:
raise ValueError("npts must be greater than 1")
if npts == 2:
return [lat1, lat2], [lon1, lon2]
if deg:
rlat1 = radians(lat1)
rlon1 = radians(lon1)
rlat2 = radians(lat2)
rlon2 = radians(lon2)
else:
rlat1, rlon1, rlat2, rlon2 = lat1, lon1, lat2, lon2
gcarclen = 2.0 * asin(sqrt((sin((rlat1 - rlat2) / 2)) ** 2 + cos(rlat1) * cos(rlat2) * (sin((rlon1 - rlon2) / 2)) ** 2))
Returns
-------
lat : float
target geodetic latitude
lon : float
target geodetic longitude
h : float
target altitude above geodetic ellipsoid (meters)
based on:
You, Rey-Jer. (2000). Transformation of Cartesian to Geodetic Coordinates without Iterations.
Journal of Surveying Engineering. doi: 10.1061/(ASCE)0733-9453
"""
if ell is None:
ell = Ellipsoid()
r = sqrt(x**2 + y**2 + z**2)
E = sqrt(ell.semimajor_axis**2 - ell.semiminor_axis**2)
# eqn. 4a
u = sqrt(0.5 * (r**2 - E**2) + 0.5 * sqrt((r**2 - E**2)**2 + 4 * E**2 * z**2))
Q = hypot(x, y)
huE = hypot(u, E)
# eqn. 4b
Beta = arctan(huE / u * z / hypot(x, y))
# eqn. 13
def sanitize(lat: "ndarray", ell: Ellipsoid, deg: bool) -> typing.Tuple["ndarray", Ellipsoid]:
if ell is None:
ell = Ellipsoid()
if asarray is not None:
lat = asarray(lat)
if deg:
lat = radians(lat)
if asarray is not None:
if (abs(lat) > pi / 2).any():
raise ValueError("-pi/2 <= latitude <= pi/2")
else:
if abs(lat) > pi / 2:
raise ValueError("-pi/2 <= latitude <= pi/2")
return lat, ell