Coverage for pygeodesy/karney.py : 94%

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 -*-
Wrapper around I{Charles Karney}'s Python classes C{Geodesic} and C{GeodesicLine} and C{Math} functions C{AngDiff}, C{AngNormalize}, C{LatFix} and C{sum} from I{Karney}'s Python package U{geographiclib<https://PyPI.org/project/geographiclib>}, provided that package is installed.
The I{wrapped} class methods return a L{GDict} instance providing access to the C{dict} items by C{key} or by C{attribute} name.
Following are the U{PyGeodesy<https://PyPI.org/project/PyGeodesy>} classes and functions I{transcoded} from I{Karney}'s original C++ U{GeographicLib<https://GeographicLib.SourceForge.io/html/annotated.html>}:
- L{AlbersEqualArea}, L{AlbersEqualArea2}, L{AlbersEqualArea4}, L{AlbersEqualAreaCylindrical}, L{AlbersEqualAreaNorth}, L{AlbersEqualAreaSouth} -- U{AlbersEqualArea<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1AlbersEqualArea.html>}
- L{CassiniSoldner} -- U{CassiniSoldner<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1CassiniSoldner.html>}
- L{EcefKarney} -- U{Geocentric<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1Geocentric.html>}
- L{Elliptic} -- U{EllipticFunction<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1EllipticFunction.html>}
- L{EquidistantExact}, L{EquidistantGeodSolve}, L{EquidistantKarney} -- U{AzimuthalEquidistant <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1AzimuthalEquidistant.html>}
- L{Etm}, L{ExactTransverseMercator} -- U{TransverseMercatorExact <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1TransverseMercatorExact.html>}
- L{GeodesicAreaExact}, L{PolygonArea} -- U{PolygonArea<https://GeographicLib.SourceForge.io/ html/classGeographicLib_1_1PolygonAreaT.html>}
- L{GeodesicExact}, L{GeodesicLineExact} -- U{GeodesicExact<https://GeographicLib.SourceForge.io/ html/classGeographicLib_1_1GeodesicExact.html>}, U{GeodesicLineExact<https://GeographicLib.SourceForge.io/ html/classGeographicLib_1_1GeodesicLineExact.html>}
- L{GeoidKarney} -- U{Geoid<https://GeographicLib.SourceForge.io/html/geoid.html>}
- L{Georef} -- U{Georef<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1Georef.html>}
- L{GnomonicExact}, L{GnomonicGeodSolve}, L{GnomonicKarney} -- U{Gnomonic <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1Gnomonic.html>}
- L{LocalCartesian}, L{Ltp} -- U{LocalCartesian<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1LocalCartesian.html>}
- L{Ups} -- U{PolarStereographic<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1PolarStereographic.html>}
- L{Utm} -- U{TransverseMercator<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1TransverseMercator.html>}
- L{UtmUps}, L{Epsg} -- U{UTMUPS<https://GeographicLib.SourceForge.io/html/ classGeographicLib_1_1UTMUPS.html>}
- L{atan2d}, L{sincos2}, L{sincos2d}-- U{Math<https://GeographicLib.sourceforge.io/html/ classGeographicLib_1_1Math.html>}
The following U{PyGeodesy<https://PyPI.org/project/PyGeodesy>} module, classes and functions are I{wrappers} around some of I{Karney}'s Python U{geographiclib<https://PyPI.org/project/geographiclib>} or C++ U{Utility programs<https://GeographicLib.SourceForge.io/html/utilities.html>}:
- L{karney}, L{ellipsoidalGeodSolve}, L{ellipsoidalKarney}, L{EquidistantKarney}, L{FrechetKarney}, L{geodsolve}, L{GeodesicSolve}, L{GeodesicLineSolve}, L{GnomonicGeodSolve}, L{GnomonicKarney}, L{HeightIDWkarney}
Lastly, spherical functions:
- L{excessKarney_}, L{sphericalTrigonometry.areaOf}
are based on I{Karney}'s post U{Area of a spherical polygon <http://OSGeo-org.1560.x6.Nabble.com/Area-of-a-spherical-polygon-td3841625.html>} and ellipsoidal functions and methods:
- L{ellipsoidalExact.intersection3}, L{ellipsoidalExact.intersections2}, L{ellipsoidalExact.nearestOn}, L{ellipsoidalExact.LatLon.intersection3}, L{ellipsoidalExact.LatLon.intersections2}, L{ellipsoidalExact.LatLon.nearestOn}, L{ellipsoidalExact.LatLon.trilaterate5}
- L{ellipsoidalKarney.intersection3}, L{ellipsoidalKarney.intersections2}, L{ellipsoidalKarney.nearestOn}, L{ellipsoidalKarney.LatLon.intersection3}, L{ellipsoidalKarney.LatLon.intersections2}, L{ellipsoidalKarney.LatLon.nearestOn}, L{ellipsoidalKarney.LatLon.trilaterate5}
- L{ellipsoidalVincenty.intersection3}, L{ellipsoidalVincenty.intersections2}, L{ellipsoidalVincenty.nearestOn}, L{ellipsoidalVincenty.LatLon.intersection3}, L{ellipsoidalVincenty.LatLon.intersections2}, L{ellipsoidalVincenty.LatLon.nearestOn}, L{ellipsoidalVincenty.LatLon.trilaterate5}
are implementations of I{Karney}'s solution posted under U{The B{ellipsoidal} case <https://GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>} and in paper U{Geodesics on an ellipsoid of revolution<https://ArXiv.org/pdf/1102.1215.pdf>} (pp 20-21, section B{14. MARITIME BOUNDARIES}). '''
_lat2_, _lon2_, _0_0, _1_0, _2_0, \ _16_0, _180_0, _360_0 Meter2 as _M2, _1mm as _TOL_M # PYCHOK shared
'''(INTERNAL) Helper. ''' '''Convert this C{*Tuple} to a L{GDict}.
@kwarg updates: Optional updates to apply (C{nam=value} pairs)
''' r.update(updates)
'''9-Tuple C{(a12, lat2, lon2, azi2, s12, m12, M12, M21, S12)} with arc length C{a12}, angles C{lat2}, C{lon2} and azimuth C{azi2} in C{degrees}, distance C{s12} and reduced length C{m12} in C{meter} and area C{S12} in C{meter} I{squared}. '''
'''Basic C{dict} with both key I{and} attribute access to the C{dict} items.
Results of all C{geodesic} methods are returned as a L{GDict} instance. ''' '''Convert this L{GDict} result to a 9-tuple, compatible with I{Karney}'s C{geographiclib} method C{Direct}.
@return: L{Direct9Tuple}C{(a12, lat2, lon2, azi2, s12, m12, M12, M21, S12)} '''
s12=dflt, m12=dflt, M12=dflt, M21=dflt, S12=dflt, **unused): s12, m12, M12, M21, S12)
'''Convert this L{GDict} result to a 12-Tuple, compatible with I{Karney}'s U{GeodSolve<https://GeographicLib.SourceForge.io/html/GeodSolve.1.html>} result.
@return: L{GeodSolve12Tuple}C{(lat1, lon1, azi1, lat2, lon2, azi2, s12, a12, m12, M12, M21, S12)}. '''
def _12Tuple(lat1=dflt, lon1=dflt, azi1=dflt, lat2=dflt, lon2=dflt, azi2=dflt, s12=dflt, a12=dflt, m12=dflt, M12=dflt, M21=dflt, S12=dflt, **unused): return GeodSolve12Tuple(lat1, lon1, azi1, lat2, lon2, azi2, s12, a12, m12, M12, M21, S12)
return _12Tuple(**self)
'''Convert this L{GDict} result to a 10-tuple, compatible with I{Karney}'s C{geographiclib} method C{Indirect}.
@return: L{Inverse10Tuple}C{(a12, s12, salp1, calp1, salp2, calp2, m12, M12, M21, S12)}. '''
salp2=dflt, calp2=dflt, m12=dflt, M12=dflt, M21=dflt, S12=dflt, **unused): m12, M12, M21, S12)
'''Error raised for I{geodesicx}'s methods for lack of convergence or other issues. '''
'''12-Tuple C{(lat1, lon1, azi1, lat2, lon2, azi2, s12, a12, m12, M12, M21, S12)} with angles C{lat1}, C{lon1}, C{azi1}, C{lat2}, C{lon2} and C{azi2} and arc C{a12} all in C{degrees}, distance C{s12} and reduced length C{m12} in C{meter}, area C{S12} in C{meter} I{squared} and geodesic scales C{M12} and C{M21} C{scalar}, see U{GeodSolve <https://GeographicLib.SourceForge.io/html/GeodSolve.1.html>}. ''' # from GeodSolve --help option -f ... lat1 lon1 azi1 lat2 lon2 azi2 s12 a12 m12 M12 M21 S12
'''10-Tuple C{(a12, s12, salp1, calp1, salp2, calp2, m12, M12, M21, S12)} with arc length C{a12} in C{degrees}, distance C{s12} and reduced length C{m12} in C{meter}, area C{S12} in C{meter} I{squared} and sines and cosines of initial and final (forward) azimuths. '''
''''(INTERNAL) Wrapper for some of I{Karney}'s U{geographiclib <https://PyPI.org/project/geographiclib>} classes. '''
'''Get the I{wrapped} C{Geodesic} class, provided the U{geographiclib <https://PyPI.org/project/geographiclib>} package is installed, otherwise an C{ImportError}. '''
'''I{Karney}'s U{Geodesic<https://GeographicLib.SourceForge.io/html/ python/code.html#geographiclib.geodesic.Geodesic>} wrapper. '''
'''New C{Geodesic} instance.
@arg a_ellipsoid: An ellipsoid (L{Ellipsoid}) or datum (L{datum}) or the equatorial radius of the ellipsoid (C{meter}). @arg f: The flattening of the ellipsoid (C{scalar}) if B{C{a_ellipsoid}) is specified as C{meter}. @kwarg name: Optional name (C{str}). ''' else:
'''Get the C{debug} option (C{bool}). ''' return bool(self._debug)
'''Set the C{debug} option.
@arg debug: Include more details in results (C{bool}). '''
'''Return the C{Direct} result. '''
'''Return the destination lat, lon and reverse azimuth (final bearing) in C{degrees}.
@return: L{Destination3Tuple}C{(lat, lon, final)}. '''
'''Get this geodesic's ellipsoid (C{Ellipsoid[2]}). '''
outmask=_Geodesic.STANDARD): '''(INTERNAL) Get C{._GenDirect} result as C{GDict}. ''' s12, m12, M12, M21, S12): s12=s12, m12=m12, M12=M12, M21=M21, S12=S12)
'''(INTERNAL) Get C{._GenInverse} result as C{GDict}. ''' m12, M12, M21, S12): salp1=salp1, calp1=calp1, azi1=atan2d(salp1, calp1), salp2=salp2, calp2=calp2, azi2=atan2d(salp2, calp2), m12=m12, M12=M12, M21=M21, S12=S12, lon1=lon1)
'''Return the C{Inverse} result. '''
'''Return the non-negative, I{angular} distance in C{degrees}. ''' # see .FrechetKarney.distance, .HausdorffKarney._distance # and .HeightIDWkarney._distances # XXX self.DISTANCE needed for 'a12'?
'''Return the distance in C{meter} and the forward and reverse azimuths (initial and final bearing) in C{degrees}.
@return: L{Distance3Tuple}C{(distance, initial, final)}. '''
# PYCHOK .geodesicx.GeodesictExact._Line and -._GDictDirect
# Geodesic.Direct.__doc__ = _Geodesic.Direct.__doc__ # Geodesic.Inverse.__doc__ = _Geodesic.Inverse.__doc__ # Geodesic.Line.__doc__ = _Geodesic.Line.__doc__
'''Get the I{wrapped} C{GeodesicLine} class, provided the U{geographiclib <https://PyPI.org/project/geographiclib>} package is installed, otherwise an C{ImportError}. '''
'''I{Karney}'s U{GeodesicLine <https://GeographicLib.SourceForge.io/html/ python/code.html#geographiclib.geodesicline.GeodesicLine>} wrapper. '''
# GeodesicLine.ArcPosition.__doc__ = _GeodesicLine.ArcPosition.__doc__ # GeodesicLine.Position.__doc__ = _GeodesicLine.Position.__doc__
'''Get the I{wrapped} C{Geodesic.WGS84} I{instance} provided the U{geographiclib<https://PyPI.org/project/geographiclib>} package is installed, otherwise an C{ImportError}. '''
'''Get the imported C{geographiclib}, provided the U{geographiclib <https://PyPI.org/project/geographiclib>} package is installed, otherwise an C{ImportError}. ''' return self._xgeographiclib(_Wrapped.geographiclib)
'''Get the C{Math} class, provided the U{geographiclib <https://PyPI.org/project/geographiclib>} package is installed, otherwise C{None}. ''' # replace karney. with Math. functions except AttributeError: pass
'''(INTERNAL) Import C{geographiclib}. '''
'''Coarsen a scalar to zero.
@return: Coarsened value (C{float}). '''
else:
'''Compute C{deg - deg0}, reduced to C{[-180,180]} accurately.
@return: 2-Tuple C{(delta_angle, residual)} in C{degrees}. '''
d = -_180_0
# def _Equidistant(equidistant, exact=False, geodsolve=False): # # (INTERNAL) Get the C{EquidistantExact}, C{-GeodSolve} or # # C{-Karney} class if B{C{equidistant}} in not callable. # if equidistant is None or not callable(equidistant): # if exact: # from pygeodesy.azimuthal import EquidistantExact as equidistant # elif geodsolve: # from pygeodesy.azimuthal import EquidistantGeodSolve as equidistant # else: # from pygeodesy.azimuthal import EquidistantKarney as equidistant # return equidistant
'''Replace angle in C{degrees} outside [-90,90] by NAN.
@return: Angle C{degrees} or NAN. '''
'''Cascaded summation, like C{.fmath.fsum_}.
@arg vs: Values to be added (C{scalar}[]).
@return: 2-Tuple C{(sum_of_vs, residual)}.
@note: NOT "error-free", see .test/testKarney.py.
@see: U{Algorithm 4.1<http://www.ti3.TUHH.De/paper/rump/OgRuOi05.pdf>}. '''
'''Check finitenessof C{x}.
@return: True if finite. ''' return M.isfinite(x)
'''Reduce angle in C{degrees} to (-180,180].
@return: Reduced angle C{degrees}. '''
# with Python 2.7.16 and 3.7.3 on macOS 10.13.6 # fmod( 0, 360) == 0.0 # fmod( 360, 360) == 0.0 # fmod(-0, 360) == 0.0 # fmod(-0.0, 360) == -0.0 # fmod(-360, 360) == -0.0 # however, using the % operator ... # 0 % 360 == 0 # 360 % 360 == 0 # 360.0 % 360 == 0.0 # -0 % 360 == 0 # -360 % 360 == 0 # -0.0 % 360 == 0.0 # -360.0 % 360 == 0.0
# On Windows 32-bit with Python 2.7, math.fmod(-0.0, 360) # == +0.0. This fixes this bug. See also Math::AngNormalize # in the C++ library, Math::sincosd has a similar fix. if d < _180_0 else (d - _360_0))
'''(INTERNAL) Compute the area or perimeter of a polygon, using a L{GeodesicExact}, L{GeodesicSolve} or (if the C{geographiclib} package is installed) a C{Geodesic} or C{_wrapped.Geodesic} instance. ''' raise _ValueError(wrap=wrap)
# note, lon deltas are unrolled, by default p_(p0.lat, p0.lon)
# gP.Compute returns (number_of_points, perimeter, signed area)
'''Remainder of C{x / y}.
@return: Remainder in the range M{[-y / 2, y / 2]}. ''' except AttributeError: pass
# On Windows 32-bit with python 2.7, math.fmod(-0.0, 360) # == +0.0. This fixes this bug. See also Math::AngNormalize # in the C++ library, Math.sincosd has a similar fix. if z < h else (z - y))
'''Error-free summation like C{Math::sum}.
@return: 2-Tuple C{(sum_u_plus_v, residual)}.
@note: The C{residual} can be the same as B{C{u}} or B{C{v}}.
@see: U{Algorithm 3.1<http://www.ti3.TUHH.De/paper/rump/OgRuOi05.pdf>}. ''' return M.sum(u, v)
# if True: # Algorithm 3.1
# else: # in Math C/C++ # r -= u # t -= v # t = -(r + t)
# u + v = s + t # = round(u + v) + t
'''Accumulate B{C{x}} into C{_sum2(s, t)}.
@see: I{Karney's} C++ U{Accumulator<https://GeographicLib.sourceforge.io/ html/Accumulator_8hpp_source.html>} comments for more details. ''' else:
'''Unroll B{C{lon2 - lon1}} like C{geodesic.Geodesic.Inverse}.
@return: 2-Tuple C{(lon2 - lon1, lon2)} with B{C{lon2}} unrolled if B{C{wrap}} is C{True}, normalized otherwise. ''' else: lon2 = _norm180(lon2)
# **) 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. |