Coverage for pygeodesy/ellipsoidalVincenty.py: 99%
176 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-09 11:05 -0400
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-09 11:05 -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-2024}
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
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 atan2, atan2b, atan2d, sincos2, sincos2d, \
71 unroll180, wrap180
73from math import cos, degrees, fabs, radians, tan as _tan
75__all__ = _ALL_LAZY.ellipsoidalVincenty
76__version__ = '24.11.26'
78_antipodal_to_ = _SPACE_(_antipodal_, _to_)
81class VincentyError(_ValueError):
82 '''Error raised by I{Vincenty}'s C{Direct} and C{Inverse} methods
83 for coincident points or lack of convergence.
84 '''
85 pass
88class Cartesian(CartesianEllipsoidalBase):
89 '''Extended to convert geocentric, L{Cartesian} points to
90 Vincenty-based, ellipsoidal, geodetic L{LatLon}.
91 '''
92 @property_RO
93 def Ecef(self):
94 '''Get the ECEF I{class} (L{EcefVeness}), I{once}.
95 '''
96 return _Ecef()
98 def toLatLon(self, **LatLon_and_kwds): # PYCHOK LatLon=LatLon, datum=None
99 '''Convert this cartesian point to a C{Vincenty}-based geodetic point.
101 @kwarg LatLon_and_kwds: Optional L{LatLon} and L{LatLon} keyword
102 arguments as C{datum}. Use C{B{LatLon}=...,
103 B{datum}=...} to override this L{LatLon}
104 class or specify C{B{LatLon}=None}.
106 @return: The geodetic point (L{LatLon}) or if C{B{LatLon} is None},
107 an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)}
108 with C{C} and C{M} if available.
110 @raise TypeError: Invalid B{C{LatLon_and_kwds}} argument.
111 '''
112 kwds = _xkwds(LatLon_and_kwds, LatLon=LatLon, datum=self.datum)
113 return CartesianEllipsoidalBase.toLatLon(self, **kwds)
116class LatLon(LatLonEllipsoidalBaseDI):
117 '''New point on an (oblate) ellipsoidal earth model, using the formulae devised
118 by U{I{Thaddeus Vincenty}<https://WikiPedia.org/wiki/Vincenty's_formulae>}
119 (1975) to compute geodesic distances, bearings (azimuths), etc.
121 Set the earth model to be used with the keyword argument datum. The default
122 is C{Datums.WGS84}, which is the most globally accurate. For other models,
123 see the L{Datums<pygeodesy.datums>}.
125 @note: This implementation of I{Vincenty} methods may not converge for some
126 valid points, raising a L{VincentyError}. In that case, a result may
127 be obtained by increasing the tolerance C{epsilon} and/or iteration
128 C{limit}, see properties L{LatLon.epsilon} and L{LatLon.iterations}.
129 '''
130 _epsilon = 1e-12 # radians, about 6 um
131# _iteration = None # iteration number from .named._NamedBase
132 _iterations = 201 # 5, default max, 200 vs Veness' 1,000
134 @deprecated_method
135 def bearingTo(self, other, wrap=False): # PYCHOK no cover
136 '''DEPRECATED, use method L{initialBearingTo} or L{bearingTo2}.
137 '''
138 return self.initialBearingTo(other, wrap=wrap)
140 @property_RO
141 def Ecef(self):
142 '''Get the ECEF I{class} (L{EcefVeness}), I{once}.
143 '''
144 return _Ecef()
146 @property_doc_(''' the convergence epsilon (C{radians}).''')
147 def epsilon(self):
148 '''Get the convergence epsilon (C{radians}).
149 '''
150 return self._epsilon
152 @epsilon.setter # PYCHOK setter!
153 def epsilon(self, epsilon):
154 '''Set the convergence epsilon (C{radians}).
156 @raise TypeError: Non-scalar B{C{epsilon}}.
158 @raise ValueError: Out of bounds B{C{epsilon}}.
159 '''
160 self._epsilon = Scalar_(epsilon=epsilon)
162 @property_doc_(''' the iteration limit (C{int}).''')
163 def iterations(self):
164 '''Get the iteration limit (C{int}).
165 '''
166 return self._iterations - 1
168 @iterations.setter # PYCHOK setter!
169 def iterations(self, limit):
170 '''Set the iteration limit (C{int}).
172 @raise TypeError: Non-scalar B{C{limit}}.
174 @raise ValueError: Out-of-bounds B{C{limit}}.
175 '''
176 self._iterations = Number_(limit, name=_limit_, low=4, high=1000) + 1
178 def toCartesian(self, **Cartesian_datum_kwds): # PYCHOK Cartesian=Cartesian, datum=None
179 '''Convert this point to C{Vincenty}-based cartesian (ECEF) coordinates.
181 @kwarg Cartesian_datum_kwds: Optional L{Cartesian}, B{C{datum}} and other
182 keyword arguments, ignored if C{B{Cartesian}=None}. Use
183 C{B{Cartesian}=...} to override this L{Cartesian} class
184 or specify C{B{Cartesian}=None}.
186 @return: The cartesian point (L{Cartesian}) or if C{B{Cartesian} is None},
187 an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)} with
188 C{C} and C{M} if available.
190 @raise TypeError: Invalid B{C{Cartesian}}, B{C{datum}} or other B{C{Cartesian_datum_kwds}}.
191 '''
192 kwds = _xkwds(Cartesian_datum_kwds, Cartesian=Cartesian,
193 datum=self.datum)
194 return LatLonEllipsoidalBaseDI.toCartesian(self, **kwds)
196 def _Direct(self, distance, bearing, llr, height):
197 '''(INTERNAL) Direct Vincenty method.
199 @raise TypeError: The B{C{other}} point is not L{LatLon}.
201 @raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are
202 not compatible.
204 @raise VincentyError: Vincenty fails to converge for the current limits, see
205 L{epsilon<LatLon.epsilon>} and L{iterations<LatLon.iterations>}.
206 '''
207 E = self.ellipsoid()
208 f = E.f
210 sb, cb = sincos2d(bearing)
211 s1, c1, t1 = _sincostan3r(self.phi, f)
213 eps = self.epsilon
214 s12 = atan2(t1, cb) * _2_0
215 sa, ca2 = _sincos22(c1 * sb)
216 A, B = _AB2(ca2 * E.e22) # e22 == (a / b)**2 - 1
217 s = d = distance / (A * E.b)
218 for i in range(1, self._iterations): # 1-origin
219 ss, cs = sincos2(s)
220 c2sm, e = cos(s12 + s), s
221 s = _Ds(B, cs, ss, c2sm, d)
222 e = fabs(s - e)
223 if e < eps:
224 self._iteration = i
225 break
226 else:
227 t = self._no_convergence(e)
228 raise VincentyError(t, txt=repr(self)) # self.toRepr()
230 t = s1 * ss - c1 * cs * cb
231 # final bearing (reverse azimuth +/- 180)
232 d = atan2b(sa, -t)
233 if llr:
234 b = cb * ss
235 a = atan2d(s1 * cs + c1 * b, hypot(sa, t) * E.b_a)
236 b = atan2d(sb * ss, -s1 * b + c1 * cs) + self.lon \
237 - degrees(_Dl(f, ca2, sa, s, cs, ss, c2sm))
238 t = Destination3Tuple(a, wrap180(b), d)
239 r = self._Direct2Tuple(self.classof, height, t)
240 else:
241 r = Destination2Tuple(None, d, name=self.name)
242 r._iteration = i
243 return r
245 def _Inverse(self, other, wrap, azis=True): # PYCHOK signature
246 '''(INTERNAL) Inverse Vincenty method.
248 @raise TypeError: The B{C{other}} point is not L{LatLon}.
250 @raise ValueError: If this and the B{C{other}} point's L{Datum}
251 ellipsoids are not compatible.
253 @raise VincentyError: Vincenty fails to converge for the current
254 L{LatLon.epsilon} and L{LatLon.iterations}
255 limits and/or if this and the B{C{other}}
256 point are coincident or near-antipodal.
257 '''
258 E = self.ellipsoids(other)
259 f = E.f
261 s1, c1, _ = _sincostan3r( self.phi, f)
262 s2, c2, _ = _sincostan3r(other.phi, f)
264 c1c2, s1c2 = c1 * c2, s1 * c2
265 c1s2, s1s2 = c1 * s2, s1 * s2
267 eps = self.epsilon
268 d, _ = unroll180(self.lon, other.lon, wrap=wrap)
269 dl = ll = radians(d)
270 for i in range(1, self._iterations): # 1-origin
271 sll, cll = sincos2(ll)
273 ss = hypot(c2 * sll, c1s2 - s1c2 * cll)
274 if ss < EPS: # coincident or antipodal, ...
275 if self.isantipodeTo(other, eps=eps):
276 t = self._is_to(other, True)
277 raise VincentyError(_ambiguous_, txt=t)
278 self._iteration = i
279 # return zeros like Karney, unlike Veness
280 return Distance3Tuple(_0_0, 0, 0, iteration=i)
282 cs = s1s2 + c1c2 * cll
283 s, e = atan2(ss, cs), ll
284 sa, ca2 = _sincos22(c1c2 * sll / ss)
285 if ca2:
286 c2sm = cs - _2_0 * s1s2 / ca2
287 ll = _Dl(f, ca2, sa, s, cs, ss, c2sm, dl)
288 else: # equatorial line
289 ll = dl + f * sa * s
290 e = fabs(ll - e)
291 if e < eps:
292 self._iteration = i
293 break
294# elif abs(ll) > PI and self.isantipodeTo(other, eps=eps):
295# # omitted and applied *after* failure to converge below,
296# # see footnote under Inverse <https://WikiPedia.org/wiki/
297# # Vincenty's_formulae> and <https://GitHub.com/chrisveness/
298# # geodesy/blob/master/latlon-ellipsoidal-vincenty.js>
299# raise VincentyError(_ambiguous_, self._is_to(other, True))
300 else:
301 t = self._is_to(other, self.isantipodeTo(other, eps=eps))
302 raise VincentyError(self._no_convergence(e), txt=t)
304 if ca2: # e22 == (a / b)**2 - 1
305 A, B = _AB2(ca2 * E.e22)
306 s = -A * _Ds(B, cs, ss, c2sm, -s)
308 b = E.b
309# if self.height or other.height:
310# b += self._havg(other)
311 d = b * s
313 if azis: # forward and reverse azimuth
314 s, c = sincos2(ll)
315 f = atan2b(c2 * s, c1s2 - s1c2 * c)
316 r = atan2b(c1 * s, -s1c2 + c1s2 * c)
317 else:
318 f = r = _0_0 # NAN
319 return Distance3Tuple(d, f, r, name=self.name, iteration=i)
321 def _is_to(self, other, anti):
322 '''(INTERNAL) Return I{'<self> [antipodal] to <other>'} text (C{str}).
323 '''
324 t = _antipodal_to_ if anti else _to_
325 return _SPACE_(repr(self), t, repr(other))
327 def _no_convergence(self, e):
328 '''(INTERNAL) Return I{'no convergence (..): ...'} text (C{str}).
329 '''
330 t = (Fmt.PARENSPACED(*t) for t in ((LatLon.epsilon.name, self.epsilon),
331 (LatLon.iterations.name, self.iterations)))
332 return _COLONSPACE_(Fmt.no_convergence(e), _and(*t))
335def _AB2(u2): # WGS84 e22 = 0.00673949674227643
336 # 2-Tuple C{(A, B)} polynomials
337 if u2:
338 A = Fpolynomial(u2, 16384, 4096, -768, 320, -175).fover(16384)
339 B = Fpolynomial(u2, 0, 256, -128, 74, -47).fover( 1024)
340 return A, B
341 return _1_0, _0_0
344def _c2sm2(c2sm):
345 # C{2 * c2sm**2 - 1}
346 return c2sm**2 * _2_0 - _1_0
349def _Dl(f, ca2, sa, s, cs, ss, c2sm, dl=_0_0):
350 # C{Dl}
351 if f and sa:
352 C = f * ca2 / _4_0
353 C *= f - C * _3_0 + _1_0
354 if C and ss:
355 s += C * ss * (c2sm +
356 C * cs * _c2sm2(c2sm))
357 dl += (_1_0 - C) * f * sa * s
358 return dl
361def _Ds(B, cs, ss, c2sm, d):
362 # C{Ds - d}
363 if B and ss:
364 c2sm2 = _c2sm2(c2sm)
365 ss2 = (ss**2 * _4_0 - _3_0) * (c2sm2 * _2_0 - _1_0)
366 B *= ss * (c2sm + B / _4_0 * (c2sm2 * cs -
367 B / _6_0 * c2sm * ss2))
368 d += B
369 return d
372def _Ecef():
373 # get the Ecef class and overwrite property_RO
374 Cartesian.Ecef = LatLon.Ecef = E = _MODS.ecef.EcefVeness
375 return E
378def _sincos22(sa):
379 # 2-Tuple C{(sin(a), cos(a)**2)}
380 ca2 = _1_0 - sa**2
381 return sa, (_0_0 if ca2 < EPS0 else ca2) # XXX EPS?
384def _sincostan3r(a, f):
385 # I{Reduced} 3-tuple C{(sin(B{a}), cos(B{a}), tan(B{a}))}
386 if a: # see L{sincostan3}
387 t = (_1_0 - f) * _tan(a)
388 if t:
389 c = _1_0 / hypot1(t)
390 s = c * t
391 return s, c, t
392 return _0_0, _1_0, _0_0
395@deprecated_function
396def areaOf(points, **datum_wrap):
397 '''DEPRECATED, use function L{ellipsoidalExact.areaOf} or L{ellipsoidalKarney.areaOf}.
398 '''
399 try:
400 return _MODS.ellipsoidalKarney.areaOf(points, **datum_wrap)
401 except ImportError:
402 return _MODS.ellipsoidalExact.areaOf(points, **datum_wrap)
405def intersection3(start1, end1, start2, end2, height=None, wrap=False, # was=True
406 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
407 '''I{Iteratively} compute the intersection point of two lines, each defined
408 by two (ellipsoidal) points or by an (ellipsoidal) start point and an
409 (initial) bearing from North.
411 @arg start1: Start point of the first line (L{LatLon}).
412 @arg end1: End point of the first line (L{LatLon}) or the initial bearing
413 at the first point (compass C{degrees360}).
414 @arg start2: Start point of the second line (L{LatLon}).
415 @arg end2: End point of the second line (L{LatLon}) or the initial bearing
416 at the second point (compass C{degrees360}).
417 @kwarg height: Optional height at the intersection (C{meter}, conventionally)
418 or C{None} for the mean height.
419 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the B{C{start2}}
420 and B{C{end*}} points (C{bool}).
421 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function
422 L{pygeodesy.equidistant}) or C{None} for the preferred
423 C{B{start1}.Equidistant}.
424 @kwarg tol: Tolerance for convergence and for skew line distance and length
425 (C{meter}, conventionally).
426 @kwarg LatLon: Optional class to return the intersection points (L{LatLon})
427 or C{None}.
428 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
429 ignored if C{B{LatLon} is None}.
431 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)} with C{point}
432 a B{C{LatLon}} or if C{B{LatLon} is None}, a L{LatLon4Tuple}C{(lat,
433 lon, height, datum)}.
435 @raise IntersectionError: Skew, colinear, parallel or otherwise
436 non-intersecting lines or no convergence
437 for the given B{C{tol}}.
439 @raise TypeError: Invalid or non-ellipsoidal B{C{start1}}, B{C{end1}},
440 B{C{start2}} or B{C{end2}} or invalid B{C{equidistant}}.
442 @note: For each line specified with an initial bearing, a pseudo-end point
443 is computed as the C{destination} along that bearing at about 1.5
444 times the distance from the start point to an initial gu-/estimate
445 of the intersection point (and between 1/8 and 3/8 of the authalic
446 earth perimeter).
448 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
449 calculating-intersection-of-two-circles>} and U{Karney's paper
450 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME
451 BOUNDARIES} for more details about the iteration algorithm.
452 '''
453 return _intersection3(start1, end1, start2, end2, height=height, wrap=wrap,
454 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
457def intersections2(center1, radius1, center2, radius2, height=None, wrap=False, # was=True
458 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
459 '''I{Iteratively} compute the intersection points of two circles, each defined
460 by an (ellipsoidal) center point and a radius.
462 @arg center1: Center of the first circle (L{LatLon}).
463 @arg radius1: Radius of the first circle (C{meter}, conventionally).
464 @arg center2: Center of the second circle (L{LatLon}).
465 @arg radius2: Radius of the second circle (C{meter}, same units as
466 B{C{radius1}}).
467 @kwarg height: Optional height for the intersection points (C{meter},
468 conventionally) or C{None} for the I{"radical height"}
469 at the I{radical line} between both centers.
470 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{center2}}
471 (C{bool}).
472 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
473 function L{pygeodesy.equidistant}) or C{None} for
474 the preferred C{B{center1}.Equidistant}.
475 @kwarg tol: Convergence tolerance (C{meter}, same units as B{C{radius1}}
476 and B{C{radius2}}).
477 @kwarg LatLon: Optional class to return the intersection points (L{LatLon})
478 or C{None}.
479 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
480 ignored if C{B{LatLon} is None}.
482 @return: 2-Tuple of the intersection points, each a B{C{LatLon}} instance
483 or L{LatLon4Tuple}C{(lat, lon, height, datum)} if C{B{LatLon} is
484 None}. For abutting circles, both points are the same instance,
485 aka the I{radical center}.
487 @raise IntersectionError: Concentric, antipodal, invalid or non-intersecting
488 circles or no convergence for the B{C{tol}}.
490 @raise TypeError: Invalid or non-ellipsoidal B{C{center1}} or B{C{center2}}
491 or invalid B{C{equidistant}}.
493 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.
495 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
496 calculating-intersection-of-two-circles>}, U{Karney's paper
497 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},
498 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and
499 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}
500 intersections.
501 '''
502 return _intersections2(center1, radius1, center2, radius2, height=height, wrap=wrap,
503 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
506def nearestOn(point, point1, point2, within=True, height=None, wrap=False,
507 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
508 '''I{Iteratively} locate the closest point on the geodesic between
509 two other (ellipsoidal) points.
511 @arg point: Reference point (C{LatLon}).
512 @arg point1: Start point of the geodesic (C{LatLon}).
513 @arg point2: End point of the geodesic (C{LatLon}).
514 @kwarg within: If C{True}, return the closest point I{between}
515 B{C{point1}} and B{C{point2}}, otherwise the
516 closest point elsewhere on the geodesic (C{bool}).
517 @kwarg height: Optional height for the closest point (C{meter},
518 conventionally) or C{None} or C{False} for the
519 interpolated height. If C{False}, the closest
520 takes the heights of the points into account.
521 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both
522 B{C{point1}} and B{C{point2}} (C{bool}).
523 @kwarg equidistant: An azimuthal equidistant projection (I{class}
524 or function L{pygeodesy.equidistant}) or C{None}
525 for the preferred C{B{point}.Equidistant}.
526 @kwarg tol: Convergence tolerance (C{meter}).
527 @kwarg LatLon: Optional class to return the closest point
528 (L{LatLon}) or C{None}.
529 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword
530 arguments, ignored if C{B{LatLon} is None}.
532 @return: Closest point, a B{C{LatLon}} instance or if C{B{LatLon}
533 is None}, a L{LatLon4Tuple}C{(lat, lon, height, datum)}.
535 @raise ImportError: Package U{geographiclib
536 <https://PyPI.org/project/geographiclib>}
537 not installed or not found, but only if
538 C{B{equidistant}=}L{EquidistantKarney}.
540 @raise TypeError: Invalid or non-ellipsoidal B{C{point}}, B{C{point1}}
541 or B{C{point2}} or invalid B{C{equidistant}}.
543 @raise ValueError: No convergence for the B{C{tol}}.
545 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
546 calculating-intersection-of-two-circles>} and U{Karney's paper
547 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME
548 BOUNDARIES} for more details about the iteration algorithm.
549 '''
550 return _nearestOn(point, point1, point2, within=within, height=height, wrap=wrap,
551 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
554@deprecated_function
555def perimeterOf(points, **closed_datum_wrap):
556 '''DEPRECATED, use function L{ellipsoidalExact.perimeterOf} or L{ellipsoidalKarney.perimeterOf}.
557 '''
558 try:
559 return _MODS.ellipsoidalKarney.perimeterOf(points, **closed_datum_wrap)
560 except ImportError:
561 return _MODS.ellipsoidalExact.perimeterOf(points, **closed_datum_wrap)
564__all__ += _ALL_DOCS(Cartesian, LatLon, intersecant2, # from .ellipsoidalBaseDI
565 intersection3, intersections2, ispolar, # from .points
566 nearestOn,
567 areaOf, perimeterOf) # DEPRECATED
569# **) MIT License
570#
571# Copyright (C) 2016-2025 -- mrJean1 at Gmail -- All Rights Reserved.
572#
573# Permission is hereby granted, free of charge, to any person obtaining a
574# copy of this software and associated documentation files (the "Software"),
575# to deal in the Software without restriction, including without limitation
576# the rights to use, copy, modify, merge, publish, distribute, sublicense,
577# and/or sell copies of the Software, and to permit persons to whom the
578# Software is furnished to do so, subject to the following conditions:
579#
580# The above copyright notice and this permission notice shall be included
581# in all copies or substantial portions of the Software.
582#
583# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
584# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
585# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
586# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
587# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
588# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
589# OTHER DEALINGS IN THE SOFTWARE.