Coverage for pygeodesy/ellipsoidalVincenty.py: 99%
175 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-10-11 16:04 -0400
« prev ^ index » next coverage.py v7.2.2, created at 2023-10-11 16:04 -0400
2# -*- coding: utf-8 -*-
4u'''Ellipsoidal, I{Vincenty}-based geodesy.
6I{Thaddeus Vincenty}'s geodetic (lat-/longitude) L{LatLon}, geocentric
7(ECEF) L{Cartesian} and L{VincentyError} classes and functions L{areaOf},
8L{intersections2}, L{nearestOn} and L{perimeterOf}.
10Pure Python implementation of geodesy tools for ellipsoidal earth models,
11transcoded from JavaScript originals by I{(C) Chris Veness 2005-2016}
12and published under the same MIT Licence**, see U{Vincenty geodesics
13<https://www.Movable-Type.co.UK/scripts/LatLongVincenty.html>}. More
14at U{geographiclib<https://PyPI.org/project/geographiclib>} and
15U{GeoPy<https://PyPI.org/project/geopy>}.
17Calculate geodesic distance between two points using the U{Vincenty
18<https://WikiPedia.org/wiki/Vincenty's_formulae>} formulae and one of
19several ellipsoidal earth models. The default model is WGS-84, the
20most widely used globally-applicable model for the earth ellipsoid.
22Other ellipsoids offering a better fit to the local geoid include Airy
23(1830) in the UK, Clarke (1880) in Africa, International 1924 in much
24of Europe, and GRS-67 in South America. North America (NAD83) and
25Australia (GDA) use GRS-80, which is equivalent to the WGS-84 model.
27Great-circle distance uses a I{spherical} model of the earth with the
28mean earth radius defined by the International Union of Geodesy and
29Geophysics (IUGG) as M{(2 * a + b) / 3 = 6371008.7714150598} or about
306,371,009 meter (for WGS-84, resulting in an error of up to about 0.5%).
32Here's an example usage of C{ellipsoidalVincenty}:
34 >>> from pygeodesy.ellipsoidalVincenty import LatLon
35 >>> Newport_RI = LatLon(41.49008, -71.312796)
36 >>> Cleveland_OH = LatLon(41.499498, -81.695391)
37 >>> Newport_RI.distanceTo(Cleveland_OH)
38 866,455.4329158525 # meter
40To change the ellipsoid model used by the Vincenty formulae use:
42 >>> from pygeodesy import Datums
43 >>> from pygeodesy.ellipsoidalVincenty import LatLon
44 >>> p = LatLon(0, 0, datum=Datums.OSGB36)
46or by converting to anothor datum:
48 >>> p = p.toDatum(Datums.OSGB36)
49'''
50# make sure int/int division yields float quotient, see .basics
51from __future__ import division as _; del _ # PYCHOK semicolon
53from pygeodesy.constants import EPS, EPS0, _0_0, _1_0, _2_0, _3_0, _4_0, _6_0
54from pygeodesy.ellipsoidalBase import CartesianEllipsoidalBase, intersecant2, \
55 _nearestOn
56from pygeodesy.ellipsoidalBaseDI import LatLonEllipsoidalBaseDI, \
57 _intersection3, _intersections2, _TOL_M
58from pygeodesy.errors import _and, _ValueError, _xkwds
59from pygeodesy.fmath import Fpolynomial, hypot, hypot1
60from pygeodesy.interns import _ambiguous_, _antipodal_, _COLONSPACE_, \
61 _to_, _SPACE_, _limit_ # PYCHOK used!
62from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS, _ALL_OTHER
63from pygeodesy.namedTuples import Destination2Tuple, Destination3Tuple, \
64 Distance3Tuple
65from pygeodesy.points import Fmt, ispolar # PYCHOK exported
66from pygeodesy.props import deprecated_function, deprecated_method, \
67 Property_RO, property_doc_
68# from pygeodesy.streprs import Fmt # from .points
69from pygeodesy.units import Number_, Scalar_
70from pygeodesy.utily import atan2b, atan2d, sincos2, sincos2d, unroll180, wrap180
72from math import atan2, cos, degrees, fabs, radians, tan
74__all__ = _ALL_LAZY.ellipsoidalVincenty
75__version__ = '23.10.08'
77_antipodal_to_ = _SPACE_(_antipodal_, _to_)
80class VincentyError(_ValueError):
81 '''Error raised from I{Vincenty}'s C{direct} and C{inverse} methods
82 for coincident points or lack of convergence.
83 '''
84 pass
87class Cartesian(CartesianEllipsoidalBase):
88 '''Extended to convert geocentric, L{Cartesian} points to
89 Vincenty-based, ellipsoidal, geodetic L{LatLon}.
90 '''
91 @Property_RO
92 def Ecef(self):
93 '''Get the ECEF I{class} (L{EcefVeness}), I{lazily}.
94 '''
95 return _MODS.ecef.EcefVeness
97 def toLatLon(self, **LatLon_and_kwds): # PYCHOK LatLon=LatLon, datum=None
98 '''Convert this cartesian point to a C{Vincenty}-based geodetic point.
100 @kwarg LatLon_and_kwds: Optional L{LatLon} and L{LatLon} keyword
101 arguments as C{datum}. Use C{B{LatLon}=...,
102 B{datum}=...} to override this L{LatLon}
103 class or specify C{B{LatLon}=None}.
105 @return: The geodetic point (L{LatLon}) or if B{C{LatLon}} is C{None},
106 an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)}
107 with C{C} and C{M} if available.
109 @raise TypeError: Invalid B{C{LatLon_and_kwds}} argument.
110 '''
111 kwds = _xkwds(LatLon_and_kwds, LatLon=LatLon, datum=self.datum)
112 return CartesianEllipsoidalBase.toLatLon(self, **kwds)
115class LatLon(LatLonEllipsoidalBaseDI):
116 '''Using the formulae devised by U{I{Thaddeus Vincenty (1975)}
117 <https://WikiPedia.org/wiki/Vincenty's_formulae>} for an (oblate)
118 ellipsoidal model of the earth to compute the geodesic distance
119 and bearings between two given points or the destination point
120 given an start point and (initial) bearing.
122 Set the earth model to be used with the keyword argument
123 datum. The default is Datums.WGS84, which is the most globally
124 accurate. For other models, see the Datums in module datum.
126 Note: This implementation of I{Vincenty} methods may not converge
127 for some valid points, raising a L{VincentyError}. In that case,
128 a result may be obtained by increasing the tolerance C{epsilon}
129 and/or iteration C{limit}, see properties L{LatLon.epsilon} and
130 L{LatLon.iterations}.
131 '''
132 _epsilon = 1e-12 # radians, about 6 um
133# _iteration = None # iteration number from .named._NamedBase
134 _iterations = 201 # 5, default max, 200 vs Veness' 1,000
136 @deprecated_method
137 def bearingTo(self, other, wrap=False): # PYCHOK no cover
138 '''DEPRECATED, use method L{initialBearingTo} or L{bearingTo2}.
139 '''
140 return self.initialBearingTo(other, wrap=wrap)
142 @Property_RO
143 def Ecef(self):
144 '''Get the ECEF I{class} (L{EcefVeness}), I{lazily}.
145 '''
146 return _MODS.ecef.EcefVeness
148 @property_doc_(''' the convergence epsilon (C{radians}).''')
149 def epsilon(self):
150 '''Get the convergence epsilon (C{radians}).
151 '''
152 return self._epsilon
154 @epsilon.setter # PYCHOK setter!
155 def epsilon(self, epsilon):
156 '''Set the convergence epsilon (C{radians}).
158 @raise TypeError: Non-scalar B{C{epsilon}}.
160 @raise ValueError: Out of bounds B{C{epsilon}}.
161 '''
162 self._epsilon = Scalar_(epsilon=epsilon)
164 @property_doc_(''' the iteration limit (C{int}).''')
165 def iterations(self):
166 '''Get the iteration limit (C{int}).
167 '''
168 return self._iterations - 1
170 @iterations.setter # PYCHOK setter!
171 def iterations(self, limit):
172 '''Set the iteration limit (C{int}).
174 @raise TypeError: Non-scalar B{C{limit}}.
176 @raise ValueError: Out-of-bounds B{C{limit}}.
177 '''
178 self._iterations = Number_(limit, name=_limit_, low=4, high=1000) + 1
180 def toCartesian(self, **Cartesian_datum_kwds): # PYCHOK Cartesian=Cartesian, datum=None
181 '''Convert this point to C{Vincenty}-based cartesian (ECEF)
182 coordinates.
184 @kwarg Cartesian_datum_kwds: Optional L{Cartesian}, B{C{datum}} and other
185 keyword arguments, ignored if C{B{Cartesian}=None}. Use
186 C{B{Cartesian}=...} to override this L{Cartesian} class
187 or specify C{B{Cartesian}=None}.
189 @return: The cartesian point (L{Cartesian}) or if B{C{Cartesian}}
190 is C{None}, an L{Ecef9Tuple}C{(x, y, z, lat, lon, height,
191 C, M, datum)} with C{C} and C{M} if available.
193 @raise TypeError: Invalid B{C{Cartesian}}, B{C{datum}} or other
194 B{C{Cartesian_datum_kwds}}.
195 '''
196 kwds = _xkwds(Cartesian_datum_kwds, Cartesian=Cartesian,
197 datum=self.datum)
198 return LatLonEllipsoidalBaseDI.toCartesian(self, **kwds)
200 def _Direct(self, distance, bearing, llr, height):
201 '''(INTERNAL) Direct Vincenty method.
203 @raise TypeError: The B{C{other}} point is not L{LatLon}.
205 @raise ValueError: If this and the B{C{other}} point's L{Datum}
206 ellipsoids are not compatible.
208 @raise VincentyError: Vincenty fails to converge for the current
209 L{LatLon.epsilon} and L{LatLon.iterations}
210 limits.
211 '''
212 E = self.ellipsoid()
213 f = E.f
215 sb, cb = sincos2d(bearing)
216 s1, c1, t1 = _sincostan3r(self.phi, f)
218 eps = self.epsilon
219 s12 = atan2(t1, cb) * _2_0
220 sa, ca2 = _sincos22(c1 * sb)
221 A, B = _AB2(ca2 * E.e22) # e22 == (a / b)**2 - 1
222 s = d = distance / (A * E.b)
223 for i in range(1, self._iterations): # 1-origin
224 ss, cs = sincos2(s)
225 c2sm, e = cos(s12 + s), s
226 s = _Ds(B, cs, ss, c2sm, d)
227 e = fabs(s - e)
228 if e < eps:
229 self._iteration = i
230 break
231 else:
232 t = self._no_convergence(e)
233 raise VincentyError(t, txt=repr(self)) # self.toRepr()
235 t = s1 * ss - c1 * cs * cb
236 # final bearing (reverse azimuth +/- 180)
237 d = atan2b(sa, -t)
238 if llr:
239 b = cb * ss
240 a = atan2d(s1 * cs + c1 * b, hypot(sa, t) * E.b_a)
241 b = atan2d(sb * ss, -s1 * b + c1 * cs) + self.lon \
242 - degrees(_Dl(f, ca2, sa, s, cs, ss, c2sm))
243 t = Destination3Tuple(a, wrap180(b), d)
244 r = self._Direct2Tuple(self.classof, height, t)
245 else:
246 r = Destination2Tuple(None, d, name=self.name)
247 r._iteration = i
248 return r
250 def _Inverse(self, other, wrap, azis=True): # PYCHOK signature
251 '''(INTERNAL) Inverse Vincenty method.
253 @raise TypeError: The B{C{other}} point is not L{LatLon}.
255 @raise ValueError: If this and the B{C{other}} point's L{Datum}
256 ellipsoids are not compatible.
258 @raise VincentyError: Vincenty fails to converge for the current
259 L{LatLon.epsilon} and L{LatLon.iterations}
260 limits and/or if this and the B{C{other}}
261 point are coincident or near-antipodal.
262 '''
263 E = self.ellipsoids(other)
264 f = E.f
266 s1, c1, _ = _sincostan3r( self.phi, f)
267 s2, c2, _ = _sincostan3r(other.phi, f)
269 c1c2, s1c2 = c1 * c2, s1 * c2
270 c1s2, s1s2 = c1 * s2, s1 * s2
272 eps = self.epsilon
273 d, _ = unroll180(self.lon, other.lon, wrap=wrap)
274 dl = ll = radians(d)
275 for i in range(1, self._iterations): # 1-origin
276 sll, cll = sincos2(ll)
278 ss = hypot(c2 * sll, c1s2 - s1c2 * cll)
279 if ss < EPS: # coincident or antipodal, ...
280 if self.isantipodeTo(other, eps=eps):
281 t = self._is_to(other, True)
282 raise VincentyError(_ambiguous_, txt=t)
283 self._iteration = i
284 # return zeros like Karney, unlike Veness
285 return Distance3Tuple(_0_0, 0, 0, iteration=i)
287 cs = s1s2 + c1c2 * cll
288 s, e = atan2(ss, cs), ll
289 sa, ca2 = _sincos22(c1c2 * sll / ss)
290 if ca2:
291 c2sm = cs - _2_0 * s1s2 / ca2
292 ll = _Dl(f, ca2, sa, s, cs, ss, c2sm, dl)
293 else: # equatorial line
294 ll = dl + f * sa * s
295 e = fabs(ll - e)
296 if e < eps:
297 self._iteration = i
298 break
299# elif abs(ll) > PI and self.isantipodeTo(other, eps=eps):
300# # omitted and applied *after* failure to converge below,
301# # see footnote under Inverse <https://WikiPedia.org/wiki/
302# # Vincenty's_formulae> and <https://GitHub.com/chrisveness/
303# # geodesy/blob/master/latlon-ellipsoidal-vincenty.js>
304# raise VincentyError(_ambiguous_, self._is_to(other, True))
305 else:
306 t = self._is_to(other, self.isantipodeTo(other, eps=eps))
307 raise VincentyError(self._no_convergence(e), txt=t)
309 if ca2: # e22 == (a / b)**2 - 1
310 A, B = _AB2(ca2 * E.e22)
311 s = -A * _Ds(B, cs, ss, c2sm, -s)
313 b = E.b
314# if self.height or other.height:
315# b += self._havg(other)
316 d = b * s
318 if azis: # forward and reverse azimuth
319 s, c = sincos2(ll)
320 f = atan2b(c2 * s, c1s2 - s1c2 * c)
321 r = atan2b(c1 * s, -s1c2 + c1s2 * c)
322 else:
323 f = r = _0_0
324 return Distance3Tuple(d, f, r, name=self.name, iteration=i)
326 def _is_to(self, other, anti):
327 '''(INTERNAL) Return I{'<self> [antipodal] to <other>'} text (C{str}).
328 '''
329 t = _antipodal_to_ if anti else _to_
330 return _SPACE_(repr(self), t, repr(other))
332 def _no_convergence(self, e):
333 '''(INTERNAL) Return I{'no convergence (..): ...'} text (C{str}).
334 '''
335 t = (Fmt.PARENSPACED(*t) for t in ((LatLon.epsilon.name, self.epsilon),
336 (LatLon.iterations.name, self.iterations)))
337 return _COLONSPACE_(Fmt.no_convergence(e), _and(*t))
340def _AB2(u2): # WGS84 e22 = 0.00673949674227643
341 # 2-Tuple C{(A, B)} polynomials
342 if u2:
343 A = Fpolynomial(u2, 16384, 4096, -768, 320, -175).fover(16384)
344 B = Fpolynomial(u2, 0, 256, -128, 74, -47).fover( 1024)
345 return A, B
346 return _1_0, _0_0
349def _c2sm2(c2sm):
350 # C{2 * c2sm**2 - 1}
351 return c2sm**2 * _2_0 - _1_0
354def _Dl(f, ca2, sa, s, cs, ss, c2sm, dl=_0_0):
355 # C{Dl}
356 if f and sa:
357 C = f * ca2 / _4_0
358 C *= f - C * _3_0 + _1_0
359 if C and ss:
360 s += C * ss * (c2sm +
361 C * cs * _c2sm2(c2sm))
362 dl += (_1_0 - C) * f * sa * s
363 return dl
366def _Ds(B, cs, ss, c2sm, d):
367 # C{Ds - d}
368 if B and ss:
369 c2sm2 = _c2sm2(c2sm)
370 ss2 = (ss**2 * _4_0 - _3_0) * (c2sm2 * _2_0 - _1_0)
371 B *= ss * (c2sm + B / _4_0 * (c2sm2 * cs -
372 B / _6_0 * c2sm * ss2))
373 d += B
374 return d
377def _sincos22(sa):
378 # 2-Tuple C{(sin(a), cos(a)**2)}
379 ca2 = _1_0 - sa**2
380 return sa, (_0_0 if ca2 < EPS0 else ca2) # XXX EPS?
383def _sincostan3r(a, f):
384 # I{Reduced} C{(sin(B{a}), cos(B{a}), tan(B{a}))}
385 if a: # see L{sincostan3}
386 t = (_1_0 - f) * tan(a)
387 if t:
388 c = _1_0 / hypot1(t)
389 s = t * c
390 return s, c, t
391 return _0_0, _1_0, _0_0
394@deprecated_function
395def areaOf(points, **datum_wrap):
396 '''DEPRECATED, use function L{ellipsoidalExact.areaOf} or L{ellipsoidalKarney.areaOf}.
397 '''
398 try:
399 return _MODS.ellipsoidalKarney.areaOf(points, **datum_wrap)
400 except ImportError:
401 return _MODS.ellipsoidalExact.areaOf(points, **datum_wrap)
404def intersection3(start1, end1, start2, end2, height=None, wrap=False, # was=True
405 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
406 '''I{Iteratively} compute the intersection point of two lines, each defined
407 by two (ellipsoidal) points or by an (ellipsoidal) start point and an
408 (initial) bearing from North.
410 @arg start1: Start point of the first line (L{LatLon}).
411 @arg end1: End point of the first line (L{LatLon}) or the initial bearing
412 at the first point (compass C{degrees360}).
413 @arg start2: Start point of the second line (L{LatLon}).
414 @arg end2: End point of the second line (L{LatLon}) or the initial bearing
415 at the second point (compass C{degrees360}).
416 @kwarg height: Optional height at the intersection (C{meter}, conventionally)
417 or C{None} for the mean height.
418 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the B{C{start2}}
419 and B{C{end*}} points (C{bool}).
420 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function
421 L{pygeodesy.equidistant}) or C{None} for the preferred
422 C{B{start1}.Equidistant}.
423 @kwarg tol: Tolerance for convergence and for skew line distance and length
424 (C{meter}, conventionally).
425 @kwarg LatLon: Optional class to return the intersection points (L{LatLon})
426 or C{None}.
427 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
428 ignored if C{B{LatLon} is None}.
430 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)} with C{point}
431 a B{C{LatLon}} or if C{B{LatLon} is None}, a L{LatLon4Tuple}C{(lat,
432 lon, height, datum)}.
434 @raise IntersectionError: Skew, colinear, parallel or otherwise
435 non-intersecting lines or no convergence
436 for the given B{C{tol}}.
438 @raise TypeError: Invalid or non-ellipsoidal B{C{start1}}, B{C{end1}},
439 B{C{start2}} or B{C{end2}} or invalid B{C{equidistant}}.
441 @note: For each line specified with an initial bearing, a pseudo-end point
442 is computed as the C{destination} along that bearing at about 1.5
443 times the distance from the start point to an initial gu-/estimate
444 of the intersection point (and between 1/8 and 3/8 of the authalic
445 earth perimeter).
447 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
448 calculating-intersection-of-two-circles>} and U{Karney's paper
449 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME
450 BOUNDARIES} for more details about the iteration algorithm.
451 '''
452 return _intersection3(start1, end1, start2, end2, height=height, wrap=wrap,
453 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
456def intersections2(center1, radius1, center2, radius2, height=None, wrap=False, # was=True
457 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
458 '''I{Iteratively} compute the intersection points of two circles, each defined
459 by an (ellipsoidal) center point and a radius.
461 @arg center1: Center of the first circle (L{LatLon}).
462 @arg radius1: Radius of the first circle (C{meter}, conventionally).
463 @arg center2: Center of the second circle (L{LatLon}).
464 @arg radius2: Radius of the second circle (C{meter}, same units as
465 B{C{radius1}}).
466 @kwarg height: Optional height for the intersection points (C{meter},
467 conventionally) or C{None} for the I{"radical height"}
468 at the I{radical line} between both centers.
469 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{center2}}
470 (C{bool}).
471 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
472 function L{pygeodesy.equidistant}) or C{None} for
473 the preferred C{B{center1}.Equidistant}.
474 @kwarg tol: Convergence tolerance (C{meter}, same units as B{C{radius1}}
475 and B{C{radius2}}).
476 @kwarg LatLon: Optional class to return the intersection points (L{LatLon})
477 or C{None}.
478 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
479 ignored if C{B{LatLon} is None}.
481 @return: 2-Tuple of the intersection points, each a B{C{LatLon}} instance
482 or L{LatLon4Tuple}C{(lat, lon, height, datum)} if C{B{LatLon} is
483 None}. For abutting circles, both points are the same instance,
484 aka the I{radical center}.
486 @raise IntersectionError: Concentric, antipodal, invalid or non-intersecting
487 circles or no convergence for the B{C{tol}}.
489 @raise TypeError: Invalid or non-ellipsoidal B{C{center1}} or B{C{center2}}
490 or invalid B{C{equidistant}}.
492 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.
494 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
495 calculating-intersection-of-two-circles>}, U{Karney's paper
496 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},
497 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and
498 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}
499 intersections.
500 '''
501 return _intersections2(center1, radius1, center2, radius2, height=height, wrap=wrap,
502 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
505def nearestOn(point, point1, point2, within=True, height=None, wrap=False,
506 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
507 '''I{Iteratively} locate the closest point on the geodesic between
508 two other (ellipsoidal) points.
510 @arg point: Reference point (C{LatLon}).
511 @arg point1: Start point of the geodesic (C{LatLon}).
512 @arg point2: End point of the geodesic (C{LatLon}).
513 @kwarg within: If C{True} return the closest point I{between}
514 B{C{point1}} and B{C{point2}}, otherwise the
515 closest point elsewhere on the geodesic (C{bool}).
516 @kwarg height: Optional height for the closest point (C{meter},
517 conventionally) or C{None} or C{False} for the
518 interpolated height. If C{False}, the closest
519 takes the heights of the points into account.
520 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both
521 B{C{point1}} and B{C{point2}} (C{bool}).
522 @kwarg equidistant: An azimuthal equidistant projection (I{class}
523 or function L{pygeodesy.equidistant}) or C{None}
524 for the preferred C{B{point}.Equidistant}.
525 @kwarg tol: Convergence tolerance (C{meter}).
526 @kwarg LatLon: Optional class to return the closest point
527 (L{LatLon}) or C{None}.
528 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword
529 arguments, ignored if C{B{LatLon} is None}.
531 @return: Closest point, a B{C{LatLon}} instance or if C{B{LatLon}
532 is None}, a L{LatLon4Tuple}C{(lat, lon, height, datum)}.
534 @raise ImportError: Package U{geographiclib
535 <https://PyPI.org/project/geographiclib>}
536 not installed or not found, but only if
537 C{B{equidistant}=}L{EquidistantKarney}.
539 @raise TypeError: Invalid or non-ellipsoidal B{C{point}}, B{C{point1}}
540 or B{C{point2}} or invalid B{C{equidistant}}.
542 @raise ValueError: No convergence for the B{C{tol}}.
544 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
545 calculating-intersection-of-two-circles>} and U{Karney's paper
546 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME
547 BOUNDARIES} for more details about the iteration algorithm.
548 '''
549 return _nearestOn(point, point1, point2, within=within, height=height, wrap=wrap,
550 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
553@deprecated_function
554def perimeterOf(points, **closed_datum_wrap):
555 '''DEPRECATED, use function L{ellipsoidalExact.perimeterOf} or L{ellipsoidalKarney.perimeterOf}.
556 '''
557 try:
558 return _MODS.ellipsoidalKarney.perimeterOf(points, **closed_datum_wrap)
559 except ImportError:
560 return _MODS.ellipsoidalExact.perimeterOf(points, **closed_datum_wrap)
563__all__ += _ALL_OTHER(Cartesian, LatLon, intersecant2, # from .ellipsoidalBase
564 intersection3, intersections2, ispolar, # from .points
565 nearestOn) + _ALL_DOCS(areaOf, perimeterOf) # deprecated
567# **) MIT License
568#
569# Copyright (C) 2016-2023 -- mrJean1 at Gmail -- All Rights Reserved.
570#
571# Permission is hereby granted, free of charge, to any person obtaining a
572# copy of this software and associated documentation files (the "Software"),
573# to deal in the Software without restriction, including without limitation
574# the rights to use, copy, modify, merge, publish, distribute, sublicense,
575# and/or sell copies of the Software, and to permit persons to whom the
576# Software is furnished to do so, subject to the following conditions:
577#
578# The above copyright notice and this permission notice shall be included
579# in all copies or substantial portions of the Software.
580#
581# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
582# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
583# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
584# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
585# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
586# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
587# OTHER DEALINGS IN THE SOFTWARE.