Coverage for pygeodesy/ellipsoidalBaseDI.py : 97%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
C{LatLonEllipsoidalBaseDI} and functions. ''' # make sure int/int division yields float quotient, see .basics
_ValueError, _xellipsoidal, _xError, _xkwds_not _height_, _no_, _near_concentric_, _reframe_, \ _too_, _0_0 Intersection3Tuple, _LL4Tuple # from pygeodesy.props import Property_RO # from .ellipsoidalBase
'''(INTERNAL) Base class for C{ellipsoidal*.LatLon} classes with I{overloaded} C{Direct} and C{Inverse} methods. '''
'''Compute the initial and final bearing (forward and reverse azimuth) from this to an other point, using this C{Inverse} method. See methods L{initialBearingTo} and L{finalBearingTo} for more details.
@arg other: The other point (C{LatLon}). @kwarg wrap: Wrap and unroll longitudes (C{bool}).
@return: A L{Bearing2Tuple}C{(initial, final)}.
@raise TypeError: The B{C{other}} point is not C{LatLon}.
@raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are not compatible. '''
'''Compute the destination point after having travelled for the given distance from this point along a geodesic given by an initial bearing, using this C{Direct} method. See method L{destination2} for more details.
@arg distance: Distance (C{meter}). @arg bearing: Initial bearing in (compass C{degrees360}). @kwarg height: Optional height, overriding the default height (C{meter}, same units as C{distance}).
@return: The destination point (C{LatLon}). '''
'''Compute the destination point and the final bearing (reverse azimuth) after having travelled for the given distance from this point along a geodesic given by an initial bearing, using this C{Direct} method.
The distance must be in the same units as this point's datum axes, conventionally C{meter}. The distance is measured on the surface of the ellipsoid, ignoring this point's height.
The initial and final bearing (forward and reverse azimuth) are in compass C{degrees360}.
The destination point's height and datum are set to this point's height and datum, unless the former is overridden.
@arg distance: Distance (C{meter}). @arg bearing: Initial bearing (compass C{degrees360}). @kwarg height: Optional height, overriding the default height (C{meter}, same units as C{distance}).
@return: A L{Destination2Tuple}C{(destination, final)}. '''
'''(INTERNAL) I{Karney}'s C{Direct} method.
@return: A L{Destination2Tuple}C{(destination, final)} or a L{Destination3Tuple}C{(lat, lon, final)} if B{C{LL}} is C{None}. '''
'''(INTERNAL) Helper for C{._Direct} result L{Destination2Tuple}. ''' **_xkwds_not(None, epoch=self.epoch, reframe=self.reframe))
'''Compute the distance between this and an other point along a geodesic, using this C{Inverse} method. See method L{distanceTo3} for more details.
@arg other: The other point (C{LatLon}). @kwarg wrap: Wrap and unroll longitudes (C{bool}).
@return: Distance (C{meter}).
@raise TypeError: The B{C{other}} point is not C{LatLon}.
@raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are not compatible. '''
'''Compute the distance, the initial and final bearing along a geodesic between this and an other point, using this C{Inverse} method.
The distance is in the same units as this point's datum axes, conventionally meter. The distance is measured on the surface of the ellipsoid, ignoring this point's height.
The initial and final bearing (forward and reverse azimuth) are in compass C{degrees360} from North.
@arg other: Destination point (C{LatLon}). @kwarg wrap: Wrap and unroll longitudes (C{bool}).
@return: A L{Distance3Tuple}C{(distance, initial, final)}.
@raise TypeError: The B{C{other}} point is not C{LatLon}.
@raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are not compatible. '''
'''Compute the final bearing (reverse azimuth) after having travelled for the given distance along a geodesic given by an initial bearing from this point, using this C{Direct} method. See method L{destination2} for more details.
@arg distance: Distance (C{meter}). @arg bearing: Initial bearing (compass C{degrees360}).
@return: Final bearing (compass C{degrees360}). '''
'''Compute the final bearing (reverse azimuth) after having travelled along a geodesic from this point to an other point, using this C{Inverse} method. See method L{distanceTo3} for more details.
@arg other: The other point (C{LatLon}). @kwarg wrap: Wrap and unroll longitudes (C{bool}).
@return: Final bearing (compass C{degrees360}).
@raise TypeError: The B{C{other}} point is not C{LatLon}.
@raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are not compatible. '''
'''N/A, invalid (C{None} I{always}). ''' return None # PYCHOK no cover
'''Compute the initial bearing (forward azimuth) to travel along a geodesic from this point to an other point, using this C{Inverse} method. See method L{distanceTo3} for more details.
@arg other: The other point (C{LatLon}). @kwarg wrap: Wrap and unroll longitudes (C{bool}).
@return: Initial bearing (compass C{degrees360}).
@raise TypeError: The B{C{other}} point is not C{LatLon}.
@raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are not compatible. '''
'''Return the point at given fraction along the geodesic between this and an other point, using this C{Direct} and C{Inverse} methods.
@arg other: The other point (C{LatLon}). @arg fraction: Fraction between both points ranging from 0, meaning this to 1, the other point (C{float}). @kwarg height: Optional height, overriding the fractional height (C{meter}). @kwarg wrap: Wrap and unroll longitudes (C{bool}).
@return: Intermediate point (C{LatLon}).
@raise TypeError: The B{C{other}} point is not C{LatLon}.
@raise UnitError: Invalid B{C{fraction}} or B{C{height}}.
@raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are not compatible.
@see: Methods L{distanceTo3} and L{destination}. '''
'''(INTERNAL) I{Karney}'s C{Inverse} method.
@return: A L{Distance3Tuple}C{(distance, initial, final)}.
@raise TypeError: The B{C{other}} point is not L{LatLon}.
@raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are not compatible. '''
'''(INTERNAL) Get an C{Equidistant*(0, 0, ...)} instance. '''
elif not issubclassof(equidistant, *_Equidistants): # PYCHOK no cover t = tuple(_.__name__ for _ in _Equidistants) raise _IsnotError(*t, equidistant=equidistant)
equidistant=None, tol=_TOL_M, LatLon=None, **LatLon_kwds): '''(INTERNAL) Intersect two (ellipsoidal) path, see L{_intersection} above, separated to allow callers to embellish any exceptions. '''
# E = s1.ellipsoids(s2) # assert E == s1.ellispoids(e1) == s1.ellipsoids(e2)
# get the azimuthal equidistant projection
# gu-/estimate initial intersection, spherically ... _LLS(e1.lat, e1.lon, height=e1.height), _LLS(s2.lat, s2.lon, height=s2.height), _LLS(e2.lat, e2.lon, height=e2.height), height=height, wrap=False, LatLon=_LLS) # unrolled already
# ... and iterate as Karney describes, @see: # LatLonEllipsoidalBase.LatLon.intersections2 # convert start and end points to projection # space and compute an intersection there A.forward(e1.lat, e1.lon), A.forward(s2.lat, s2.lon), A.forward(e2.lat, e2.lon), eps=e, useZ=False) # convert intersection back to geodetic # break if below tolerance or if unchanged else: raise IntersectionError(_no_(Fmt.convergence(e)))
equidistant=None, tol=_TOL_M, LatLon=None, **LatLon_kwds): '''(INTERNAL) Iteratively compute the intersection point of two paths, each defined by an (ellipsoidal) start and end point. '''
equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds) raise _xError(x, start1=start1, end1=end1, start2=start2, end2=end2)
equidistant=None, tol=_TOL_M, LatLon=None, **LatLon_kwds): '''(INTERNAL) Iteratively compute the intersection points of two circles, each defined by an (ellipsoidal) center point and a radius. '''
equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds) raise _xError(x, center1=center1, radius1=radius1, center2=center2, radius2=radius2)
equidistant=None, tol=_TOL_M, LatLon=None, **LatLon_kwds): '''(INTERNAL) Intersect two (ellipsoidal) circles, see L{_intersections2} above, separated to allow callers to embellish any exceptions. '''
# get the azimuthal equidistant projection
raise _ValueError(_exceed_PI_radians_)
# distance between centers and radii are # measured along the ellipsoid's surface raise IntersectionError(_near_concentric_) raise IntersectionError(_too_(Fmt.distant(m)))
# gu-/estimate initial intersections, spherically ... _LLS(c2.lat, c2.lon, height=c2.height), r2, radius=r, height=height, wrap=False, too_d=m) # unrolled already
# ... and iterate as Karney describes, @see: # LatLonEllipsoidalBase.LatLon.intersections2 # convert centers to projection space # compute intersections in projection space t2, r2, # XXX * t2.scale?, sphere=False, too_d=m) # convert intersections back to geodetic t, d = t1, d1 # PYCHOK no cover else: # consider only the closer intersection # break if below tolerance or if unchanged ta = t # PYCHOK no coves else: raise IntersectionError(_no_(Fmt.convergence(tol)))
pass # PYCHOK no cover _latlon4(ts[1], h, n, c2)) elif len(ts) == 1: # PYCHOK no cover ta = ts[0] # assume abutting else: # PYCHOK no cover raise _AssertionError(ts=ts) r = _latlon4(ta, h, n, c1) return r, r
equidistant=None, tol=_TOL_M, LatLon=None, **LatLon_kwds): '''(INTERNAL) Get closest point, imported by .ellipsoidalExact, -GeodSolve, -Karney and -Vincenty to embellish exceptions. ''' equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds) except (TypeError, ValueError) as x: raise _xError(x, point=point, point1=point1, point2=point2)
equidistant=None, tol=_TOL_M, LatLon=None, **LatLon_kwds): '''(INTERNAL) Get closest point, like L{_intersects2} above, separated to allow callers to embellish any exceptions. '''
# get the azimuthal equidistant projection
# gu-/estimate initial nearestOn, spherically ... wrap=False, only! _LLS(p1.lat, p1.lon, height=p1.height), _LLS(p2.lat, p2.lon, height=p2.height), within=within, height=height) if height is False: # PYCHOK no cover h = t.height # use heights as Z h1 = p1.height h2 = p2.height else:
# ... and iterate as Karney describes, @see: # LatLonEllipsoidalBase.LatLon.intersections2 # closest to origin, .z to interpolate height # convert points to projection space # and compute the nearest one there _v(A.forward(p2.lat, p2.lon), h2), within=within) # convert nearest one back to geodetic # break if below tolerance or if unchanged h = v.z # nearest interpolated else: raise _ValueError(_no_(Fmt.convergence(tol)))
# wrap, unroll and replace longitude if different p2 = p2.classof(p2.lat, lon, **_xkwds_not(None, height=getattr(p2, _height_, None), datum=getattr(p2, _datum_, None), epoch=getattr(p2, _epoch_, None), reframe=getattr(p2, _reframe_, None)))
# **) MIT License # # Copyright (C) 2016-2021 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |