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 _ # PYCHOK semicolon

52

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

54 from pygeodesy.ellipsoidalBase import CartesianEllipsoidalBase, _nearestOn

55 from pygeodesy.ellipsoidalBaseDI import LatLonEllipsoidalBaseDI, \

56 _intersection3, _intersections2, \

57 _TOL_M, intersecant2

58 from pygeodesy.errors import _and, _ValueError, _xkwds

59 from pygeodesy.fmath import Fpolynomial, hypot, hypot1

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

61 _to_, _SPACE_, _limit_ # PYCHOK used!

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

63 from pygeodesy.namedTuples import Destination2Tuple, Destination3Tuple, \

64 Distance3Tuple

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

66 from pygeodesy.props import deprecated_function, deprecated_method, \

67 property_doc_, property_RO

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

69 from pygeodesy.units import Number_, Scalar_

70 from pygeodesy.utily import atan2b, atan2d, sincos2, sincos2d, unroll180, wrap180

71

72 from math import atan2, cos, degrees, fabs, radians, tan

73

74__all__ = _ALL_LAZY.ellipsoidalVincenty

75__version__ = '24.10.12'

76

77_antipodal_to_ = _SPACE_(_antipodal_, _to_)

78

79

80 class 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

85

86

87 class 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{once}.

94 '''

95 return _Ecef()

96

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

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

99

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

104

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

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

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

108

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)

113

114

115 class LatLon(LatLonEllipsoidalBaseDI):

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

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

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

119

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

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

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

123

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

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

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

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

128 '''

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

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

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

132

133 @deprecated_method

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

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

136 '''

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

138

139 @property_RO

140 def Ecef(self):

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

142 '''

143 return _Ecef()

144

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

146 def epsilon(self):

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

148 '''

149 return self._epsilon

150

151 @epsilon.setter # PYCHOK setter!

152 def epsilon(self, epsilon):

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

154

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

156

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

158 '''

159 self._epsilon = Scalar_(epsilon=epsilon)

160

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

162 def iterations(self):

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

164 '''

165 return self._iterations - 1

166

167 @iterations.setter # PYCHOK setter!

168 def iterations(self, limit):

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

170

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

172

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

174 '''

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

176

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

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

179

180 @kwarg Cartesian_datum_kwds: Optional L{Cartesian}, B{C{datum}} and other

181 keyword arguments, ignored if C{B{Cartesian}=None}. Use

182 C{B{Cartesian}=...} to override this L{Cartesian} class

183 or specify C{B{Cartesian}=None}.

184

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

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

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

188

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

190 '''

191 kwds = _xkwds(Cartesian_datum_kwds, Cartesian=Cartesian,

192 datum=self.datum)

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

194

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

196 '''(INTERNAL) Direct Vincenty method.

197

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

199

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

201 not compatible.

202

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

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

205 '''

206 E = self.ellipsoid()

207 f = E.f

208

209 sb, cb = sincos2d(bearing)

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

211

212 eps = self.epsilon

213 s12 = atan2(t1, cb) * _2_0

214 sa, ca2 = _sincos22(c1 * sb)

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

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

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

218 ss, cs = sincos2(s)

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

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

221 e = fabs(s - e)

222 if e < eps:

223 self._iteration = i

224 break

225 else:

226 t = self._no_convergence(e)

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

228

229 t = s1 * ss - c1 * cs * cb

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

231 d = atan2b(sa, -t)

232 if llr:

233 b = cb * ss

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

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

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

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

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

239 else:

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

241 r._iteration = i

242 return r

243

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

245 '''(INTERNAL) Inverse Vincenty method.

246

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

248

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

250 ellipsoids are not compatible.

251

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

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

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

255 point are coincident or near-antipodal.

256 '''

257 E = self.ellipsoids(other)

258 f = E.f

259

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

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

262

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

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

265

266 eps = self.epsilon

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

268 dl = ll = radians(d)

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

270 sll, cll = sincos2(ll)

271

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

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

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

275 t = self._is_to(other, True)

276 raise VincentyError(_ambiguous_, txt=t)

277 self._iteration = i

278 # return zeros like Karney, unlike Veness

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

280

281 cs = s1s2 + c1c2 * cll

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

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

284 if ca2:

285 c2sm = cs - _2_0 * s1s2 / ca2

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

287 else: # equatorial line

288 ll = dl + f * sa * s

289 e = fabs(ll - e)

290 if e < eps:

291 self._iteration = i

292 break

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

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

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

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

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

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

299 else:

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

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

302

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

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

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

306

307 b = E.b

308# if self.height or other.height:

309# b += self._havg(other)

310 d = b * s

311

312 if azis: # forward and reverse azimuth

313 s, c = sincos2(ll)

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

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

316 else:

317 f = r = _0_0 # NAN

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

319

320 def _is_to(self, other, anti):

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

322 '''

323 t = _antipodal_to_ if anti else _to_

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

325

326 def _no_convergence(self, e):

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

328 '''

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

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

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

332

333

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

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

336 if u2:

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

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

339 return A, B

340 return _1_0, _0_0

341

342

343 def _c2sm2(c2sm):

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

345 return c2sm**2 * _2_0 - _1_0

346

347

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

349 # C{Dl}

350 if f and sa:

351 C = f * ca2 / _4_0

352 C *= f - C * _3_0 + _1_0

353 if C and ss:

354 s += C * ss * (c2sm +

355 C * cs * _c2sm2(c2sm))

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

357 return dl

358

359

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

361 # C{Ds - d}

362 if B and ss:

363 c2sm2 = _c2sm2(c2sm)

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

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

366 B / _6_0 * c2sm * ss2))

367 d += B

368 return d

369

370

371 def _Ecef():

372 # get the Ecef class and overwrite property_RO

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

374 return E

375

376

377 def _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?

381

382

383 def _sincostan3r(a, f):

384 # I{Reduced} 3-tuple 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 = c * t

390 return s, c, t

391 return _0_0, _1_0, _0_0

392

393

394@deprecated_function

395 def 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)

402

403

404 def 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.

409

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

429

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

433

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

435 non-intersecting lines or no convergence

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

437

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

440

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

446

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)

454

455

456 def 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.

460

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

480

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

485

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

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

488

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

490 or invalid B{C{equidistant}}.

491

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

493

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)

503

504

505 def 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.

509

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

530

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

533

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

538

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

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

541

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

543

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)

551

552

553@deprecated_function

554 def 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)

561

562

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

564 intersection3, intersections2, ispolar, # from .points

565 nearestOn,

566 areaOf, perimeterOf) # DEPRECATED

567

568# **) MIT License

569#

570# Copyright (C) 2016-2024 -- mrJean1 at Gmail -- All Rights Reserved.

571#

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

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

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

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

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

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

578#

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

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

581#

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

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

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

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

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

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

588# OTHER DEALINGS IN THE SOFTWARE.