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 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, _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_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__ = '23.11.20'

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

145 '''

146 return _Ecef()

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 # NAN

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

378 # get the Ecef class and overwrite property_RO

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

380 return E

381

382

383 def _sincos22(sa):

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

385 ca2 = _1_0 - sa**2

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

387

388

389 def _sincostan3r(a, f):

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

391 if a: # see L{sincostan3}

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

393 if t:

394 c = _1_0 / hypot1(t)

395 s = c * t

396 return s, c, t

397 return _0_0, _1_0, _0_0

398

399

400@deprecated_function

401 def areaOf(points, **datum_wrap):

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

403 '''

404 try:

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

406 except ImportError:

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

408

409

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

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

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

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

414 (initial) bearing from North.

415

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

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

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

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

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

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

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

423 or C{None} for the mean height.

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

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

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

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

428 C{B{start1}.Equidistant}.

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

430 (C{meter}, conventionally).

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

432 or C{None}.

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

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

435

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

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

438 lon, height, datum)}.

439

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

441 non-intersecting lines or no convergence

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

443

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

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

446

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

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

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

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

451 earth perimeter).

452

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

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

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

456 BOUNDARIES} for more details about the iteration algorithm.

457 '''

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

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

460

461

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

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

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

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

466

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

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

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

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

471 B{C{radius1}}).

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

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

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

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

476 (C{bool}).

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

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

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

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

481 and B{C{radius2}}).

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

483 or C{None}.

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

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

486

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

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

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

490 aka the I{radical center}.

491

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

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

494

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

496 or invalid B{C{equidistant}}.

497

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

499

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

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

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

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

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

505 intersections.

506 '''

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

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

509

510

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

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

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

514 two other (ellipsoidal) points.

515

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

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

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

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

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

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

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

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

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

525 takes the heights of the points into account.

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

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

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

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

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

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

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

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

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

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

536

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

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

539

540 @raise ImportError: Package U{geographiclib

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

542 not installed or not found, but only if

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

544

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

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

547

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

549

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

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

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

553 BOUNDARIES} for more details about the iteration algorithm.

554 '''

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

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

557

558

559@deprecated_function

560 def perimeterOf(points, **closed_datum_wrap):

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

562 '''

563 try:

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

565 except ImportError:

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

567

568

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

570 intersection3, intersections2, ispolar, # from .points

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

572

573# **) MIT License

574#

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

576#

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

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

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

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

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

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

583#

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

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

586#

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

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

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

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

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

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

593# OTHER DEALINGS IN THE SOFTWARE.