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

55 from pygeodesy.ellipsoidalBaseDI import _intersection3, _intersections2, \

56 LatLonEllipsoidalBaseDI, _TOL_M

57 from pygeodesy.errors import _and, _ValueError, _xkwds

58 from pygeodesy.fmath import Fpolynomial, hypot, hypot1

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

60 _to_, _SPACE_, _limit_ # PYCHOK used!

61 from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS, _ALL_OTHER

62 from pygeodesy.namedTuples import Destination2Tuple, Destination3Tuple, \

63 Distance3Tuple

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

65 from pygeodesy.props import deprecated_function, deprecated_method, \

66 Property_RO, property_doc_

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

68 from pygeodesy.units import Number_, Scalar_

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

70

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

72

73__all__ = _ALL_LAZY.ellipsoidalVincenty

74__version__ = '23.05.30'

75

76_antipodal_to_ = _SPACE_(_antipodal_, _to_)

77

78

79 class VincentyError(_ValueError):

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

81 for coincident points or lack of convergence.

82 '''

83 pass

84

85

86 class Cartesian(CartesianEllipsoidalBase):

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

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

89 '''

90 @Property_RO

91 def Ecef(self):

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

93 '''

94 return _MODS.ecef.EcefVeness

95

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

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

98

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

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

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

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

103

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

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

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

107

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

109 '''

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

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

112

113

114 class LatLon(LatLonEllipsoidalBaseDI):

115 '''Using the formulae devised by U{I{Thaddeus Vincenty (1975)}

116 <https://WikiPedia.org/wiki/Vincenty's_formulae>} for an (oblate)

117 ellipsoidal model of the earth to compute the geodesic distance

118 and bearings between two given points or the destination point

119 given an start point and (initial) bearing.

120

121 Set the earth model to be used with the keyword argument

122 datum. The default is Datums.WGS84, which is the most globally

123 accurate. For other models, see the Datums in module datum.

124

125 Note: This implementation of I{Vincenty} methods may not converge

126 for some valid points, raising a L{VincentyError}. In that case,

127 a result may be obtained by increasing the tolerance C{epsilon}

128 and/or iteration C{limit}, see properties L{LatLon.epsilon} and

129 L{LatLon.iterations}.

130 '''

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

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

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

134

135 @deprecated_method

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

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

138 '''

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

140

141 @Property_RO

142 def Ecef(self):

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

144 '''

145 return _MODS.ecef.EcefVeness

146

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

148 def epsilon(self):

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

150 '''

151 return self._epsilon

152

153 @epsilon.setter # PYCHOK setter!

154 def epsilon(self, epsilon):

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

156

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

158

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

160 '''

161 self._epsilon = Scalar_(epsilon=epsilon)

162

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

164 def iterations(self):

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

166 '''

167 return self._iterations - 1

168

169 @iterations.setter # PYCHOK setter!

170 def iterations(self, limit):

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

172

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

174

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

176 '''

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

178

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

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

181 coordinates.

182

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

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

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

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

187

188 @return: The cartesian point (L{Cartesian}) or if B{C{Cartesian}}

189 is C{None}, an L{Ecef9Tuple}C{(x, y, z, lat, lon, height,

190 C, M, datum)} with C{C} and C{M} if available.

191

192 @raise TypeError: Invalid B{C{Cartesian}}, B{C{datum}} or other

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

205 ellipsoids are not compatible.

206

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

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

209 limits.

210 '''

211 E = self.ellipsoid()

212 f = E.f

213

214 sb, cb = sincos2d(bearing)

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

216

217 eps = self.epsilon

218 s12 = atan2(t1, cb) * _2_0

219 sa, ca2 = _sincos22(c1 * sb)

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

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

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

223 ss, cs = sincos2(s)

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

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

226 e = fabs(s - e)

227 if e < eps:

228 self._iteration = i

229 break

230 else:

231 t = self._no_convergence(e)

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

233

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

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

236 d = atan2b(sa, -t)

237 if llr:

238 b = cb * ss

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

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

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

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

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

244 else:

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

246 r._iteration = i

247 return r

248

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

250 '''(INTERNAL) Inverse Vincenty method.

251

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

253

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

255 ellipsoids are not compatible.

256

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

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

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

260 point are coincident or near-antipodal.

