Coverage for pygeodesy/ellipsoidalVincenty.py: 99%

1

2# -*- coding: utf-8 -*-

3

4 u'''Ellipsoidal, I{Vincenty}-based geodesy.

5

6 I{Thaddeus Vincenty}'s geodetic (lat-/longitude) L{LatLon}, geocentric

7(ECEF) L{Cartesian} and L{VincentyError} classes and functions L{areaOf},

8 L{intersections2}, L{nearestOn} and L{perimeterOf}.

9

10 Pure Python implementation of geodesy tools for ellipsoidal earth models,

11 transcoded from JavaScript originals by I{(C) Chris Veness 2005-2024}

12 and published under the same MIT Licence**, see U{Vincenty geodesics

13<https://www.Movable-Type.co.UK/scripts/LatLongVincenty.html>}. More

14 at U{geographiclib<https://PyPI.org/project/geographiclib>} and

15 U{GeoPy<https://PyPI.org/project/geopy>}.

16

17 Calculate geodesic distance between two points using the U{Vincenty

18<https://WikiPedia.org/wiki/Vincenty's_formulae>} formulae and one of

19 several ellipsoidal earth models. The default model is WGS-84, the

20 most widely used globally-applicable model for the earth ellipsoid.

21

22 Other ellipsoids offering a better fit to the local geoid include Airy

23(1830) in the UK, Clarke (1880) in Africa, International 1924 in much

24 of Europe, and GRS-67 in South America. North America (NAD83) and

25 Australia (GDA) use GRS-80, which is equivalent to the WGS-84 model.

26

27 Great-circle distance uses a I{spherical} model of the earth with the

28 mean earth radius defined by the International Union of Geodesy and

29 Geophysics (IUGG) as M{(2 * a + b) / 3 = 6371008.7714150598} or about

30 6,371,009 meter (for WGS-84, resulting in an error of up to about 0.5%).

31

32 Here's an example usage of C{ellipsoidalVincenty}:

33

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

39

40 To change the ellipsoid model used by the Vincenty formulae use:

41

42 >>> from pygeodesy import Datums

43 >>> from pygeodesy.ellipsoidalVincenty import LatLon

44 >>> p = LatLon(0, 0, datum=Datums.OSGB36)

45

46 or by converting to anothor datum:

47

48 >>> p = p.toDatum(Datums.OSGB36)

49'''

50# make sure int/int division yields float quotient, see .basics

51 from __future__ import division as _; del _ # noqa: E702 ;

52

53 from pygeodesy.constants import EPS, EPS0, _0_0, _1_0, _2_0, _3_0, _4_0, _6_0

54# from pygeodesy.ecef import EcefVeness # _MODS

55 from pygeodesy.ellipsoidalBase import CartesianEllipsoidalBase, _nearestOn

56 from pygeodesy.ellipsoidalBaseDI import LatLonEllipsoidalBaseDI, \

57 _intersection3, _intersections2, \

58 _TOL_M, intersecant2

59# from pygeodesy.ellipsoidalExact import areaOf, perimeterOf # _MODS

60# from pygeodesy.ellipsoidalKarney import areaOf, perimeterOf # _MODS

61 from pygeodesy.errors import _and, _ValueError, _xkwds

62 from pygeodesy.fmath import fdot_, Fpolynomial, hypot, hypot1

63 from pygeodesy.interns import _ambiguous_, _antipodal_, _COLONSPACE_, \

64 _to_, _SPACE_, _limit_ # PYCHOK used!

65 from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS

66 from pygeodesy.namedTuples import Destination2Tuple, Destination3Tuple, \

67 Distance3Tuple

68 from pygeodesy.points import Fmt, ispolar # PYCHOK exported

69 from pygeodesy.props import deprecated_function, deprecated_method, \

70 property_doc_, property_RO

71# from pygeodesy.streprs import Fmt # from .points

72 from pygeodesy.units import Number_, Scalar_

73 from pygeodesy.utily import atan2, atan2b, atan2d, sincos2, sincos2d, \

74 unroll180, wrap180

75

76 from math import cos, degrees, fabs, radians, tan as _tan

77

78 __all__ = _ALL_LAZY.ellipsoidalVincenty

79 __version__ = '25.05.26'

80

81 _antipodal_to_ = _SPACE_(_antipodal_, _to_)

82

83

84 class VincentyError(_ValueError):

