Coverage for pygeodesy/ellipsoidalVincenty.py : 98%

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 -*-
L{Cartesian} amd L{VincentyError} classes and functions L{areaOf} and L{perimeterOf}, I{all ellipsoidal}.
Pure Python implementation of geodesy tools for ellipsoidal earth models, transcribed from JavaScript originals by I{(C) Chris Veness 2005-2016} and published under the same MIT Licence**, see U{Vincenty geodesics <https://www.Movable-Type.co.UK/scripts/LatLongVincenty.html>}. More at U{GeographicLib<https://PyPI.org/project/geographiclib>} and U{GeoPy<https://PyPI.org/project/geopy>}.
Calculate geodesic distance between two points using the U{Vincenty <https://WikiPedia.org/wiki/Vincenty's_formulae>} formulae and one of several ellipsoidal earth models. The default model is WGS-84, the most accurate and widely used globally-applicable model for the earth ellipsoid.
Other ellipsoids offering a better fit to the local geoid include Airy (1830) in the UK, Clarke (1880) in Africa, International 1924 in much of Europe, and GRS-67 in South America. North America (NAD83) and Australia (GDA) use GRS-80, which is equivalent to the WGS-84 model.
Great-circle distance uses a spherical model of the earth with the mean earth radius defined by the International Union of Geodesy and Geophysics (IUGG) as M{(2 * a + b) / 3 = 6371008.7714150598} meter or approx. 6371009 meter (for WGS-84, resulting in an error of up to about 0.5%).
Here's an example usage of C{ellipsoidalVincenty}:
>>> from pygeodesy.ellipsoidalVincenty import LatLon >>> Newport_RI = LatLon(41.49008, -71.312796) >>> Cleveland_OH = LatLon(41.499498, -81.695391) >>> Newport_RI.distanceTo(Cleveland_OH) 866,455.4329158525 # meter
You can change the ellipsoid model used by the Vincenty formulae as follows:
>>> from pygeodesy import Datums >>> from pygeodesy.ellipsoidalVincenty import LatLon >>> p = LatLon(0, 0, datum=Datums.OSGB36)
or by converting to anothor datum:
>>> p = p.convertDatum(Datums.OSGB36)
@newfield example: Example, Examples '''
# make sure int division yields float quotient raise ImportError('%s 1/2 == %d' % ('division', division))
LatLonEllipsoidalBase property_RO, sincos2, unroll180
# all public contants, classes and functions 'Cartesian', 'LatLon', 'ispolar') # from .points
'''Error raised from Vincenty's direct and inverse methods for coincident points or lack of convergence. '''
'''Extended to convert geocentric, L{Cartesian} points to Vincenty-based, ellipsoidal, geodetic L{LatLon}. '''
'''Convert this cartesian point to a C{Vincenty}-based geodetic point.
@keyword kwds: Optional, additional B{C{LatLon}} keyword arguments, ignored if C{B{LatLon}=None}. For example, use C{LatLon=...} to override the L{LatLon} (sub-)class or specify C{B{LatLon}=None}.
@return: The B{C{LatLon}} point (L{LatLon}) or if C{B{LatLon}=None}, an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)} with C{C} and C{M} if available.
@raise TypeError: Invalid B{C{LatLon}}, B{C{datum}} or B{C{kwds}}. '''
'''Using the formulae devised by Thaddeus Vincenty (1975) with an ellipsoidal model of the earth to compute the geodesic distance and bearings between two given points or the destination point given an start point and initial bearing.
Set the earth model to be used with the keyword argument datum. The default is Datums.WGS84, which is the most globally accurate. For other models, see the Datums in module datum.
Note: This implementation of the Vincenty methods may not converge for some valid points, raising a VincentyError. In that case, a result may be obtained by increasing the epsilon and/or the iteration limit, see properties L{LatLon.epsilon} and L{LatLon.iterations}. '''
'''DEPRECATED, use method C{initialBearingTo}. ''' return self.initialBearingTo(other, wrap=wrap)
'''Compute the initial and final bearing (forward and reverse azimuth) from this to an other point, using Vincenty's inverse method. See methods L{initialBearingTo} and L{finalBearingTo} for more details.
@param other: The other point (L{LatLon}). @keyword wrap: Wrap and unroll longitudes (C{bool}).
@return: A L{Bearing2Tuple}C{(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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit and/or if this and the B{C{other}} point are coincident or near-antipodal. '''
'''Compute the destination point after having travelled for the given distance from this point along a geodesic given by an initial bearing, using Vincenty's direct method. See method L{destination2} for more details.
@param distance: Distance (C{meter}). @param bearing: Initial bearing (compass C{degrees360}). @keyword height: Optional height, overriding the default height (C{meter}, same units as C{distance}).
@return: The destination point (L{LatLon}).
@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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit.
@example:
>>> p = LatLon(-37.95103, 144.42487) >>> d = p.destination(54972.271, 306.86816) # 37.6528°S, 143.9265°E '''
'''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 Vincenty's direct method.
The distance must be 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 degrees.
The destination point's height and datum are set to this point's height and datum.
@param distance: Distance (C{meter}). @param bearing: Initial bearing (compass C{degrees360}). @keyword height: Optional height, overriding the default height (C{meter}, same units as B{C{distance}}).
@return: A L{Destination2Tuple}C{(destination, 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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit.
@example:
>>> p = LatLon(-37.95103, 144.42487) >>> b = 306.86816 >>> d, f = p.destination2(54972.271, b) # 37.652818°S, 143.926498°E, 307.1736 ''' height=height))
'''Compute the distance between this and an other point along a geodesic, using Vincenty's inverse method. See method L{distanceTo3} for more details.
@param other: The other point (L{LatLon}). @keyword wrap: Wrap and unroll longitudes (C{bool}).
@return: Distance (C{meter}).
@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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit and/or if this and the B{C{other}} point are coincident or near-antipodal.
@example:
>>> p = LatLon(50.06632, -5.71475) >>> q = LatLon(58.64402, -3.07009) >>> d = p.distanceTo(q) # 969,954.166 m '''
'''Compute the distance, the initial and final bearing along a geodesic between this and an other point, using Vincenty's inverse method.
The distance is in the same units as this point's datum axes, conventially 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 degrees from North.
@param other: Destination point (L{LatLon}). @keyword wrap: Wrap and unroll longitudes (C{bool}).
@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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit and/or if this and the B{C{other}} point are coincident or near-antipodal. '''
def epsilon(self): '''Get the convergence epsilon (scalar). '''
def epsilon(self, eps): '''Set the convergence epsilon.
@param eps: New epsilon (scalar).
@raise TypeError: Non-scalar B{C{eps}}.
@raise ValueError: Out of bounds B{C{eps}}. '''
'''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 Vincenty's direct method. See method L{destination2} for more details.
@param distance: Distance (C{meter}). @param bearing: Initial bearing (compass C{degrees360}).
@return: Final bearing (compass C{degrees360}).
@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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit.
@example:
>>> p = LatLon(-37.95103, 144.42487) >>> b = 306.86816 >>> f = p.finalBearingOn(54972.271, b) # 307.1736 '''
'''Compute the final bearing (reverse azimuth) after having travelled along a geodesic from this point to an other point, using Vincenty's inverse method. See method L{distanceTo3} for more details.
@param other: The other point (L{LatLon}). @keyword wrap: Wrap and unroll longitudes (C{bool}).
@return: Final bearing (compass C{degrees360}).
@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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit and/or if this and the B{C{other}} point are coincident or near-antipodal.
@example:
>>> p = new LatLon(50.06632, -5.71475) >>> q = new LatLon(58.64402, -3.07009) >>> f = p.finalBearingTo(q) # 11.2972°
>>> p = LatLon(52.205, 0.119) >>> q = LatLon(48.857, 2.351) >>> f = p.finalBearingTo(q) # 157.9 '''
'''Compute the initial bearing (forward azimuth) to travel along a geodesic from this point to an other point, using Vincenty's inverse method. See method L{distanceTo3} for more details.
@param other: The other point (L{LatLon}). @keyword wrap: Wrap and unroll longitudes (C{bool}).
@return: Initial bearing (compass C{degrees360}).
@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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit and/or if this and the B{C{other}} point are coincident or near-antipodal.
@example:
>>> p = LatLon(50.06632, -5.71475) >>> q = LatLon(58.64402, -3.07009) >>> b = p.initialBearingTo(q) # 9.141877°
>>> p = LatLon(52.205, 0.119) >>> q = LatLon(48.857, 2.351) >>> b = p.initialBearingTo(q) # 156.11064°
@JSname: I{bearingTo}. '''
def iteration(self): '''Get the iteration number (C{int} or C{None} if not available/applicable). '''
def iterations(self): '''Get the iteration limit (C{int}). '''
def iterations(self, limit): '''Set the iteration limit.
@param limit: New iteration limit (scalar).
@raise TypeError: Non-scalar B{C{limit}}.
@raise ValueError: Out-of-bounds B{C{limit}}. '''
'''Convert this point to C{Vincenty}-based cartesian (ECEF) coordinates.
@keyword kwds: Optional, additional B{C{Cartesian}} keyword arguments, ignored if C{B{Cartesian}=None}. For example, use C{Cartesian=...} to override the L{Cartesian} (sub-)class or specify C{B{Cartesian}=None}.
@return: The B{C{Cartesian}} point (L{Cartesian}) or if C{B{Cartesian}=None}, an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)} with C{C} and C{M} if available.
@raise TypeError: Invalid B{C{Cartesian}}, B{C{datum}} or B{C{kwds}}. '''
'''(INTERNAL) Direct Vincenty method.
@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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit. '''
c2a = 0 A, B = 1, 0 else: # e22 == (a / b)**2 - 1
else: raise VincentyError('%s, %r' % ('no convergence', self))
# final bearing (reverse azimuth +/- 180) # destination latitude in [-90, 90) (1 - E.f) * hypot(sa, t))) # destination longitude in [-180, 180) _dl(E.f, c2a, sa, s, cs, ss, c2sm) + radians(self.lon))
'''(INTERNAL) Inverse Vincenty method.
@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.
@raise VincentyError: Vincenty fails to converge for the current L{LatLon.epsilon} and L{LatLon.iterations} limit and/or if this and the B{C{other}} point are coincident or near-antipodal. '''
raise VincentyError('%s, %r %sto %r' % ('ambiguous', self, 'antipodal ', other))
else:
# # omitted and applied only after failure to converge below, see footnote # # under Inverse at <https://WikiPedia.org/wiki/Vincenty's_formulae> # # <https://GitHub.com/ChrisVeness/geodesy/blob/master/latlon-vincenty.js> # elif abs(ll) > PI and self.isantipodeTo(other, eps=self._epsilon): # raise VincentyError('%s, %r %sto %r' % ('ambiguous', self, # 'antipodal ', other)) else: raise VincentyError('%s, %r %sto %r' % ('no convergence', self, t, other))
# if self.height or other.height: # b += self._havg(other)
'''(INTERNAL) Dl. ''' C * cs * (2 * c2sm**2 - 1)))
'''(INTERNAL) Ds. ''' B / 6.0 * c2sm * ss2))
'''(INTERNAL) Compute A, B polynomials. '''
'''(INTERNAL) Reduced cos, sin, tan. '''
'''DEPRECATED, use function C{ellipsoidalKarney.areaOf}. '''
'''DEPRECATED, use function C{ellipsoidalKarney.perimeterOf}. '''
# **) MIT License # # Copyright (C) 2016-2020 -- 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. |