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

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, intersecant2, \

55 _nearestOn

56 from pygeodesy.ellipsoidalBaseDI import LatLonEllipsoidalBaseDI, \

57 _intersection3, _intersections2, _TOL_M

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, _ALL_OTHER

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_RO, property_doc_

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__ = '23.10.08'

76

77_antipodal_to_ = _SPACE_(_antipodal_, _to_)

78

79

80 class VincentyError(_ValueError):

81 '''Error raised from I{Vincenty}'s C{direct} and C{inverse} methods

82 for coincident points or lack of convergence.

83 '''

84 pass

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

94 '''

95 return _MODS.ecef.EcefVeness

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

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

121

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.

125

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

135

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)

141

142 @Property_RO

143 def Ecef(self):

144 '''Get the ECEF I{class} (L{EcefVeness}), I{lazily}.

145 '''

146 return _MODS.ecef.EcefVeness

147

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

149 def epsilon(self):

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

151 '''

152 return self._epsilon

153

154 @epsilon.setter # PYCHOK setter!

155 def epsilon(self, epsilon):

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

157

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

159

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

161 '''

162 self._epsilon = Scalar_(epsilon=epsilon)

163

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

169

170 @iterations.setter # PYCHOK setter!

171 def iterations(self, limit):

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

173

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

175

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

177 '''

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

179

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

181 '''Convert this point to C{Vincenty}-based cartesian (ECEF)

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

192

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)

199

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

201 '''(INTERNAL) Direct Vincenty method.

202

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

204

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

206 ellipsoids are not compatible.

207

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

214

215 sb, cb = sincos2d(bearing)

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

217

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

234

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

249

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

251 '''(INTERNAL) Inverse Vincenty method.

252

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

254

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

256 ellipsoids are not compatible.

257

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

265

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

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

268

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

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

271

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)

277

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)

286

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)

308

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

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

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

312

313 b = E.b

314# if self.height or other.height:

315# b += self._havg(other)

316 d = b * s

317

318 if azis: # forward and reverse azimuth

319 s, c = sincos2(ll)

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

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

322 else:

323 f = r = _0_0

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

325

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

331

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

338

339

340 def _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

347

348

349 def _c2sm2(c2sm):

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

351 return c2sm**2 * _2_0 - _1_0

352

353

354 def _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

364

365

366 def _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

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} C{(sin(B{a}), cos(B{a}), tan(B{a}))}

385 if a: # see L{sincostan3}

386 t = (_1_0 - f) * tan(a)

387 if t:

388 c = _1_0 / hypot1(t)

389 s = t * c

390 return s, c, t

391 return _0_0, _1_0, _0_0

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_OTHER(Cartesian, LatLon, intersecant2, # from .ellipsoidalBase

564 intersection3, intersections2, ispolar, # from .points

565 nearestOn) + _ALL_DOCS(areaOf, perimeterOf) # deprecated

566

567# **) MIT License

568#

569# Copyright (C) 2016-2023 -- mrJean1 at Gmail -- All Rights Reserved.

570#

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

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

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

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

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

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

577#

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

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

580#

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

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

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

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

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

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

587# OTHER DEALINGS IN THE SOFTWARE.