85 '''Error raised by I{Vincenty}'s C{Direct} and C{Inverse} methods

86 for coincident points or lack of convergence.

87 '''

88 pass

89

90

91 class Cartesian(CartesianEllipsoidalBase):

92 '''Extended to convert geocentric, L{Cartesian} points to

93 Vincenty-based, ellipsoidal, geodetic L{LatLon}.

94 '''

95 @property_RO

96 def Ecef(self):

97 '''Get the ECEF I{class} (L{EcefVeness}), I{once}.

98 '''

99 return _Ecef()

100

101 def toLatLon(self, **LatLon_and_kwds): # PYCHOK LatLon=LatLon, datum=None

102 '''Convert this cartesian point to a C{Vincenty}-based geodetic point.

103

104 @kwarg LatLon_and_kwds: Optional L{LatLon} and L{LatLon} keyword

105 arguments as C{datum}. Use C{B{LatLon}=...,

106 B{datum}=...} to override this L{LatLon}

107 class or specify C{B{LatLon}=None}.

108

109 @return: The geodetic point (L{LatLon}) or if C{B{LatLon} is None},

110 an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)}

111 with C{C} and C{M} if available.

112

113 @raise TypeError: Invalid B{C{LatLon_and_kwds}} argument.

114 '''

115 kwds = _xkwds(LatLon_and_kwds, LatLon=LatLon, datum=self.datum)

116 return CartesianEllipsoidalBase.toLatLon(self, **kwds)

117

118

119 class LatLon(LatLonEllipsoidalBaseDI):

120 '''New point on an (oblate) ellipsoidal earth model, using the formulae devised

121 by U{I{Thaddeus Vincenty}<https://WikiPedia.org/wiki/Vincenty's_formulae>}

122 (1975) to compute geodesic distances, bearings (azimuths), etc.

123

124 Set the earth model to be used with the keyword argument datum. The default

125 is C{Datums.WGS84}, which is the most globally accurate. For other models,

126 see the L{Datums<pygeodesy.datums>}.

127

128 @note: This implementation of I{Vincenty} methods may not converge for some

129 valid points, raising a L{VincentyError}. In that case, a result may

130 be obtained by increasing the tolerance C{epsilon} and/or iteration

131 C{limit}, see properties L{LatLon.epsilon} and L{LatLon.iterations}.

132 '''

133 _epsilon = 1e-12 # radians, about 6 um

134# _iteration = None # iteration number from .named._NamedBase

135 _iterations = 201 # 5, default max, 200 vs Veness' 1,000

136

137 @deprecated_method

138 def bearingTo(self, other, wrap=False): # PYCHOK no cover

139 '''DEPRECATED, use method L{initialBearingTo} or L{bearingTo2}.

140 '''

141 return self.initialBearingTo(other, wrap=wrap)

142

143 @property_RO

144 def Ecef(self):

145 '''Get the ECEF I{class} (L{EcefVeness}), I{once}.

146 '''

147 return _Ecef()

148

149 @property_doc_(''' the convergence epsilon (C{radians}).''')

150 def epsilon(self):

151 '''Get the convergence epsilon (C{radians}).

152 '''

153 return self._epsilon

154

155 @epsilon.setter # PYCHOK setter!

156 def epsilon(self, epsilon):

157 '''Set the convergence epsilon (C{radians}).

158

159 @raise TypeError: Non-scalar B{C{epsilon}}.

160

161 @raise ValueError: Out of bounds B{C{epsilon}}.

162 '''

163 self._epsilon = Scalar_(epsilon=epsilon)

164

165 @property_doc_(''' the iteration limit (C{int}).''')

166 def iterations(self):

167 '''Get the iteration limit (C{int}).

168 '''

169 return self._iterations - 1

170

171 @iterations.setter # PYCHOK setter!

172 def iterations(self, limit):

173 '''Set the iteration limit (C{int}).

174

175 @raise TypeError: Non-scalar B{C{limit}}.

176

177 @raise ValueError: Out-of-bounds B{C{limit}}.

178 '''

179 self._iterations = Number_(limit, name=_limit_, low=4, high=1000) + 1

180

181 def toCartesian(self, **Cartesian_datum_kwds): # PYCHOK Cartesian=Cartesian, datum=None

182 '''Convert this point to C{Vincenty}-based cartesian (ECEF) coordinates.

183

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}.

188

189 @return: The cartesian point (L{Cartesian}) or if C{B{Cartesian} is None},

190 an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)} with

191 C{C} and C{M} if available.

192

193 @raise TypeError: Invalid B{C{Cartesian}}, B{C{datum}} or other B{C{Cartesian_datum_kwds}}.

194 '''