261 '''

262 E = self.ellipsoids(other)

263 f = E.f

264

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

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

267

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

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

270

271 eps = self.epsilon

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

273 dl = ll = radians(d)

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

275 sll, cll = sincos2(ll)

276

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

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

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

280 t = self._is_to(other, True)

281 raise VincentyError(_ambiguous_, txt=t)

282 self._iteration = i

283 # return zeros like Karney, unlike Veness

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

285

286 cs = s1s2 + c1c2 * cll

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

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

289 if ca2:

290 c2sm = cs - _2_0 * s1s2 / ca2

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

292 else: # equatorial line

293 ll = dl + f * sa * s

294 e = fabs(ll - e)

295 if e < eps:

296 self._iteration = i

297 break

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

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

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

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

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

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

304 else:

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

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

307

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

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

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

311

312 b = E.b

313# if self.height or other.height:

314# b += self._havg(other)

315 d = b * s

316

317 if azis: # forward and reverse azimuth

318 s, c = sincos2(ll)

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

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

321 else:

322 f = r = _0_0

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

324

325 def _is_to(self, other, anti):

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

327 '''

328 t = _antipodal_to_ if anti else _to_

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

330

331 def _no_convergence(self, e):

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

333 '''

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

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

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

337

338

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

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

341 if u2:

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

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

344 return A, B

345 return _1_0, _0_0

346

347

348 def _c2sm2(c2sm):

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

350 return c2sm**2 * _2_0 - _1_0

351

352

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

354 # C{Dl}

355 if f and sa:

356 C = f * ca2 / _4_0

357 C *= f - C * _3_0 + _1_0

358 if C and ss:

359 s += C * ss * (c2sm +

360 C * cs * _c2sm2(c2sm))

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

362 return dl

363

364

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

366 # C{Ds - d}

367 if B and ss:

368 c2sm2 = _c2sm2(c2sm)

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

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

371 B / _6_0 * c2sm * ss2))

372 d += B

373 return d

374

375

376 def _sincos22(sa):

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

378 ca2 = _1_0 - sa**2

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

380

381

382 def _sincostan3r(a, f):

383 # I{Reduced} C{(sin(B{a}), cos(B{a}), tan(B{a}))}

384 if a: # see L{sincostan3}

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

386 if t:

387 c = _1_0 / hypot1(t)

388 s = t * c

389 return s, c, t

390 return _0_0, _1_0, _0_0

391

392

393@deprecated_function

394 def areaOf(points, **datum_wrap):

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

396 '''

397 try:

398 return _MODS.ellipsoidalKarney.areaOf(points, **datum_wrap)

399 except ImportError:

400 return _MODS.ellipsoidalExact.areaOf(points, **datum_wrap)

401

402

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

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

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

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

407 (initial) bearing from North.

408

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

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

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

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

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

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

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

416 or C{None} for the mean height.

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

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

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

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

421 C{B{start1}.Equidistant}.

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

423 (C{meter}, conventionally).

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

425 or C{None}.

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

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

428

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

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

431 lon, height, datum)}.

432

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

434 non-intersecting lines or no convergence

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

436

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

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

439

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

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

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

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

444 earth perimeter).

445

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

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

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

449 BOUNDARIES} for more details about the iteration algorithm.

450 '''

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

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

453

454

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

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

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

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

459

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

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

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

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

464 B{C{radius1}}).

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

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

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

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

469 (C{bool}).

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

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

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

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

474 and B{C{radius2}}).

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

476 or C{None}.

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

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

479

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

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

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

483 aka the I{radical center}.

484

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

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

487

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

489 or invalid B{C{equidistant}}.

490

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

492

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

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

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

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

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

498 intersections.

499 '''

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

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

502

503

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

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

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

507 two other (ellipsoidal) points.

508

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

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

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

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

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

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

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

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

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

518 takes the heights of the points into account.

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

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

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

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

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

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

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

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

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

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

529

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

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

532

533 @raise ImportError: Package U{geographiclib

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

535 not installed or not found, but only if

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

537

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

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

540

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

542

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

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

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

546 BOUNDARIES} for more details about the iteration algorithm.

547 '''

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

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

550

551

552@deprecated_function

553 def perimeterOf(points, **closed_datum_wrap):

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

555 '''

556 try:

557 return _MODS.ellipsoidalKarney.perimeterOf(points, **closed_datum_wrap)

558 except ImportError:

559 return _MODS.ellipsoidalExact.perimeterOf(points, **closed_datum_wrap)

560

561

562__all__ += _ALL_OTHER(Cartesian, LatLon,

563 intersection3, intersections2, ispolar, # from .points

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

565

566# **) MIT License

567#

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

569#

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

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

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

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

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

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

576#

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

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

579#

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

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

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

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

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

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

586# OTHER DEALINGS IN THE SOFTWARE.