Coverage for pygeodesy/ellipsoidalVincenty.py: 99%
178 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-12-02 13:46 -0500
« prev ^ index » next coverage.py v7.2.2, created at 2023-12-02 13:46 -0500
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, _nearestOn
55from pygeodesy.ellipsoidalBaseDI import LatLonEllipsoidalBaseDI, \
56 _intersection3, _intersections2, \
57 _TOL_M, intersecant2
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_doc_, property_RO
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.11.20'
77_antipodal_to_ = _SPACE_(_antipodal_, _to_)
80class VincentyError(_ValueError):
81 '''Error raised by 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, once}.
94 '''
95 return _Ecef()
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, once}.
145 '''
146 return _Ecef()
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 # NAN
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 _Ecef():
378 # get the Ecef class and overwrite property_RO
379 Cartesian.Ecef = LatLon.Ecef = E = _MODS.ecef.EcefVeness
380 return E
383def _sincos22(sa):
384 # 2-Tuple C{(sin(a), cos(a)**2)}
385 ca2 = _1_0 - sa**2
386 return sa, (_0_0 if ca2 < EPS0 else ca2) # XXX EPS?
389def _sincostan3r(a, f):
390 # I{Reduced} 3-tuple C{(sin(B{a}), cos(B{a}), tan(B{a}))}
391 if a: # see L{sincostan3}
392 t = (_1_0 - f) * tan(a)
393 if t:
394 c = _1_0 / hypot1(t)
395 s = c * t
396 return s, c, t
397 return _0_0, _1_0, _0_0
400@deprecated_function
401def areaOf(points, **datum_wrap):
402 '''DEPRECATED, use function L{ellipsoidalExact.areaOf} or L{ellipsoidalKarney.areaOf}.
403 '''
404 try:
405 return _MODS.ellipsoidalKarney.areaOf(points, **datum_wrap)
406 except ImportError:
407 return _MODS.ellipsoidalExact.areaOf(points, **datum_wrap)
410def intersection3(start1, end1, start2, end2, height=None, wrap=False, # was=True
411 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
412 '''I{Iteratively} compute the intersection point of two lines, each defined
413 by two (ellipsoidal) points or by an (ellipsoidal) start point and an
414 (initial) bearing from North.
416 @arg start1: Start point of the first line (L{LatLon}).
417 @arg end1: End point of the first line (L{LatLon}) or the initial bearing
418 at the first point (compass C{degrees360}).
419 @arg start2: Start point of the second line (L{LatLon}).
420 @arg end2: End point of the second line (L{LatLon}) or the initial bearing
421 at the second point (compass C{degrees360}).
422 @kwarg height: Optional height at the intersection (C{meter}, conventionally)
423 or C{None} for the mean height.
424 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the B{C{start2}}
425 and B{C{end*}} points (C{bool}).
426 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function
427 L{pygeodesy.equidistant}) or C{None} for the preferred
428 C{B{start1}.Equidistant}.
429 @kwarg tol: Tolerance for convergence and for skew line distance and length
430 (C{meter}, conventionally).
431 @kwarg LatLon: Optional class to return the intersection points (L{LatLon})
432 or C{None}.
433 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
434 ignored if C{B{LatLon} is None}.
436 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)} with C{point}
437 a B{C{LatLon}} or if C{B{LatLon} is None}, a L{LatLon4Tuple}C{(lat,
438 lon, height, datum)}.
440 @raise IntersectionError: Skew, colinear, parallel or otherwise
441 non-intersecting lines or no convergence
442 for the given B{C{tol}}.
444 @raise TypeError: Invalid or non-ellipsoidal B{C{start1}}, B{C{end1}},
445 B{C{start2}} or B{C{end2}} or invalid B{C{equidistant}}.
447 @note: For each line specified with an initial bearing, a pseudo-end point
448 is computed as the C{destination} along that bearing at about 1.5
449 times the distance from the start point to an initial gu-/estimate
450 of the intersection point (and between 1/8 and 3/8 of the authalic
451 earth perimeter).
453 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
454 calculating-intersection-of-two-circles>} and U{Karney's paper
455 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME
456 BOUNDARIES} for more details about the iteration algorithm.
457 '''
458 return _intersection3(start1, end1, start2, end2, height=height, wrap=wrap,
459 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
462def intersections2(center1, radius1, center2, radius2, height=None, wrap=False, # was=True
463 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
464 '''I{Iteratively} compute the intersection points of two circles, each defined
465 by an (ellipsoidal) center point and a radius.
467 @arg center1: Center of the first circle (L{LatLon}).
468 @arg radius1: Radius of the first circle (C{meter}, conventionally).
469 @arg center2: Center of the second circle (L{LatLon}).
470 @arg radius2: Radius of the second circle (C{meter}, same units as
471 B{C{radius1}}).
472 @kwarg height: Optional height for the intersection points (C{meter},
473 conventionally) or C{None} for the I{"radical height"}
474 at the I{radical line} between both centers.
475 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{center2}}
476 (C{bool}).
477 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
478 function L{pygeodesy.equidistant}) or C{None} for
479 the preferred C{B{center1}.Equidistant}.
480 @kwarg tol: Convergence tolerance (C{meter}, same units as B{C{radius1}}
481 and B{C{radius2}}).
482 @kwarg LatLon: Optional class to return the intersection points (L{LatLon})
483 or C{None}.
484 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
485 ignored if C{B{LatLon} is None}.
487 @return: 2-Tuple of the intersection points, each a B{C{LatLon}} instance
488 or L{LatLon4Tuple}C{(lat, lon, height, datum)} if C{B{LatLon} is
489 None}. For abutting circles, both points are the same instance,
490 aka the I{radical center}.
492 @raise IntersectionError: Concentric, antipodal, invalid or non-intersecting
493 circles or no convergence for the B{C{tol}}.
495 @raise TypeError: Invalid or non-ellipsoidal B{C{center1}} or B{C{center2}}
496 or invalid B{C{equidistant}}.
498 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.
500 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
501 calculating-intersection-of-two-circles>}, U{Karney's paper
502 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},
503 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and
504 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}
505 intersections.
506 '''
507 return _intersections2(center1, radius1, center2, radius2, height=height, wrap=wrap,
508 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
511def nearestOn(point, point1, point2, within=True, height=None, wrap=False,
512 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
513 '''I{Iteratively} locate the closest point on the geodesic between
514 two other (ellipsoidal) points.
516 @arg point: Reference point (C{LatLon}).
517 @arg point1: Start point of the geodesic (C{LatLon}).
518 @arg point2: End point of the geodesic (C{LatLon}).
519 @kwarg within: If C{True} return the closest point I{between}
520 B{C{point1}} and B{C{point2}}, otherwise the
521 closest point elsewhere on the geodesic (C{bool}).
522 @kwarg height: Optional height for the closest point (C{meter},
523 conventionally) or C{None} or C{False} for the
524 interpolated height. If C{False}, the closest
525 takes the heights of the points into account.
526 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both
527 B{C{point1}} and B{C{point2}} (C{bool}).
528 @kwarg equidistant: An azimuthal equidistant projection (I{class}
529 or function L{pygeodesy.equidistant}) or C{None}
530 for the preferred C{B{point}.Equidistant}.
531 @kwarg tol: Convergence tolerance (C{meter}).
532 @kwarg LatLon: Optional class to return the closest point
533 (L{LatLon}) or C{None}.
534 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword
535 arguments, ignored if C{B{LatLon} is None}.
537 @return: Closest point, a B{C{LatLon}} instance or if C{B{LatLon}
538 is None}, a L{LatLon4Tuple}C{(lat, lon, height, datum)}.
540 @raise ImportError: Package U{geographiclib
541 <https://PyPI.org/project/geographiclib>}
542 not installed or not found, but only if
543 C{B{equidistant}=}L{EquidistantKarney}.
545 @raise TypeError: Invalid or non-ellipsoidal B{C{point}}, B{C{point1}}
546 or B{C{point2}} or invalid B{C{equidistant}}.
548 @raise ValueError: No convergence for the B{C{tol}}.
550 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
551 calculating-intersection-of-two-circles>} and U{Karney's paper
552 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME
553 BOUNDARIES} for more details about the iteration algorithm.
554 '''
555 return _nearestOn(point, point1, point2, within=within, height=height, wrap=wrap,
556 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
559@deprecated_function
560def perimeterOf(points, **closed_datum_wrap):
561 '''DEPRECATED, use function L{ellipsoidalExact.perimeterOf} or L{ellipsoidalKarney.perimeterOf}.
562 '''
563 try:
564 return _MODS.ellipsoidalKarney.perimeterOf(points, **closed_datum_wrap)
565 except ImportError:
566 return _MODS.ellipsoidalExact.perimeterOf(points, **closed_datum_wrap)
569__all__ += _ALL_OTHER(Cartesian, LatLon, intersecant2, # from .ellipsoidalBaseDI
570 intersection3, intersections2, ispolar, # from .points
571 nearestOn) + _ALL_DOCS(areaOf, perimeterOf) # deprecated
573# **) MIT License
574#
575# Copyright (C) 2016-2023 -- mrJean1 at Gmail -- All Rights Reserved.
576#
577# Permission is hereby granted, free of charge, to any person obtaining a
578# copy of this software and associated documentation files (the "Software"),
579# to deal in the Software without restriction, including without limitation
580# the rights to use, copy, modify, merge, publish, distribute, sublicense,
581# and/or sell copies of the Software, and to permit persons to whom the
582# Software is furnished to do so, subject to the following conditions:
583#
584# The above copyright notice and this permission notice shall be included
585# in all copies or substantial portions of the Software.
586#
587# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
588# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
589# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
590# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
591# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
592# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
593# OTHER DEALINGS IN THE SOFTWARE.