195 kwds = _xkwds(Cartesian_datum_kwds, Cartesian=Cartesian,

196 datum=self.datum)

197 return LatLonEllipsoidalBaseDI.toCartesian(self, **kwds)

198

199 def _Direct(self, distance, bearing, llr, height):

200 '''(INTERNAL) Direct Vincenty method.

201

202 @raise TypeError: The B{C{other}} point is not L{LatLon}.

203

204 @raise ValueError: If this and the B{C{other}} point's L{Datum} ellipsoids are

205 not compatible.

206

207 @raise VincentyError: Vincenty fails to converge for the current limits, see

208 L{epsilon<LatLon.epsilon>} and L{iterations<LatLon.iterations>}.

209 '''

210 E = self.ellipsoid()

211 f = E.f

212

213 sb, cb = sincos2d(bearing)

214 s1, c1, t1 = _sincostan3r(self.phi, f)

215

216 eps = self.epsilon

217 s12 = atan2(t1, cb) * _2_0

218 sa, ca2 = _sincos22(c1 * sb)

219 A, B = _AB2(ca2 * E.e22) # e22 == (a / b)**2 - 1

220 s = d = distance / (A * E.b)

221 for i in range(1, self._iterations): # 1-origin

222 ss, cs = sincos2(s)

223 c2sm, e = cos(s12 + s), s

224 s = _Ds(B, cs, ss, c2sm, d)

225 e = fabs(s - e)

226 if e < eps:

227 self._iteration = i

228 break

229 else:

230 t = self._no_convergence(e)

231 raise VincentyError(t, txt=repr(self)) # self.toRepr()

232

233 t = fdot_(s1, ss, -c1, cs * cb)

234 # final bearing (reverse azimuth +/- 180)

235 d = atan2b(sa, -t)

236 if llr:

237 b = cb * ss

238 a = atan2d(fdot_(s1, cs, c1, b), hypot(sa, t) * E.b_a)

239 b = atan2d(sb * ss, fdot_(-s1, b, c1, cs)) + self.lon \

240 - degrees(_Dl(f, ca2, sa, s, cs, ss, c2sm))

241 t = Destination3Tuple(a, wrap180(b), d)

242 r = self._Direct2Tuple(self.classof, height, t)

243 else:

244 r = Destination2Tuple(None, d, name=self.name)

245 r._iteration = i

246 return r

247

248 def _Inverse(self, other, wrap, azis=True): # PYCHOK signature

249 '''(INTERNAL) Inverse Vincenty method.

250

251 @raise TypeError: The B{C{other}} point is not L{LatLon}.

252

253 @raise ValueError: If this and the B{C{other}} point's L{Datum}

254 ellipsoids are not compatible.

255

256 @raise VincentyError: Vincenty fails to converge for the current

257 L{LatLon.epsilon} and L{LatLon.iterations}

258 limits and/or if this and the B{C{other}}

259 point are coincident or near-antipodal.

260 '''

261 E = self.ellipsoids(other)

262 f = E.f

263

264 s1, c1, _ = _sincostan3r( self.phi, f)

265 s2, c2, _ = _sincostan3r(other.phi, f)

266

267 c1c2, s1c2 = c1 * c2, s1 * c2

268 c1s2, s1s2 = c1 * s2, s1 * s2

269

270 eps = self.epsilon

271 d, _ = unroll180(self.lon, other.lon, wrap=wrap)

272 dl = ll = radians(d)

273 for i in range(1, self._iterations): # 1-origin

274 sll, cll = sincos2(ll)

275

276 ss = hypot(c2 * sll, c1s2 - s1c2 * cll)

277 if ss < EPS: # coincident or antipodal, ...

278 if self.isantipodeTo(other, eps=eps):

279 t = self._is_to(other, True)

280 raise VincentyError(_ambiguous_, txt=t)

281 self._iteration = i

282 # return zeros like Karney, unlike Veness

283 return Distance3Tuple(_0_0, 0, 0, iteration=i)

284

285 cs = s1s2 + c1c2 * cll

286 s, e = atan2(ss, cs), ll

287 sa, ca2 = _sincos22(c1c2 * sll / ss)

288 if ca2:

289 c2sm = cs - _2_0 * s1s2 / ca2

290 ll = _Dl(f, ca2, sa, s, cs, ss, c2sm, dl)

291 else: # equatorial line

292 ll = dl + f * sa * s

293 e = fabs(ll - e)

294 if e < eps:

295 self._iteration = i

296 break

297# elif abs(ll) > PI and self.isantipodeTo(other, eps=eps):

298# # omitted and applied *after* failure to converge below,

299# # see footnote under Inverse <https://WikiPedia.org/wiki/

300# # Vincenty's_formulae> and <https://GitHub.com/chrisveness/

301# # geodesy/blob/master/latlon-ellipsoidal-vincenty.js>

302# raise VincentyError(_ambiguous_, self._is_to(other, True))

303 else:

304 t = self._is_to(other, self.isantipodeTo(other, eps=eps))

305 raise VincentyError(self._no_convergence(e), txt=t)

306

307 if ca2: # e22 == (a / b)**2 - 1

308 A, B = _AB2(ca2 * E.e22)

309 s = -A * _Ds(B, cs, ss, c2sm, -s)

310

311 b = E.b

312# if self.height or other.height:

313# b += self._havg(other)

314 d = b * s

315

316 if azis: # forward and reverse azimuth

317 s, c = sincos2(ll)

318 f = atan2b(c2 * s, c1s2 - s1c2 * c)

319 r = atan2b(c1 * s, -s1c2 + c1s2 * c)

320 else:

321 f = r = _0_0 # NAN

322 return Distance3Tuple(d, f, r, name=self.name, iteration=i)

323

324 def _is_to(self, other, anti):

325 '''(INTERNAL) Return I{'<self> [antipodal] to <other>'} text (C{str}).

326 '''

327 t = _antipodal_to_ if anti else _to_

328 return _SPACE_(repr(self), t, repr(other))

329

330 def _no_convergence(self, e):

331 '''(INTERNAL) Return I{'no convergence (..): ...'} text (C{str}).

332 '''

333 t = (Fmt.PARENSPACED(*t) for t in ((LatLon.epsilon.name, self.epsilon),

334 (LatLon.iterations.name, self.iterations)))

335 return _COLONSPACE_(Fmt.no_convergence(e), _and(*t))

336

337

338 def _AB2(u2): # WGS84 e22 = 0.00673949674227643

339 # 2-Tuple C{(A, B)} polynomials

340 if u2:

341 A = Fpolynomial(u2, 16384, 4096, -768, 320, -175).fover(16384)

342 B = Fpolynomial(u2, 0, 256, -128, 74, -47).fover( 1024)

343 return A, B

344 return _1_0, _0_0

345

346

347 def _c2sm2(c2sm):

348 # C{2 * c2sm**2 - 1}

349 return c2sm**2 * _2_0 - _1_0

350

351

352 def _Dl(f, ca2, sa, s, cs, ss, c2sm, dl=_0_0):

353 # C{Dl}

354 if f and sa:

355 C = f * ca2 / _4_0

356 C *= f - C * _3_0 + _1_0

357 if C and ss:

358 s += C * ss * (c2sm +

359 C * cs * _c2sm2(c2sm))

360 dl += (_1_0 - C) * f * sa * s

361 return dl

362

363

364 def _Ds(B, cs, ss, c2sm, d):

365 # C{Ds - d}

366 if B and ss:

367 c2sm2 = _c2sm2(c2sm)

368 ss2 = (ss**2 * _4_0 - _3_0) * (c2sm2 * _2_0 - _1_0)

369 B *= ss * (c2sm + B / _4_0 * (c2sm2 * cs -

370 B / _6_0 * c2sm * ss2))

371 d += B

372 return d

373

374

375 def _Ecef():

376 # get the Ecef class and overwrite property_RO

377 Cartesian.Ecef = LatLon.Ecef = E = _MODS.ecef.EcefVeness

378 return E

379

380

381 def _ellipsoidalOf(_Of, points, **kwds): # helper for DEPRECATED areaOf and perimeterOf

382 try:

383 r = getattr(_MODS.ellipsoidalKarney, _Of.__name__)(points, **kwds)

384 except ImportError: # no geographiclib

385 r = getattr(_MODS.ellipsoidalExact, _Of.__name__)(points, **kwds)

386 return r

387

388

389 def _sincos22(sa):

390 # 2-Tuple C{(sin(a), cos(a)**2)}

391 ca2 = _1_0 - sa**2

392 return sa, (_0_0 if ca2 < EPS0 else ca2) # XXX EPS?

393

394

395 def _sincostan3r(a, f):

396 # I{Reduced} 3-tuple C{(sin(B{a}), cos(B{a}), tan(B{a}))}

397 if a: # see L{sincostan3}

398 t = (_1_0 - f) * _tan(a)

399 if t:

400 c = _1_0 / hypot1(t)

401 s = c * t

402 return s, c, t

403 return _0_0, _1_0, _0_0

404

405

406@deprecated_function

407 def areaOf(points, **datum_wrap_polar):

408 '''DEPRECATED, use function L{ellipsoidalExact.areaOf} or L{ellipsoidalKarney.areaOf}.

409 '''

410 return _ellipsoidalOf(areaOf, points, **datum_wrap_polar)

411

412

413 def intersection3(start1, end1, start2, end2, height=None, wrap=False, # was=True

414 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):

415 '''I{Iteratively} compute the intersection point of two lines, each defined

416 by two (ellipsoidal) points or by an (ellipsoidal) start point and an

417 (initial) bearing from North.

418

419 @arg start1: Start point of the first line (L{LatLon}).

420 @arg end1: End point of the first line (L{LatLon}) or the initial bearing

421 at the first point (compass C{degrees360}).

422 @arg start2: Start point of the second line (L{LatLon}).

423 @arg end2: End point of the second line (L{LatLon}) or the initial bearing

424 at the second point (compass C{degrees360}).

425 @kwarg height: Optional height at the intersection (C{meter}, conventionally)

426 or C{None} for the mean height.

427 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the B{C{start2}}

428 and B{C{end*}} points (C{bool}).

429 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function

430 L{pygeodesy.equidistant}) or C{None} for the preferred

431 C{B{start1}.Equidistant}.

432 @kwarg tol: Tolerance for convergence and for skew line distance and length

433 (C{meter}, conventionally).

434 @kwarg LatLon: Optional class to return the intersection points (L{LatLon})

435 or C{None}.

436 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,

437 ignored if C{B{LatLon} is None}.

438

439 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)} with C{point}

440 a B{C{LatLon}} or if C{B{LatLon} is None}, a L{LatLon4Tuple}C{(lat,

441 lon, height, datum)}.

442

443 @raise IntersectionError: Skew, colinear, parallel or otherwise

444 non-intersecting lines or no convergence

445 for the given B{C{tol}}.

446

447 @raise TypeError: Invalid or non-ellipsoidal B{C{start1}}, B{C{end1}},

448 B{C{start2}} or B{C{end2}} or invalid B{C{equidistant}}.

449

450 @note: For each line specified with an initial bearing, a pseudo-end point

451 is computed as the C{destination} along that bearing at about 1.5

452 times the distance from the start point to an initial gu-/estimate

453 of the intersection point (and between 1/8 and 3/8 of the authalic

454 earth perimeter).

455

456 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/

457 calculating-intersection-of-two-circles>} and U{Karney's paper

458 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME

459 BOUNDARIES} for more details about the iteration algorithm.

460 '''

461 return _intersection3(start1, end1, start2, end2, height=height, wrap=wrap,

462 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)

463

464

465 def intersections2(center1, radius1, center2, radius2, height=None, wrap=False, # was=True

466 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):

467 '''I{Iteratively} compute the intersection points of two circles, each defined

468 by an (ellipsoidal) center point and a radius.

469

470 @arg center1: Center of the first circle (L{LatLon}).

471 @arg radius1: Radius of the first circle (C{meter}, conventionally).

472 @arg center2: Center of the second circle (L{LatLon}).

473 @arg radius2: Radius of the second circle (C{meter}, same units as

474 B{C{radius1}}).

475 @kwarg height: Optional height for the intersection points (C{meter},

476 conventionally) or C{None} for the I{"radical height"}

477 at the I{radical line} between both centers.

478 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{center2}}

479 (C{bool}).

480 @kwarg equidistant: An azimuthal equidistant projection (I{class} or

481 function L{pygeodesy.equidistant}) or C{None} for

482 the preferred C{B{center1}.Equidistant}.

483 @kwarg tol: Convergence tolerance (C{meter}, same units as B{C{radius1}}

484 and B{C{radius2}}).

485 @kwarg LatLon: Optional class to return the intersection points (L{LatLon})

486 or C{None}.

487 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,

488 ignored if C{B{LatLon} is None}.

489

490 @return: 2-Tuple of the intersection points, each a B{C{LatLon}} instance

491 or L{LatLon4Tuple}C{(lat, lon, height, datum)} if C{B{LatLon} is

492 None}. For abutting circles, both points are the same instance,

493 aka the I{radical center}.

494

495 @raise IntersectionError: Concentric, antipodal, invalid or non-intersecting

496 circles or no convergence for the B{C{tol}}.

497

498 @raise TypeError: Invalid or non-ellipsoidal B{C{center1}} or B{C{center2}}

499 or invalid B{C{equidistant}}.

500

501 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.

502

503 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/

504 calculating-intersection-of-two-circles>}, U{Karney's paper

505 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},

506 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and

507 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}

508 intersections.

509 '''

510 return _intersections2(center1, radius1, center2, radius2, height=height, wrap=wrap,

511 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)

512

513

514 def nearestOn(point, point1, point2, within=True, height=None, wrap=False,

515 equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):

516 '''I{Iteratively} locate the closest point on the geodesic between

517 two other (ellipsoidal) points.

518

519 @arg point: Reference point (C{LatLon}).

520 @arg point1: Start point of the geodesic (C{LatLon}).

521 @arg point2: End point of the geodesic (C{LatLon}).

522 @kwarg within: If C{True}, return the closest point I{between}

523 B{C{point1}} and B{C{point2}}, otherwise the

524 closest point elsewhere on the geodesic (C{bool}).

525 @kwarg height: Optional height for the closest point (C{meter},

526 conventionally) or C{None} or C{False} for the

527 interpolated height. If C{False}, the closest

528 takes the heights of the points into account.

529 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both

530 B{C{point1}} and B{C{point2}} (C{bool}).

531 @kwarg equidistant: An azimuthal equidistant projection (I{class}

532 or function L{pygeodesy.equidistant}) or C{None}

533 for the preferred C{B{point}.Equidistant}.

534 @kwarg tol: Convergence tolerance (C{meter}).

535 @kwarg LatLon: Optional class to return the closest point

536 (L{LatLon}) or C{None}.

537 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword

538 arguments, ignored if C{B{LatLon} is None}.

539

540 @return: Closest point, a B{C{LatLon}} instance or if C{B{LatLon}

541 is None}, a L{LatLon4Tuple}C{(lat, lon, height, datum)}.

542

543 @raise ImportError: Package U{geographiclib

544 <https://PyPI.org/project/geographiclib>}

545 not installed or not found, but only if

546 C{B{equidistant}=}L{EquidistantKarney}.

547

548 @raise TypeError: Invalid or non-ellipsoidal B{C{point}}, B{C{point1}}

549 or B{C{point2}} or invalid B{C{equidistant}}.

550

551 @raise ValueError: No convergence for the B{C{tol}}.

552

553 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/

554 calculating-intersection-of-two-circles>} and U{Karney's paper

555 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME

556 BOUNDARIES} for more details about the iteration algorithm.

557 '''

558 return _nearestOn(point, point1, point2, within=within, height=height, wrap=wrap,

559 equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)

560

561

562@deprecated_function

563 def perimeterOf(points, **closed_datum_wrap):

564 '''DEPRECATED, use function L{ellipsoidalExact.perimeterOf} or L{ellipsoidalKarney.perimeterOf}.

565 '''

566 return _ellipsoidalOf(perimeterOf, points, **closed_datum_wrap)

567

568

569 __all__ += _ALL_DOCS(Cartesian, LatLon, intersecant2, # from .ellipsoidalBaseDI

570 intersection3, intersections2, ispolar, # from .points

571 nearestOn,

572 areaOf, perimeterOf) # DEPRECATED

573

574# **) MIT License

575#

576# Copyright (C) 2016-2026 -- mrJean1 at Gmail -- All Rights Reserved.

577#

578# Permission is hereby granted, free of charge, to any person obtaining a

579# copy of this software and associated documentation files (the "Software"),

580# to deal in the Software without restriction, including without limitation

581# the rights to use, copy, modify, merge, publish, distribute, sublicense,

582# and/or sell copies of the Software, and to permit persons to whom the

583# Software is furnished to do so, subject to the following conditions:

584#

585# The above copyright notice and this permission notice shall be included

586# in all copies or substantial portions of the Software.

587#

588# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS

589# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

590# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

591# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR

592# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,

593# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

594# OTHER DEALINGS IN THE SOFTWARE.