1

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

3

4 u'''(INTERNAL) Base class L{LatLonBase} for all elliposiodal, spherical and N-vectorial C{LatLon} classes.

5

6@see: I{(C) Chris Veness}' U{latlong<https://www.Movable-Type.co.UK/scripts/latlong.html>},

7 U{-ellipsoidal<https://www.Movable-Type.co.UK/scripts/geodesy/docs/latlon-ellipsoidal.js.html>} and

8 U{-vectors<https://www.Movable-Type.co.UK/scripts/latlong-vectors.html>} and I{Charles Karney}'s

9 U{Rhumb<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1Rhumb.html>} and

10 U{RhumbLine<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1RhumbLine.html>} classes.

11'''

12

13 from pygeodesy.basics import isscalar, isstr, map1, _xinstanceof

14 from pygeodesy.constants import EPS, EPS0, EPS1, EPS4, INT0, R_M, \

15 _0_0, _0_5, _1_0

16# from pygeodesy.datums import _spherical_datum # from .formy

17 from pygeodesy.dms import F_D, F_DMS, latDMS, lonDMS, parse3llh

18# from pygeodesy.ecef import EcefKarney # _MODS

19 from pygeodesy.errors import _incompatible, IntersectionError, _IsnotError, \

20 _TypeError, _ValueError, _xdatum, _xError, \

21 _xkwds, _xkwds_not

22# from pygeodesy.fmath import favg # _MODS

23 from pygeodesy.formy import antipode, compassAngle, cosineAndoyerLambert_, \

24 cosineForsytheAndoyerLambert_, cosineLaw, \

25 equirectangular, euclidean, flatLocal_, \

26 flatPolar, _hartzell, haversine, isantipode, \

27 _isequalTo, isnormal, normal, philam2n_xyz, \

28 thomas_, vincentys, _spherical_datum

29 from pygeodesy.interns import NN, _COMMASPACE_, _concentric_, _height_, \

30 _intersection_, _LatLon_, _m_, _negative_, \

31 _no_, _overlap_, _point_ # PYCHOK used!

32# from pygeodesy.iters import PointsIter, points2 # from .vector3d, _MODS

33# from pygeodesy.karney import Caps # _MODS

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

35# from pygeodesy.ltp import Ltp, _xLtp # _MODS

36 from pygeodesy.named import _NamedBase, notOverloaded, Fmt

37 from pygeodesy.namedTuples import Bounds2Tuple, LatLon2Tuple, PhiLam2Tuple, \

38 Trilaterate5Tuple, Vector3Tuple

39# from pygeodesy.nvectorBase import _N_vector_ # _MODS

40 from pygeodesy.props import deprecated_method, Property, Property_RO, \

41 property_RO, _update_all

42# from pygeodesy.streprs import Fmt, hstr # from .named, _MODS

43 from pygeodesy.units import Distance_, Lat, Lon, Height, Radius, Radius_, \

44 Scalar, Scalar_

45 from pygeodesy.utily import _unrollon, _unrollon3, _Wrap

46 from pygeodesy.vector2d import _circin6, Circin6Tuple, _circum3, circum4_, \

47 Circum3Tuple, _radii11ABC

48 from pygeodesy.vector3d import nearestOn6, Vector3d, PointsIter

49

50 from contextlib import contextmanager

51 from math import asin, cos, degrees, fabs, radians

52

53__all__ = _ALL_LAZY.latlonBase

54__version__ = '23.10.04'

55

56

57 class LatLonBase(_NamedBase):

58 '''(INTERNAL) Base class for C{LatLon} points on spherical or

59 ellipsoidal earth models.

60 '''

61 _clipid = INT0 # polygonal clip, see .booleans

62 _datum = None # L{Datum}, to be overriden

63 _height = INT0 # height (C{meter}), default

64 _lat = 0 # latitude (C{degrees})

65 _lon = 0 # longitude (C{degrees})

66

67 def __init__(self, latlonh, lon=None, height=0, wrap=False, name=NN):

68 '''New C{LatLon}.

69

70 @arg latlonh: Latitude (C{degrees} or DMS C{str} with N or S suffix) or

71 a previous C{LatLon} instance provided C{B{lon}=None}.

72 @kwarg lon: Longitude (C{degrees} or DMS C{str} with E or W suffix) or

73 C(None), indicating B{C{latlonh}} is a C{LatLon}.

74 @kwarg height: Optional height above (or below) the earth surface

75 (C{meter}, conventionally).

76 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{lat}} and B{C{lon}}

77 (C{bool}).

78 @kwarg name: Optional name (C{str}).

79

80 @return: New instance (C{LatLon}).

81

82 @raise RangeError: A B{C{lon}} or C{lat} value outside the valid

83 range and L{rangerrors} set to C{True}.

84

85 @raise TypeError: If B{C{latlonh}} is not a C{LatLon}.

86

87 @raise UnitError: Invalid B{C{lat}}, B{C{lon}} or B{C{height}}.

88

89 @example:

90

91 >>> p = LatLon(50.06632, -5.71475)

92 >>> q = LatLon('50°03′59″N', """005°42'53"W""")

93 >>> r = LatLon(p)

94 '''

95 if name:

96 self.name = name

97

98 if lon is None:

99 try:

100 lat, lon = latlonh.lat, latlonh.lon

101 height = latlonh.get(_height_, height)

102 except AttributeError:

103 raise _IsnotError(_LatLon_, latlonh=latlonh)

104 if wrap:

105 lat, lon = _Wrap.latlon(lat, lon)

106 elif wrap:

107 lat, lon = _Wrap.latlonDMS2(latlonh, lon)

108 else:

109 lat = latlonh

110

111 self._lat = Lat(lat) # parseDMS2(lat, lon)

112 self._lon = Lon(lon) # PYCHOK LatLon2Tuple

113 if height: # elevation

114 self._height = Height(height)

115

116 def __eq__(self, other):

117 return self.isequalTo(other)

118

119 def __ne__(self, other):

120 return not self.isequalTo(other)

121

122 def __str__(self):

123 return self.toStr(form=F_D, prec=6)

124

125 def antipode(self, height=None):

126 '''Return the antipode, the point diametrically opposite

127 to this point.

128

129 @kwarg height: Optional height of the antipode (C{meter}),

130 this point's height otherwise.

131

132 @return: The antipodal point (C{LatLon}).

133 '''

134 h = self._heigHt(height)

135 return self.classof(*antipode(*self.latlon), height=h)

136

137 @deprecated_method

138 def bounds(self, wide, tall, radius=R_M): # PYCHOK no cover

139 '''DEPRECATED, use method C{boundsOf}.'''

140 return self.boundsOf(wide, tall, radius=radius)

141

142 def boundsOf(self, wide, tall, radius=R_M, height=None):

143 '''Return the SW and NE lat-/longitude of a great circle

144 bounding box centered at this location.

145

146 @arg wide: Longitudinal box width (C{meter}, same units as

147 B{C{radius}} or C{degrees} if B{C{radius}} is C{None}).

148 @arg tall: Latitudinal box size (C{meter}, same units as

149 B{C{radius}} or C{degrees} if B{C{radius}} is C{None}).

150 @kwarg radius: Mean earth radius (C{meter}) or C{None} if I{both}

151 B{C{wide}} and B{C{tall}} are in C{degrees}.

152 @kwarg height: Height for C{latlonSW} and C{latlonNE} (C{meter}),

153 overriding the point's height.

154

155 @return: A L{Bounds2Tuple}C{(latlonSW, latlonNE)}, the

156 lower-left and upper-right corner (C{LatLon}).

157

158 @see: U{https://www.Movable-Type.co.UK/scripts/latlong-db.html}

159 '''

160 w = Scalar_(wide=wide) * _0_5

161 t = Scalar_(tall=tall) * _0_5

162 if radius is not None:

163 r = Radius_(radius)

164 c = cos(self.phi)

165 w = degrees(asin(w / r) / c) if fabs(c) > EPS0 else _0_0 # XXX

166 t = degrees(t / r)

167 y, t = self.lat, fabs(t)

168 x, w = self.lon, fabs(w)

169

170 h = self._heigHt(height)

171 sw = self.classof(y - t, x - w, height=h)

172 ne = self.classof(y + t, x + w, height=h)

173 return Bounds2Tuple(sw, ne, name=self.name)

174

175 def chordTo(self, other, height=None, wrap=False):

176 '''Compute the length of the chord through the earth between

177 this and an other point.

178

179 @arg other: The other point (C{LatLon}).

180 @kwarg height: Overriding height for both points (C{meter})

181 or C{None} for each point's height.

182 @kwarg wrap: If C{True}, wrap or I{normalize} the B{C{other}}

183 point (C{bool}).

184

185 @return: The chord length (conventionally C{meter}).

186

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

188 '''

189 def _v3d(ll):

190 t = ll.toEcef(height=height) # .toVector(Vector=Vector3d)

191 return Vector3d(t.x, t.y, t.z)

192

193 p = self.others(other)

194 if wrap:

195 p = _Wrap.point(p)

196 return _v3d(self).minus(_v3d(p)).length

197

198 def circin6(self, point2, point3, eps=EPS4, wrap=False):

199 '''Return the radius and center of the I{inscribed} aka I{In-}circle

200 of the (planar) triangle formed by this and two other points.

201

202 @arg point2: Second point (C{LatLon}).

203 @arg point3: Third point (C{LatLon}).

204 @kwarg eps: Tolerance for function L{pygeodesy.trilaterate3d2}.

205 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{point2}} and

206 B{C{point3}} (C{bool}).

207

208 @return: L{Circin6Tuple}C{(radius, center, deltas, cA, cB, cC)}. The

209 C{center} and contact points C{cA}, C{cB} and C{cC}, each an

210 instance of this (sub-)class, are co-planar with this and the

211 two given points, see the B{Note} below.

212

213 @raise ImportError: Package C{numpy} not found, not installed or older

214 than version 1.10.

215

216 @raise IntersectionError: Near-coincident or -colinear points or

217 a trilateration or C{numpy} issue.

218

219 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.

220

221 @note: The C{center} is trilaterated in cartesian (ECEF) space and converted

222 back to geodetic lat-, longitude and height. The latter, conventionally

223 in C{meter} indicates whether the C{center} is above, below or on the

224 surface of the earth model. If C{deltas} is C{None}, the C{center} is

225 I{un}ambigous. Otherwise C{deltas} is a L{LatLon3Tuple}C{(lat, lon,

226 height)} representing the differences between both results from

227 L{pygeodesy.trilaterate3d2} and C{center} is the mean thereof.

228

229 @see: Function L{pygeodesy.circin6}, method L{circum3}, U{Incircle

230 <https://MathWorld.Wolfram.com/Incircle.html>} and U{Contact Triangle

231 <https://MathWorld.Wolfram.com/ContactTriangle.html>}.

232 '''

233 with _toCartesian3(self, point2, point3, wrap) as cs:

234 r, c, d, cA, cB, cC = _circin6(*cs, eps=eps, useZ=True, dLL3=True,

235 datum=self.datum) # PYCHOK unpack

236 return Circin6Tuple(r, c.toLatLon(), d, cA.toLatLon(), cB.toLatLon(), cC.toLatLon())

237

238 def circum3(self, point2, point3, circum=True, eps=EPS4, wrap=False):

239 '''Return the radius and center of the smallest circle I{through} or I{containing}

240 this and two other points.

241

242 @arg point2: Second point (C{LatLon}).

243 @arg point3: Third point (C{LatLon}).

244 @kwarg circum: If C{True} return the C{circumradius} and C{circumcenter},

245 always, ignoring the I{Meeus}' Type I case (C{bool}).

246 @kwarg eps: Tolerance for function L{pygeodesy.trilaterate3d2}.

247 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{point2}} and

248 B{C{point3}} (C{bool}).

249

250 @return: A L{Circum3Tuple}C{(radius, center, deltas)}. The C{center}, an

251 instance of this (sub-)class, is co-planar with this and the two

252 given points. If C{deltas} is C{None}, the C{center} is

253 I{un}ambigous. Otherwise C{deltas} is a L{LatLon3Tuple}C{(lat,

254 lon, height)} representing the difference between both results

255 from L{pygeodesy.trilaterate3d2} and C{center} is the mean thereof.

256

257 @raise ImportError: Package C{numpy} not found, not installed or older than

258 version 1.10.

259

260 @raise IntersectionError: Near-concentric, -coincident or -colinear points,

261 incompatible C{Ecef} classes or a trilateration

262 or C{numpy} issue.

263

264 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.

265

266 @note: The C{center} is trilaterated in cartesian (ECEF) space and converted

267 back to geodetic lat-, longitude and height. The latter, conventionally

268 in C{meter} indicates whether the C{center} is above, below or on the

269 surface of the earth model. If C{deltas} is C{None}, the C{center} is

270 I{un}ambigous. Otherwise C{deltas} is a L{LatLon3Tuple}C{(lat, lon,

271 height)} representing the difference between both results from

272 L{pygeodesy.trilaterate3d2} and C{center} is the mean thereof.

273

274 @see: Function L{pygeodesy.circum3} and methods L{circin6} and L{circum4_}.

275 '''

276 with _toCartesian3(self, point2, point3, wrap, circum=circum) as cs:

277 r, c, d = _circum3(*cs, circum=circum, eps=eps, useZ=True, dLL3=True, # XXX -3d2

278 clas=cs[0].classof, datum=self.datum) # PYCHOK unpack

279 return Circum3Tuple(r, c.toLatLon(), d)

280

281 def circum4_(self, *points, **wrap):

282 '''Best-fit a sphere through this and two or more other points.

283

284 @arg points: The other points (each a C{LatLon}).

285 @kwarg wrap: If C{True}, wrap or I{normalize} the B{C{points}}

286 (C{bool}), default C{False}.

287

288 @return: L{Circum4Tuple}C{(radius, center, rank, residuals)} with C{center}

289 an instance of this (sub-)class.

290

291 @raise ImportError: Package C{numpy} not found, not installed or older than

292 version 1.10.

293

294 @raise NumPyError: Some C{numpy} issue.

295

296 @raise TypeError: One of the B{C{points}} invalid.

297

298 @raise ValueError: Too few B{C{points}}.

299

300 @see: Function L{pygeodesy.circum4_} and L{circum3}.

301 '''

302 def _cs(ps, C, wrap=False):

303 _wp = _Wrap.point if wrap else (lambda p: p)

304 for i, p in enumerate(ps):

305 yield C(i=i, points=_wp(p))

306

307 C = self._toCartesianEcef

308 c = C(point=self)

309 t = circum4_(c, Vector=c.classof, *_cs(points, C, **wrap))

310 c = t.center.toLatLon(LatLon=self.classof)

311 return t.dup(center=c)

312

313 @property

314 def clipid(self):

315 '''Get the (polygonal) clip (C{int}).

316 '''

317 return self._clipid

318

319 @clipid.setter # PYCHOK setter!

320 def clipid(self, clipid):

321 '''Get the (polygonal) clip (C{int}).

322 '''

323 self._clipid = int(clipid)

324

325 @deprecated_method

326 def compassAngle(self, other, **adjust_wrap): # PYCHOK no cover

327 '''DEPRECATED, use method L{compassAngleTo}.'''

328 return self.compassAngleTo(other, **adjust_wrap)

329

330 def compassAngleTo(self, other, **adjust_wrap):

331 '''Return the angle from North for the direction vector between

332 this and an other point.

333

334 Suitable only for short, non-near-polar vectors up to a few

335 hundred Km or Miles. Use method C{initialBearingTo} for

336 larger distances.

337

338 @arg other: The other point (C{LatLon}).

339 @kwarg adjust_wrap: Optional keyword arguments for function

340 L{pygeodesy.compassAngle}.

341

342 @return: Compass angle from North (C{degrees360}).

343

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

345

346 @note: Courtesy of Martin Schultz.

347

348 @see: U{Local, flat earth approximation

349 <https://www.EdWilliams.org/avform.htm#flat>}.

350 '''

351 p = self.others(other)

352 return compassAngle(self.lat, self.lon, p.lat, p.lon, **adjust_wrap)

353

354 def cosineAndoyerLambertTo(self, other, wrap=False):

355 '''Compute the distance between this and an other point using the U{Andoyer-Lambert correction<https://

356 navlib.net/wp-content/uploads/2013/10/admiralty-manual-of-navigation-vol-1-1964-english501c.pdf>}

357 of the U{Law of Cosines<https://www.Movable-Type.co.UK/scripts/latlong.html#cosine-law>} formula.

358

359 @arg other: The other point (C{LatLon}).

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

361 the B{C{other}} point (C{bool}).

362

363 @return: Distance (C{meter}, same units as the axes of this

364 point's datum ellipsoid).

365

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

367

368 @see: Function L{pygeodesy.cosineAndoyerLambert} and methods

369 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo},

370 C{distanceTo*}, L{equirectangularTo}, L{euclideanTo},

371 L{flatLocalTo}/L{hubenyTo}, L{flatPolarTo}, L{haversineTo},

372 L{thomasTo} and L{vincentysTo}.

373 '''

374 return self._distanceTo_(cosineAndoyerLambert_, other, wrap=wrap)

375

376 def cosineForsytheAndoyerLambertTo(self, other, wrap=False):

377 '''Compute the distance between this and an other point using

378 the U{Forsythe-Andoyer-Lambert correction

379 <https://www2.UNB.Ca/gge/Pubs/TR77.pdf>} of the U{Law of Cosines

380 <https://www.Movable-Type.co.UK/scripts/latlong.html#cosine-law>}

381 formula.

382

383 @arg other: The other point (C{LatLon}).

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

385 the B{C{other}} point (C{bool}).

386

387 @return: Distance (C{meter}, same units as the axes of

388 this point's datum ellipsoid).

389

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

391

392 @see: Function L{pygeodesy.cosineForsytheAndoyerLambert} and methods

393 L{cosineAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},

394 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},

395 L{flatPolarTo}, L{haversineTo}, L{thomasTo} and L{vincentysTo}.

396 '''

397 return self._distanceTo_(cosineForsytheAndoyerLambert_, other, wrap=wrap)

398

399 def cosineLawTo(self, other, radius=None, wrap=False):

400 '''Compute the distance between this and an other point using the

401 U{spherical Law of Cosines

402 <https://www.Movable-Type.co.UK/scripts/latlong.html#cosine-law>}

403 formula.

404

405 @arg other: The other point (C{LatLon}).

406 @kwarg radius: Mean earth radius (C{meter}) or C{None}

407 for the mean radius of this point's datum

408 ellipsoid.

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

410 the B{C{other}} point (C{bool}).

411

412 @return: Distance (C{meter}, same units as B{C{radius}}).

413

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

415

416 @see: Function L{pygeodesy.cosineLaw} and methods L{cosineAndoyerLambertTo},

417 L{cosineForsytheAndoyerLambertTo}, C{distanceTo*}, L{equirectangularTo},

418 L{euclideanTo}, L{flatLocalTo}/L{hubenyTo}, L{flatPolarTo},

419 L{haversineTo}, L{thomasTo} and L{vincentysTo}.

420 '''

421 return self._distanceTo(cosineLaw, other, radius, wrap=wrap)

422

423 @property_RO

424 def datum(self): # PYCHOK no cover

425 '''I{Must be overloaded}.'''

426 notOverloaded(self)

427

428 def destinationXyz(self, delta, LatLon=None, **LatLon_kwds):

429 '''Calculate the destination using a I{local} delta from this point.

430

431 @arg delta: Local delta to the destination (L{XyzLocal}, L{Enu},

432 L{Ned} or L{Local9Tuple}).

433 @kwarg LatLon: Optional (geodetic) class to return the destination

434 or C{None}.

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

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

437

438 @return: Destination as a C{B{LatLon}(lat, lon, **B{LatLon_kwds})}

439 instance or if C{B{LatLon} is None}, a L{LatLon3Tuple}C{(lat,

440 lon, height)} respectively L{LatLon4Tuple}C{(lat, lon,

441 height, datum)} depending on whether a C{datum} keyword

442 is un-/specified.

443

444 @raise TypeError: Invalid B{C{delta}}, B{C{LatLon}} or B{C{LatLon_kwds}}.

445 '''

446 t = self._ltp._local2ecef(delta, nine=True)

447 return t.toLatLon(LatLon=LatLon, **_xkwds(LatLon_kwds, name=self.name))

448

449 def _distanceTo(self, func, other, radius=None, **kwds):

450 '''(INTERNAL) Helper for distance methods C{<func>To}.

451 '''

452 p, r = self.others(other, up=2), radius

453 if r is None:

454 r = self._datum.ellipsoid.R1 if self._datum else R_M

455 return func(self.lat, self.lon, p.lat, p.lon, radius=r, **kwds)

456

457 def _distanceTo_(self, func_, other, wrap=False, radius=None):

458 '''(INTERNAL) Helper for (ellipsoidal) methods C{<func>To}.

459 '''

460 p = self.others(other, up=2)

461 D = self.datum

462 lam21, phi2, _ = _Wrap.philam3(self.lam, p.phi, p.lam, wrap)

463 r = func_(phi2, self.phi, lam21, datum=D)

464 return r * (D.ellipsoid.a if radius is None else radius)

465

466 @Property_RO

467 def Ecef(self):

468 '''Get the ECEF I{class} (L{EcefKarney}), I{lazily}.

469 '''

470 return _MODS.ecef.EcefKarney # default

471

472 @Property_RO

473 def _Ecef_forward(self):

474 '''(INTERNAL) Helper for L{_ecef9} and L{toEcef} (C{callable}).

475 '''

476 return self.Ecef(self.datum, name=self.name).forward

477

478 @Property_RO

479 def _ecef9(self):

480 '''(INTERNAL) Helper for L{toCartesian}, L{toEcef} and L{toCartesian} (L{Ecef9Tuple}).

481 '''

482 return self._Ecef_forward(self, M=True)

483

484 @deprecated_method

485 def equals(self, other, eps=None): # PYCHOK no cover

486 '''DEPRECATED, use method L{isequalTo}.'''

487 return self.isequalTo(other, eps=eps)

488

489 @deprecated_method

490 def equals3(self, other, eps=None): # PYCHOK no cover

491 '''DEPRECATED, use method L{isequalTo3}.'''

492 return self.isequalTo3(other, eps=eps)

493

494 def equirectangularTo(self, other, **radius_adjust_limit_wrap):

495 '''Compute the distance between this and an other point

496 using the U{Equirectangular Approximation / Projection

497 <https://www.Movable-Type.co.UK/scripts/latlong.html#equirectangular>}.

498

499 Suitable only for short, non-near-polar distances up to a

500 few hundred Km or Miles. Use method L{haversineTo} or

501 C{distanceTo*} for more accurate and/or larger distances.

502

503 @arg other: The other point (C{LatLon}).

504 @kwarg radius_adjust_limit_wrap: Optional keyword arguments

505 for function L{pygeodesy.equirectangular},

506 overriding the default mean C{radius} of this

507 point's datum ellipsoid.

508

509 @return: Distance (C{meter}, same units as B{C{radius}}).

510

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

512

513 @see: Function L{pygeodesy.equirectangular} and methods L{cosineAndoyerLambertTo},

514 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},

515 C{euclideanTo}, L{flatLocalTo}/L{hubenyTo}, L{flatPolarTo},

516 L{haversineTo}, L{thomasTo} and L{vincentysTo}.

517 '''

518 return self._distanceTo(equirectangular, other, **radius_adjust_limit_wrap)

519

520 def euclideanTo(self, other, **radius_adjust_wrap):

521 '''Approximate the C{Euclidian} distance between this and

522 an other point.

523

524 See function L{pygeodesy.euclidean} for the available B{C{options}}.

525

526 @arg other: The other point (C{LatLon}).

527 @kwarg radius_adjust_wrap: Optional keyword arguments for function

528 L{pygeodesy.euclidean}, overriding the default mean

529 C{radius} of this point's datum ellipsoid.

530

531 @return: Distance (C{meter}, same units as B{C{radius}}).

532

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

534

535 @see: Function L{pygeodesy.euclidean} and methods L{cosineAndoyerLambertTo},

536 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},

537 L{equirectangularTo}, L{flatLocalTo}/L{hubenyTo}, L{flatPolarTo},

538 L{haversineTo}, L{thomasTo} and L{vincentysTo}.

539 '''

540 return self._distanceTo(euclidean, other, **radius_adjust_wrap)

541

542 def flatLocalTo(self, other, radius=None, wrap=False):

543 '''Compute the distance between this and an other point using the

544 U{ellipsoidal Earth to plane projection

545 <https://WikiPedia.org/wiki/Geographical_distance#Ellipsoidal_Earth_projected_to_a_plane>}

546 aka U{Hubeny<https://www.OVG.AT/de/vgi/files/pdf/3781/>} formula.

547

548 @arg other: The other point (C{LatLon}).

549 @kwarg radius: Mean earth radius (C{meter}) or C{None} for

550 the I{equatorial radius} of this point's

551 datum ellipsoid.

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

553 the B{C{other}} point (C{bool}).

554

555 @return: Distance (C{meter}, same units as B{C{radius}}).

556

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

558

559 @raise ValueError: Invalid B{C{radius}}.

560

561 @see: Function L{pygeodesy.flatLocal}/L{pygeodesy.hubeny}, methods

562 L{cosineAndoyerLambertTo}, L{cosineForsytheAndoyerLambertTo},

563 L{cosineLawTo}, C{distanceTo*}, L{equirectangularTo}, L{euclideanTo},

564 L{flatPolarTo}, L{haversineTo}, L{thomasTo} and L{vincentysTo} and

565 U{local, flat Earth approximation<https://www.edwilliams.org/avform.htm#flat>}.

566 '''

567 return self._distanceTo_(flatLocal_, other, wrap=wrap, radius=

568 radius if radius in (None, R_M, _1_0, 1) else Radius(radius)) # PYCHOK kwargs

569

570 hubenyTo = flatLocalTo # for Karl Hubeny

571

572 def flatPolarTo(self, other, **radius_wrap):

573 '''Compute the distance between this and an other point using

574 the U{polar coordinate flat-Earth<https://WikiPedia.org/wiki/

575 Geographical_distance#Polar_coordinate_flat-Earth_formula>} formula.

576

577 @arg other: The other point (C{LatLon}).

578 @kwarg radius_wrap: Optional keyword arguments for function

579 L{pygeodesy.flatPolar}, overriding the

580 default mean C{radius} of this point's

581 datum ellipsoid.

582

583 @return: Distance (C{meter}, same units as B{C{radius}}).

584

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

586

587 @see: Function L{pygeodesy.flatPolar} and methods L{cosineAndoyerLambertTo},

588 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},

589 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},

590 L{haversineTo}, L{thomasTo} and L{vincentysTo}.

591 '''

592 return self._distanceTo(flatPolar, other, **radius_wrap)

593

594 def hartzell(self, los=None, earth=None):

595 '''Compute the intersection of a Line-Of-Sight (los) from this Point-Of-View

596 (pov) with this point's ellipsoid surface.

597

598 @kwarg los: Line-Of-Sight, I{direction} to earth (L{Los}, L{Vector3d})

599 or C{None} to point to the ellipsoid's center.

600 @kwarg earth: The earth model (L{Datum}, L{Ellipsoid}, L{Ellipsoid2},

601 L{a_f2Tuple} or C{scalar} radius in C{meter}) overriding

602 this point's C{datum} ellipsoid.

603

604 @return: The ellipsoid intersection (C{LatLon}) with C{.height} set

605 to the distance to this C{pov}.

606

607 @raise IntersectionError: Null or bad C{pov} or B{C{los}}, this C{pov}

608 is inside the ellipsoid or B{C{los}} points

609 outside or away from the ellipsoid.

610

611 @raise TypeError: Invalid B{C{los}}.

612

613 @see: Function C{hartzell} for further details.

614 '''

615 return _hartzell(self, los, earth, LatLon=self.classof)

616

617 def haversineTo(self, other, **radius_wrap):

618 '''Compute the distance between this and an other point using the

619 U{Haversine<https://www.Movable-Type.co.UK/scripts/latlong.html>}

620 formula.

621

622 @arg other: The other point (C{LatLon}).

623 @kwarg radius_wrap: Optional keyword arguments for function

624 L{pygeodesy.haversine}, overriding the

625 default mean C{radius} of this point's

626 datum ellipsoid.

627

628 @return: Distance (C{meter}, same units as B{C{radius}}).

629

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

631

632 @see: Function L{pygeodesy.haversine} and methods L{cosineAndoyerLambertTo},

633 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},

634 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},

635 L{flatPolarTo}, L{thomasTo} and L{vincentysTo}.

636 '''

637 return self._distanceTo(haversine, other, **radius_wrap)

638

639 def _havg(self, other, f=_0_5, h=None):

640 '''(INTERNAL) Weighted, average height.

641

642 @arg other: An other point (C{LatLon}).

643 @kwarg f: Optional fraction (C{float}).

644 @kwarg h: Overriding height (C{meter}).

645

646 @return: Average, fractional height (C{float}) or

647 the overriding B{C{height}} (C{Height}).

648 '''

649 return Height(h) if h is not None else \

650 _MODS.fmath.favg(self.height, other.height, f=f)

651

652 @Property

653 def height(self):

654 '''Get the height (C{meter}).

655 '''

656 return self._height

657

658 @height.setter # PYCHOK setter!

659 def height(self, height):

660 '''Set the height (C{meter}).

661

662 @raise TypeError: Invalid B{C{height}} C{type}.

663

664 @raise ValueError: Invalid B{C{height}}.

665 '''

666 h = Height(height)

667 if self._height != h:

668 _update_all(self)

669 self._height = h

670

671 def _heigHt(self, height):

672 '''(INTERNAL) Overriding this C{height}.

673 '''

674 return self.height if height is None else Height(height)

675

676 def height4(self, earth=None, normal=True, LatLon=None, **LatLon_kwds):

677 '''Compute the height above or below and the projection of this point

678 on this datum's or on an other earth's ellipsoid surface.

679

680 @kwarg earth: A datum, ellipsoid, triaxial ellipsoid or earth radius

681 I{overriding} this datum (L{Datum}, L{Ellipsoid},

682 L{Ellipsoid2}, L{a_f2Tuple}, L{Triaxial}, L{Triaxial_},

683 L{JacobiConformal} or C{meter}, conventionally).

684 @kwarg normal: If C{True} the projection is the nearest point on the

685 ellipsoid's surface, otherwise the intersection of the

686 radial line to the center and the ellipsoid's surface.

687 @kwarg LatLon: Optional class to return the height and projection

688 (C{LatLon}) or C{None}.

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

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

691

692 @note: Use keyword argument C{height=0} to override C{B{LatLon}.height}

693 to {0} or any other C{scalar}, conventionally in C{meter}.

694

695 @return: An instance of B{C{LatLon}} or if C{B{LatLon} is None}, a

696 L{Vector4Tuple}C{(x, y, z, h)} with the I{projection} C{x}, C{y}

697 and C{z} coordinates and height C{h} in C{meter}, conventionally.

698

699 @raise TriaxialError: No convergence in triaxial root finding.

700

701 @raise TypeError: Invalid B{C{earth}}.

702

703 @see: L{Ellipsoid.height4} and L{Triaxial_.height4} for more information.

704 '''

705 c = self.toCartesian()

706 if LatLon is None:

707 r = c.height4(earth=earth, normal=normal)

708 else:

709 r = c.height4(earth=earth, normal=normal, Cartesian=c.classof, height=0)

710 r = r.toLatLon(LatLon=LatLon, **_xkwds(LatLon_kwds, height=r.height))

711 return r

712

713 def heightStr(self, prec=-2, m=_m_):

714 '''Return this point's B{C{height}} as C{str}ing.

715

716 @kwarg prec: Number of (decimal) digits, unstripped (C{int}).

717 @kwarg m: Optional unit of the height (C{str}).

718

719 @see: Function L{pygeodesy.hstr}.

720 '''

721 return _MODS.streprs.hstr(self.height, prec=prec, m=m)

722

723 @deprecated_method

724 def isantipode(self, other, eps=EPS): # PYCHOK no cover

725 '''DEPRECATED, use method L{isantipodeTo}.'''

726 return self.isantipodeTo(other, eps=eps)

727

728 def isantipodeTo(self, other, eps=EPS):

729 '''Check whether this and an other point are antipodal,

730 on diametrically opposite sides of the earth.

731

732 @arg other: The other point (C{LatLon}).

733 @kwarg eps: Tolerance for near-equality (C{degrees}).

734

735 @return: C{True} if points are antipodal within the given

736 tolerance, C{False} otherwise.

737 '''

738 p = self.others(other)

739 return isantipode(*(self.latlon + p.latlon), eps=eps)

740

741 @Property_RO

742 def isEllipsoidal(self):

743 '''Check whether this point is ellipsoidal (C{bool} or C{None} if unknown).

744 '''

745 return self.datum.isEllipsoidal if self._datum else None

746

747 @Property_RO

748 def isEllipsoidalLatLon(self):

749 '''Get C{LatLon} base.

750 '''

751 return False

752

753 def isequalTo(self, other, eps=None):

754 '''Compare this point with an other point, I{ignoring} height.

755

756 @arg other: The other point (C{LatLon}).

757 @kwarg eps: Tolerance for equality (C{degrees}).

758

759 @return: C{True} if both points are identical,

760 I{ignoring} height, C{False} otherwise.

761

762 @raise TypeError: The B{C{other}} point is not C{LatLon}

763 or mismatch of the B{C{other}} and

764 this C{class} or C{type}.

765

766 @raise UnitError: Invalid B{C{eps}}.

767

768 @see: Method L{isequalTo3}.

769 '''

770 return _isequalTo(self, self.others(other), eps=eps)

771

772 def isequalTo3(self, other, eps=None):

773 '''Compare this point with an other point, I{including} height.

774

775 @arg other: The other point (C{LatLon}).

776 @kwarg eps: Tolerance for equality (C{degrees}).

777

778 @return: C{True} if both points are identical

779 I{including} height, C{False} otherwise.

780

781 @raise TypeError: The B{C{other}} point is not C{LatLon}

782 or mismatch of the B{C{other}} and

783 this C{class} or C{type}.

784

785 @see: Method L{isequalTo}.

786 '''

787 return self.height == self.others(other).height and \

788 _isequalTo(self, other, eps=eps)

789

790 @Property_RO

791 def isnormal(self):

792 '''Return C{True} if this point is normal (C{bool}),

793 meaning C{abs(lat) <= 90} and C{abs(lon) <= 180}.

794

795 @see: Methods L{normal}, L{toNormal} and functions

796 L{pygeodesy.isnormal} and L{pygeodesy.normal}.

797 '''

798 return isnormal(self.lat, self.lon, eps=0)

799

800 @Property_RO

801 def isSpherical(self):

802 '''Check whether this point is spherical (C{bool} or C{None} if unknown).

803 '''

804 return self.datum.isSpherical if self._datum else None

805

806 @Property_RO

807 def lam(self):

808 '''Get the longitude (B{C{radians}}).

809 '''

810 return radians(self.lon)

811

812 @Property

813 def lat(self):

814 '''Get the latitude (C{degrees90}).

815 '''

816 return self._lat

817

818 @lat.setter # PYCHOK setter!

819 def lat(self, lat):

820 '''Set the latitude (C{str[N|S]} or C{degrees}).

821

822 @raise ValueError: Invalid B{C{lat}}.

823 '''

824 lat = Lat(lat) # parseDMS(lat, suffix=_NS_, clip=90)

825 if self._lat != lat:

826 _update_all(self)

827 self._lat = lat

828

829 @Property

830 def latlon(self):

831 '''Get the lat- and longitude (L{LatLon2Tuple}C{(lat, lon)}).

832 '''

833 return LatLon2Tuple(self._lat, self._lon, name=self.name)

834

835 @latlon.setter # PYCHOK setter!

836 def latlon(self, latlonh):

837 '''Set the lat- and longitude and optionally the height

838 (2- or 3-tuple or comma- or space-separated C{str}

839 of C{degrees90}, C{degrees180} and C{meter}).

840

841 @raise TypeError: Height of B{C{latlonh}} not C{scalar} or

842 B{C{latlonh}} not C{list} or C{tuple}.

843

844 @raise ValueError: Invalid B{C{latlonh}} or M{len(latlonh)}.

845

846 @see: Function L{pygeodesy.parse3llh} to parse a B{C{latlonh}}

847 string into a 3-tuple C{(lat, lon, h)}.

848 '''

849 if isstr(latlonh):

850 latlonh = parse3llh(latlonh, height=self.height)

851 else:

852 _xinstanceof(list, tuple, latlonh=latlonh)

853 if len(latlonh) == 3:

854 h = Height(latlonh[2], name=Fmt.SQUARE(latlonh=2))

855 elif len(latlonh) != 2:

856 raise _ValueError(latlonh=latlonh)

857 else:

858 h = self.height

859

860 llh = Lat(latlonh[0]), Lon(latlonh[1]), h # parseDMS2(latlonh[0], latlonh[1])

861 if (self._lat, self._lon, self._height) != llh:

862 _update_all(self)

863 self._lat, self._lon, self._height = llh

864

865 def latlon2(self, ndigits=0):

866 '''Return this point's lat- and longitude in C{degrees}, rounded.

867

868 @kwarg ndigits: Number of (decimal) digits (C{int}).

869

870 @return: A L{LatLon2Tuple}C{(lat, lon)}, both C{float}

871 and rounded away from zero.

872

873 @note: The C{round}ed values are always C{float}, also

874 if B{C{ndigits}} is omitted.

875 '''

876 return LatLon2Tuple(round(self.lat, ndigits),

877 round(self.lon, ndigits), name=self.name)

878

879 @deprecated_method

880 def latlon_(self, ndigits=0): # PYCHOK no cover

881 '''DEPRECATED, use method L{latlon2}.'''

882 return self.latlon2(ndigits=ndigits)

883

884 latlon2round = latlon_ # PYCHOK no cover

885

886 @Property

887 def latlonheight(self):

888 '''Get the lat-, longitude and height (L{LatLon3Tuple}C{(lat, lon, height)}).

889 '''

890 return self.latlon.to3Tuple(self.height)

891

892 @latlonheight.setter # PYCHOK setter!

893 def latlonheight(self, latlonh):

894 '''Set the lat- and longitude and optionally the height

895 (2- or 3-tuple or comma- or space-separated C{str}

896 of C{degrees90}, C{degrees180} and C{meter}).

897

898 @see: Property L{latlon} for more details.

899 '''

900 self.latlon = latlonh

901

902 @Property

903 def lon(self):

904 '''Get the longitude (C{degrees180}).

905 '''

906 return self._lon

907

908 @lon.setter # PYCHOK setter!

909 def lon(self, lon):

910 '''Set the longitude (C{str[E|W]} or C{degrees}).

911

912 @raise ValueError: Invalid B{C{lon}}.

913 '''

914 lon = Lon(lon) # parseDMS(lon, suffix=_EW_, clip=180)

915 if self._lon != lon:

916 _update_all(self)

917 self._lon = lon

918

919 @Property_RO

920 def _ltp(self):

921 '''(INTERNAL) Cache for L{toLtp}.

922 '''

923 return _MODS.ltp.Ltp(self, ecef=self.Ecef(self.datum), name=self.name)

924

925 def nearestOn6(self, points, closed=False, height=None, wrap=False):

926 '''Locate the point on a path or polygon closest to this point.

927

928 Points are converted to and distances are computed in

929 I{geocentric}, cartesian space.

930

931 @arg points: The path or polygon points (C{LatLon}[]).

932 @kwarg closed: Optionally, close the polygon (C{bool}).

933 @kwarg height: Optional height, overriding the height of

934 this and all other points (C{meter}). If

935 C{None}, take the height of points into

936 account for distances.

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

938 the B{C{points}} (C{bool}).

939

940 @return: A L{NearestOn6Tuple}C{(closest, distance, fi, j,

941 start, end)} with the C{closest}, the C{start}

942 and the C{end} point each an instance of this

943 C{LatLon} and C{distance} in C{meter}, same

944 units as the cartesian axes.

945

946 @raise PointsError: Insufficient number of B{C{points}}.

947

948 @raise TypeError: Some B{C{points}} or some B{C{points}}'

949 C{Ecef} invalid.

950

951 @raise ValueError: Some B{C{points}}' C{Ecef} is incompatible.

952

953 @see: Function L{pygeodesy.nearestOn6}.

954 '''

955 def _cs(Ps, h, w, C):

956 p = None # not used

957 for i, q in Ps.enumerate():

958 if w and i:

959 q = _unrollon(p, q)

960 yield C(height=h, i=i, up=3, points=q)

961 p = q

962

963 C = self._toCartesianEcef # to verify datum and Ecef

964 Ps = self.PointsIter(points, wrap=wrap)

965

966 c = C(height=height, this=self) # this Cartesian

967 t = nearestOn6(c, _cs(Ps, height, wrap, C), closed=closed)

968 c, s, e = t.closest, t.start, t.end

969

970 kwds = _xkwds_not(None, LatLon=self.classof, # this LatLon

971 height=height)

972 _r = self.Ecef(self.datum).reverse

973 p = _r(c).toLatLon(**kwds)

974 s = _r(s).toLatLon(**kwds) if s is not c else p

975 e = _r(e).toLatLon(**kwds) if e is not c else p

976 return t.dup(closest=p, start=s, end=e)

977

978 def normal(self):

979 '''Normalize this point I{in-place} to C{abs(lat) <= 90} and

980 C{abs(lon) <= 180}.

981

982 @return: C{True} if this point was I{normal}, C{False} if it

983 wasn't (but is now).

984

985 @see: Property L{isnormal} and method L{toNormal}.

986 '''

987 n = self.isnormal

988 if not n:

989 self.latlon = normal(*self.latlon)

990 return n

991

992 @Property_RO

993 def _N_vector(self):

994 '''(INTERNAL) Get the (C{nvectorBase._N_vector_})

995 '''

996 return _MODS.nvectorBase._N_vector_(*self.xyzh)

997

998 @Property_RO

999 def phi(self):

1000 '''Get the latitude (B{C{radians}}).

1001 '''

1002 return radians(self.lat)

1003

1004 @Property_RO

1005 def philam(self):

1006 '''Get the lat- and longitude (L{PhiLam2Tuple}C{(phi, lam)}).

1007 '''

1008 return PhiLam2Tuple(self.phi, self.lam, name=self.name)

1009

1010 def philam2(self, ndigits=0):

1011 '''Return this point's lat- and longitude in C{radians}, rounded.

1012

1013 @kwarg ndigits: Number of (decimal) digits (C{int}).

1014

1015 @return: A L{PhiLam2Tuple}C{(phi, lam)}, both C{float}

1016 and rounded away from zero.

1017

1018 @note: The C{round}ed values are always C{float}, also

1019 if B{C{ndigits}} is omitted.

1020 '''

1021 return PhiLam2Tuple(round(self.phi, ndigits),

1022 round(self.lam, ndigits), name=self.name)

1023

1024 @Property_RO

1025 def philamheight(self):

1026 '''Get the lat-, longitude in C{radians} and height (L{PhiLam3Tuple}C{(phi, lam, height)}).

1027 '''

1028 return self.philam.to3Tuple(self.height)

1029

1030 @deprecated_method

1031 def points(self, points, closed=True): # PYCHOK no cover

1032 '''DEPRECATED, use method L{points2}.'''

1033 return self.points2(points, closed=closed)

1034

1035 def points2(self, points, closed=True):

1036 '''Check a path or polygon represented by points.

1037

1038 @arg points: The path or polygon points (C{LatLon}[])

1039 @kwarg closed: Optionally, consider the polygon closed,

1040 ignoring any duplicate or closing final

1041 B{C{points}} (C{bool}).

1042

1043 @return: A L{Points2Tuple}C{(number, points)}, an C{int}

1044 and C{list} or C{tuple}.

1045

1046 @raise PointsError: Insufficient number of B{C{points}}.

1047

1048 @raise TypeError: Some B{C{points}} are not C{LatLon}.

1049 '''

1050 return _MODS.iters.points2(points, closed=closed, base=self)

1051

1052 def PointsIter(self, points, loop=0, dedup=False, wrap=False):

1053 '''Return a C{PointsIter} iterator.

1054

1055 @arg points: The path or polygon points (C{LatLon}[])

1056 @kwarg loop: Number of loop-back points (non-negative C{int}).

1057 @kwarg dedup: Skip duplicate points (C{bool}).

1058 @kwarg wrap: If C{True}, wrap or I{normalize} the

1059 enum-/iterated B{C{points}} (C{bool}).

1060

1061 @return: A new C{PointsIter} iterator.

1062

1063 @raise PointsError: Insufficient number of B{C{points}}.

1064 '''

1065 return PointsIter(points, base=self, loop=loop, dedup=dedup, wrap=wrap)

1066

1067 def radii11(self, point2, point3, wrap=False):

1068 '''Return the radii of the C{Circum-}, C{In-}, I{Soddy} and C{Tangent}

1069 circles of a (planar) triangle formed by this and two other points.

1070

1071 @arg point2: Second point (C{LatLon}).

1072 @arg point3: Third point (C{LatLon}).

1073 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{point2}} and

1074 B{C{point3}} (C{bool}).

1075

1076 @return: L{Radii11Tuple}C{(rA, rB, rC, cR, rIn, riS, roS, a, b, c, s)}.

1077

1078 @raise IntersectionError: Near-coincident or -colinear points.

1079

1080 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.

1081

1082 @see: Function L{pygeodesy.radii11}, U{Incircle

1083 <https://MathWorld.Wolfram.com/Incircle.html>}, U{Soddy Circles

1084 <https://MathWorld.Wolfram.com/SoddyCircles.html>} and U{Tangent

1085 Circles<https://MathWorld.Wolfram.com/TangentCircles.html>}.

1086 '''

1087 with _toCartesian3(self, point2, point3, wrap) as cs:

1088 return _radii11ABC(*cs, useZ=True)[0]

1089

1090 def _rhumb3(self, exact, radius): # != .sphericalBase._rhumbs3

1091 '''(INTERNAL) Get the C{rhumb} for this point's datum or for

1092 the B{C{radius}}' earth model iff non-C{None}.

1093 '''

1094 try:

1095 d = self._rhumb3dict

1096 t = d[(exact, radius)]

1097 except KeyError:

1098 D = self.datum if radius is None else _spherical_datum(radius) # ellipsoidal OK

1099 r = D.ellipsoid.rhumb_(exact=exact) # or D.isSpherical)

1100 t = r, D, _MODS.karney.Caps

1101 while d:

1102 d.popitem()

1103 d[(exact, radius)] = t # cache 3-tuple

1104 return t

1105

1106 @Property_RO

1107 def _rhumb3dict(self):

1108 return {} # single-item cache

1109

1110 def rhumbAzimuthTo(self, other, exact=False, radius=None, wrap=False):

1111 '''Return the azimuth (bearing) of a rhumb line (loxodrome)

1112 between this and an other (ellipsoidal) point.

1113

1114 @arg other: The other point (C{LatLon}).

1115 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),

1116 see method L{Ellipsoid.rhumb_}.

1117 @kwarg radius: Optional earth radius (C{meter}) or earth model

1118 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or

1119 L{a_f2Tuple}), overriding this point's datum.

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

1121 B{C{other}} point (C{bool}).

1122

1123 @return: Rhumb azimuth (compass C{degrees360}).

1124

1125 @raise TypeError: The B{C{other}} point is incompatible or

1126 B{C{radius}} is invalid.

1127 '''

1128 r, _, Cs = self._rhumb3(exact, radius)

1129 return r._Inverse(self, other, wrap, outmask=Cs.AZIMUTH).azi12

1130

1131 def rhumbDestination(self, distance, azimuth, exact=False, radius=None, height=None):

1132 '''Return the destination point having travelled the given distance

1133 from this point along a rhumb line (loxodrome) at the given azimuth.

1134

1135 @arg distance: Distance travelled (C{meter}, same units as this

1136 point's datum (ellipsoid) axes or B{C{radius}},

1137 may be negative.

1138 @arg azimuth: Azimuth (bearing) at this point (compass C{degrees}).

1139 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),

1140 see method L{Ellipsoid.rhumb_}.

1141 @kwarg radius: Optional earth radius (C{meter}) or earth model

1142 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or

1143 L{a_f2Tuple}), overriding this point's datum.

1144 @kwarg height: Optional height, overriding the default height

1145 (C{meter}).

1146

1147 @return: The destination point (ellipsoidal C{LatLon}).

1148

1149 @raise TypeError: Invalid B{C{radius}}.

1150

1151 @raise ValueError: Invalid B{C{distance}}, B{C{azimuth}},

1152 B{C{radius}} or B{C{height}}.

1153 '''

1154 r, D, _ = self._rhumb3(exact, radius)

1155 d = r._Direct(self, azimuth, distance)

1156 h = self._heigHt(height)

1157 return self.classof(d.lat2, d.lon2, datum=D, height=h)

1158

1159 def rhumbDistanceTo(self, other, exact=False, radius=None, wrap=False):

1160 '''Return the distance from this to an other point along

1161 a rhumb line (loxodrome).

1162

1163 @arg other: The other point (C{LatLon}).

1164 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),

1165 see method L{Ellipsoid.rhumb_}.

1166 @kwarg radius: Optional earth radius (C{meter}) or earth model

1167 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or

1168 L{a_f2Tuple}), overriding this point's datum.

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

1170 B{C{other}} point (C{bool}).

1171

1172 @return: Distance (C{meter}, the same units as this point's

1173 datum (ellipsoid) axes or B{C{radius}}.

1174

1175 @raise TypeError: The B{C{other}} point is incompatible or

1176 B{C{radius}} is invalid.

1177

1178 @raise ValueError: Invalid B{C{radius}}.

1179 '''

1180 r, _, Cs = self._rhumb3(exact, radius)

1181 return r._Inverse(self, other, wrap, outmask=Cs.DISTANCE).s12

1182

1183 def rhumbLine(self, azimuth_other, exact=False, radius=None, wrap=False,

1184 **name_caps):

1185 '''Get a rhumb line through this point at a given azimuth or

1186 through this and an other point.

1187

1188 @arg azimuth_other: The azimuth of the rhumb line (compass

1189 C{degrees}) or the other point (C{LatLon}).

1190 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),

1191 see method L{Ellipsoid.rhumb_}.

1192 @kwarg radius: Optional earth radius (C{meter}) or earth model

1193 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or

1194 L{a_f2Tuple}), overriding this point's datum.

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

1196 C{azimuth_B{other}} point (C{bool}).

1197 @kwarg name_caps: Optional C{B{name}=str} and C{caps}, see

1198 L{RhumbLine} C{B{caps}}.

1199

1200 @return: A C{RhumbLine} instance.

1201

1202 @raise TypeError: Invalid B{C{radius}} or BC{C{azimuth_other}}

1203 not a C{scalar} nor a C{LatLon}.

1204

1205 @see: Modules L{rhumbaux} and L{rhumbx}.

1206 '''

1207 r, _, _ = self._rhumb3(exact, radius)

1208 a, kwds = azimuth_other, _xkwds(name_caps, name=self.name)

1209 if isscalar(a):

1210 r = r._DirectLine(self, a, **kwds)

1211 elif isinstance(a, LatLonBase):

1212 r = r._InverseLine(self, a, wrap, **kwds)

1213 else:

1214 raise _TypeError(azimuth_other=a)

1215 return r

1216

1217 def rhumbMidpointTo(self, other, exact=False, radius=None,

1218 height=None, fraction=_0_5, wrap=False):

1219 '''Return the (loxodromic) midpoint on the rhumb line between

1220 this and an other point.

1221

1222 @arg other: The other point (C{LatLon}).

1223 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),

1224 see method L{Ellipsoid.rhumb_}.

1225 @kwarg radius: Optional earth radius (C{meter}) or earth model

1226 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or

1227 L{a_f2Tuple}), overriding this point's datum.

1228 @kwarg height: Optional height, overriding the mean height

1229 (C{meter}).

1230 @kwarg fraction: Midpoint location from this point (C{scalar}), 0

1231 for this, 1 for the B{C{other}}, 0.5 for halfway

1232 between this and the B{C{other}} point, may be

1233 negative or greater than 1.

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

1235 B{C{other}} point (C{bool}).

1236

1237 @return: The midpoint at the given B{C{fraction}} along the

1238 rhumb line (C{LatLon}).

1239

1240 @raise TypeError: The B{C{other}} point is incompatible or

1241 B{C{radius}} is invalid.

1242

1243 @raise ValueError: Invalid B{C{height}} or B{C{fraction}}.

1244 '''

1245 r, D, _ = self._rhumb3(exact, radius)

1246 f = Scalar(fraction=fraction)

1247 d = r._Inverse(self, other, wrap) # C.AZIMUTH_DISTANCE

1248 d = r._Direct( self, d.azi12, d.s12 * f)

1249 h = self._havg(other, f=f, h=height)

1250 return self.classof(d.lat2, d.lon2, datum=D, height=h)

1251

1252 def thomasTo(self, other, wrap=False):

1253 '''Compute the distance between this and an other point using

1254 U{Thomas'<https://apps.DTIC.mil/dtic/tr/fulltext/u2/703541.pdf>}

1255 formula.

1256

1257 @arg other: The other point (C{LatLon}).

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

1259 the B{C{other}} point (C{bool}).

1260

1261 @return: Distance (C{meter}, same units as the axes of

1262 this point's datum ellipsoid).

1263

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

1265

1266 @see: Function L{pygeodesy.thomas} and methods L{cosineAndoyerLambertTo},

1267 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},

1268 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},

1269 L{flatPolarTo}, L{haversineTo} and L{vincentysTo}.

1270 '''

1271 return self._distanceTo_(thomas_, other, wrap=wrap)

1272

1273 @deprecated_method

1274 def to2ab(self): # PYCHOK no cover

1275 '''DEPRECATED, use property L{philam}.'''

1276 return self.philam

1277

1278 def toCartesian(self, height=None, Cartesian=None, **Cartesian_kwds):

1279 '''Convert this point to cartesian, I{geocentric} coordinates,

1280 also known as I{Earth-Centered, Earth-Fixed} (ECEF).

1281

1282 @kwarg height: Optional height, overriding this point's height

1283 (C{meter}, conventionally).

1284 @kwarg Cartesian: Optional class to return the geocentric

1285 coordinates (C{Cartesian}) or C{None}.

1286 @kwarg Cartesian_kwds: Optional, additional B{C{Cartesian}}

1287 keyword arguments, ignored if

1288 C{B{Cartesian} is None}.

1289

1290 @return: A B{C{Cartesian}} or if B{C{Cartesian}} is C{None},

1291 an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M,

1292 datum)} with C{C=0} and C{M} if available.

1293

1294 @raise TypeError: Invalid B{C{Cartesian}} or B{C{Cartesian_kwds}}.

1295 '''

1296 r = self._ecef9 if height is None else self.toEcef(height=height)

1297 if Cartesian is not None: # class or .classof

1298 r = self._xnamed(Cartesian(r, **Cartesian_kwds))

1299 _xdatum(r.datum, self.datum)

1300 return r

1301

1302 def _toCartesianEcef(self, height=None, i=None, up=2, **name_point):

1303 '''(INTERNAL) Convert to cartesian and check Ecef's before and after.

1304 '''

1305 p = self.others(up=up, **name_point)

1306 c = p.toCartesian(height=height)

1307 E = self.Ecef

1308 if E:

1309 for p in (p, c):

1310 e = getattr(p, LatLonBase.Ecef.name, None)

1311 if e not in (None, E): # PYCHOK no cover

1312 n, _ = name_point.popitem()

1313 if i is not None:

1314 Fmt.SQUARE(n, i)

1315 raise _ValueError(n, e, txt=_incompatible(E.__name__))

1316 return c

1317

1318 def toDatum(self, datum2, height=None, name=NN):

1319 '''I{Must be overloaded}.'''

1320 notOverloaded(self, datum2, height=height, name=name)

1321

1322 def toEcef(self, height=None, M=False):

1323 '''Convert this point to I{geocentric} coordinates, also known as

1324 I{Earth-Centered, Earth-Fixed} (U{ECEF<https://WikiPedia.org/wiki/ECEF>}).

1325

1326 @kwarg height: Optional height, overriding this point's height

1327 (C{meter}, conventionally).

1328 @kwarg M: Optionally, include the rotation L{EcefMatrix} (C{bool}).

1329

1330 @return: An L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)}

1331 with C{C=0} and C{M} if available.

1332

1333 @raise EcefError: A C{.datum} or an ECEF issue.

1334 '''

1335 return self._ecef9 if height in (None, self.height) else \

1336 self._Ecef_forward(self.lat, self.lon, height=height, M=M)

1337

1338 @deprecated_method

1339 def to3llh(self, height=None): # PYCHOK no cover

1340 '''DEPRECATED, use property L{latlonheight} or C{latlon.to3Tuple(B{height})}.'''

1341 return self.latlonheight if height in (None, self.height) else \

1342 self.latlon.to3Tuple(height)

1343

1344 def toLocal(self, Xyz=None, ltp=None, **Xyz_kwds):

1345 '''Convert this I{geodetic} point to I{local} C{X}, C{Y} and C{Z}.

1346

1347 @kwarg Xyz: Optional class to return C{X}, C{Y} and C{Z}

1348 (L{XyzLocal}, L{Enu}, L{Ned}) or C{None}.

1349 @kwarg ltp: The I{local tangent plane} (LTP) to use,

1350 overriding this point's LTP (L{Ltp}).

1351 @kwarg Xyz_kwds: Optional, additional B{C{Xyz}} keyword

1352 arguments, ignored if C{B{Xyz} is None}.

1353

1354 @return: An B{C{Xyz}} instance or if C{B{Xyz} is None},

1355 a L{Local9Tuple}C{(x, y, z, lat, lon, height,

1356 ltp, ecef, M)} with C{M=None}, always.

1357

1358 @raise TypeError: Invalid B{C{ltp}}.

1359 '''

1360 p = _MODS.ltp._xLtp(ltp, self._ltp)

1361 return p._ecef2local(self._ecef9, Xyz, Xyz_kwds)

1362

1363 def toLtp(self, Ecef=None):

1364 '''Return the I{local tangent plane} (LTP) for this point.

1365

1366 @kwarg Ecef: Optional ECEF I{class} (L{EcefKarney}, ...

1367 L{EcefYou}), overriding this point's C{Ecef}.

1368 '''

1369 return self._ltp if Ecef in (None, self.Ecef) else _MODS.ltp.Ltp(

1370 self, ecef=Ecef(self.datum), name=self.name)

1371

1372 def toNormal(self, deep=False, name=NN):

1373 '''Get this point I{normalized} to C{abs(lat) <= 90}

1374 and C{abs(lon) <= 180}.

1375

1376 @kwarg deep: If C{True} make a deep, otherwise a

1377 shallow copy (C{bool}).

1378 @kwarg name: Optional name of the copy (C{str}).

1379

1380 @return: A copy of this point, I{normalized} and

1381 optionally renamed (C{LatLon}).

1382

1383 @see: Property L{isnormal}, method L{normal} and function

1384 L{pygeodesy.normal}.

1385 '''

1386 ll = self.copy(deep=deep)

1387 _ = ll.normal()

1388 if name:

1389 ll.rename(name)

1390 return ll

1391

1392 def toNvector(self, h=None, Nvector=None, **Nvector_kwds):

1393 '''Convert this point to C{n-vector} (normal to the earth's surface)

1394 components, I{including height}.

1395

1396 @kwarg h: Optional height, overriding this point's

1397 height (C{meter}).

1398 @kwarg Nvector: Optional class to return the C{n-vector}

1399 components (C{Nvector}) or C{None}.

1400 @kwarg Nvector_kwds_wrap: Optional, additional B{C{Nvector}}

1401 keyword arguments, ignored if C{B{Nvector}

1402 is None}.

1403

1404 @return: A B{C{Nvector}} or a L{Vector4Tuple}C{(x, y, z, h)}

1405 if B{C{Nvector}} is C{None}.

1406

1407 @raise TypeError: Invalid B{C{Nvector}} or B{C{Nvector_kwds}}.

1408 '''

1409 return self.toVector(Vector=Nvector, h=self.height if h is None else h,

1410 ll=self, **Nvector_kwds)

1411

1412 def toStr(self, form=F_DMS, joined=_COMMASPACE_, m=_m_, **prec_sep_s_D_M_S): # PYCHOK expected

1413 '''Convert this point to a "lat, lon[, +/-height]" string, formatted

1414 in the given C{B{form}at}.

1415

1416 @kwarg form: The lat-/longitude C{B{form}at} to use (C{str}), see

1417 functions L{pygeodesy.latDMS} or L{pygeodesy.lonDMS}.

1418 @kwarg joined: Separator to join the lat-, longitude and heigth

1419 strings (C{str} or C{None} or C{NN} for non-joined).

1420 @kwarg m: Optional unit of the height (C{str}), use C{None} to

1421 exclude height from the returned string.

1422 @kwarg prec_sep_s_D_M_S: Optional C{B{prec}ision}, C{B{sep}arator},

1423 B{C{s_D}}, B{C{s_M}}, B{C{s_S}} and B{C{s_DMS}} keyword

1424 arguments, see function L{pygeodesy.latDMS} or

1425 L{pygeodesy.lonDMS}.

1426

1427 @return: This point in the specified C{B{form}at}, etc. (C{str} or

1428 a 2- or 3-tuple C{(lat_str, lon_str[, height_str])} if

1429 C{B{joined}=NN} or C{B{joined}=None}).

1430

1431 @see: Function L{pygeodesy.latDMS} or L{pygeodesy.lonDMS} for more

1432 details about keyword arguments C{B{form}at}, C{B{prec}ision},

1433 C{B{sep}arator}, B{C{s_D}}, B{C{s_M}}, B{C{s_S}} and B{C{s_DMS}}.

1434

1435 @example:

1436

1437 >>> LatLon(51.4778, -0.0016).toStr() # 51°28′40″N, 000°00′06″W

1438 >>> LatLon(51.4778, -0.0016).toStr(F_D) # 51.4778°N, 000.0016°W

1439 >>> LatLon(51.4778, -0.0016, 42).toStr() # 51°28′40″N, 000°00′06″W, +42.00m

1440 '''

1441 t = (latDMS(self.lat, form=form, **prec_sep_s_D_M_S),

1442 lonDMS(self.lon, form=form, **prec_sep_s_D_M_S))

1443 if self.height and m is not None:

1444 t += (self.heightStr(m=m),)

1445 return joined.join(t) if joined else t

1446

1447 def toVector(self, Vector=None, **Vector_kwds):

1448 '''Convert this point to C{n-vector} (normal to the earth's

1449 surface) components, I{ignoring height}.

1450

1451 @kwarg Vector: Optional class to return the C{n-vector}

1452 components (L{Vector3d}) or C{None}.

1453 @kwarg Vector_kwds: Optional, additional B{C{Vector}}

1454 keyword arguments, ignored if

1455 C{B{Vector} is None}.

1456

1457 @return: A B{C{Vector}} or a L{Vector3Tuple}C{(x, y, z)}

1458 if B{C{Vector}} is C{None}.

1459

1460 @raise TypeError: Invalid B{C{Vector}} or B{C{kwds}}.

1461

1462 @note: These are C{n-vector} x, y and z components,

1463 I{NOT} geocentric (ECEF) x, y and z coordinates!

1464 '''

1465 r = self._vector3tuple

1466 if Vector is not None:

1467 r = Vector(*r, **_xkwds(Vector_kwds, name=self.name))

1468 return r

1469

1470 def toVector3d(self):

1471 '''Convert this point to C{n-vector} (normal to the earth's

1472 surface) components, I{ignoring height}.

1473

1474 @return: Unit vector (L{Vector3d}).

1475

1476 @note: These are C{n-vector} x, y and z components,

1477 I{NOT} geocentric (ECEF) x, y and z coordinates!

1478 '''

1479 return self._vector3d # XXX .unit()

1480

1481 def toWm(self, **toWm_kwds):

1482 '''Convert this point to a WM coordinate.

1483

1484 @kwarg toWm_kwds: Optional L{pygeodesy.toWm} keyword arguments.

1485

1486 @return: The WM coordinate (L{Wm}).

1487

1488 @see: Function L{pygeodesy.toWm}.

1489 '''

1490 return self._wm if not toWm_kwds else _MODS.webmercator.toWm(

1491 self, **_xkwds(toWm_kwds, name=self.name))

1492

1493 @deprecated_method

1494 def to3xyz(self): # PYCHOK no cover

1495 '''DEPRECATED, use property L{xyz} or method L{toNvector}, L{toVector},

1496 L{toVector3d} or perhaps (geocentric) L{toEcef}.'''

1497 return self.xyz # self.toVector()

1498

1499 @Property_RO

1500 def _vector3d(self):

1501 '''(INTERNAL) Cache for L{toVector3d}.

1502 '''

1503 return self.toVector(Vector=Vector3d) # XXX .unit()

1504

1505 @Property_RO

1506 def _vector3tuple(self):

1507 '''(INTERNAL) Cache for L{toVector}.

1508 '''

1509 return philam2n_xyz(self.phi, self.lam, name=self.name)

1510

1511 def vincentysTo(self, other, **radius_wrap):

1512 '''Compute the distance between this and an other point using

1513 U{Vincenty's<https://WikiPedia.org/wiki/Great-circle_distance>}

1514 spherical formula.

1515

1516 @arg other: The other point (C{LatLon}).

1517 @kwarg radius_wrap: Optional keyword arguments for function

1518 L{pygeodesy.vincentys}, overriding the

1519 default mean C{radius} of this point's

1520 datum ellipsoid.

1521

1522 @return: Distance (C{meter}, same units as B{C{radius}}).

1523

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

1525

1526 @see: Function L{pygeodesy.vincentys} and methods L{cosineAndoyerLambertTo},

1527 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},

1528 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},

1529 L{flatPolarTo}, L{haversineTo} and L{thomasTo}.

1530 '''

1531 return self._distanceTo(vincentys, other, **_xkwds(radius_wrap, radius=None))

1532

1533 @Property_RO

1534 def _wm(self):

1535 '''(INTERNAL) Get this point as webmercator (L{Wm}).

1536 '''

1537 return _MODS.webmercator.toWm(self)

1538

1539 @Property_RO

1540 def xyz(self):

1541 '''Get the C{n-vector} X, Y and Z components (L{Vector3Tuple}C{(x, y, z)})

1542

1543 @note: These are C{n-vector} x, y and z components, I{NOT}

1544 geocentric (ECEF) x, y and z coordinates!

1545 '''

1546 return self.toVector(Vector=Vector3Tuple)

1547

1548 @Property_RO

1549 def xyzh(self):

1550 '''Get the C{n-vector} X, Y, Z and H components (L{Vector4Tuple}C{(x, y, z, h)})

1551

1552 @note: These are C{n-vector} x, y and z components, I{NOT}

1553 geocentric (ECEF) x, y and z coordinates!

1554 '''

1555 return self.xyz.to4Tuple(self.height)

1556

1557

1558 class _toCartesian3(object): # see also .geodesicw._wargs, .vector2d._numpy

1559 '''(INTERNAL) Wrapper to convert 2 other points.

1560 '''

1561 @contextmanager # <https://www.python.org/dev/peps/pep-0343/> Examples

1562 def __call__(self, p, p2, p3, wrap, **kwds):

1563 try:

1564 if wrap:

1565 p2, p3 = map1(_Wrap.point, p2, p3)

1566 kwds = _xkwds(kwds, wrap=wrap)

1567 yield (p. toCartesian().copy(name=_point_), # copy to rename

1568 p._toCartesianEcef(up=4, point2=p2),

1569 p._toCartesianEcef(up=4, point3=p3))

1570 except (AssertionError, TypeError, ValueError) as x:

1571 raise _xError(x, point=p, point2=p2, point3=p3, **kwds)

1572

1573_toCartesian3 = _toCartesian3() # PYCHOK singleton

1574

1575

1576 def _trilaterate5(p1, d1, p2, d2, p3, d3, area=True, eps=EPS1, # MCCABE 13

1577 radius=R_M, wrap=False):

1578 '''(INTERNAL) Trilaterate three points by I{area overlap} or by

1579 I{perimeter intersection} of three circles.

1580

1581 @note: The B{C{radius}} is only needed for both the n-vectorial

1582 and C{sphericalTrigonometry.LatLon.distanceTo} methods and

1583 silently ignored by the C{ellipsoidalExact}, C{-GeodSolve},

1584 C{-Karney} and C{-Vincenty.LatLon.distanceTo} methods.

1585 '''

1586 p2, p3, w = _unrollon3(p1, p2, p3, wrap)

1587

1588 r1 = Distance_(distance1=d1)

1589 r2 = Distance_(distance2=d2)

1590 r3 = Distance_(distance3=d3)

1591 m = 0 if area else (r1 + r2 + r3)

1592 pc = 0

1593 t = []

1594 for _ in range(3):

1595 try: # intersection of circle (p1, r1) and (p2, r2)

1596 c1, c2 = p1.intersections2(r1, p2, r2, wrap=w)

1597

1598 if area: # check overlap

1599 if c1 is c2: # abutting

1600 c = c1

1601 else: # nearest point on radical

1602 c = p3.nearestOn(c1, c2, within=True, wrap=w)

1603 d = r3 - p3.distanceTo(c, radius=radius, wrap=w)

1604 if d > eps: # sufficient overlap

1605 t.append((d, c))

1606 m = max(m, d)

1607

1608 else: # check intersection

1609 for c in ((c1,) if c1 is c2 else (c1, c2)):

1610 d = fabs(r3 - p3.distanceTo(c, radius=radius, wrap=w))

1611 if d < eps: # below margin

1612 t.append((d, c))

1613 m = min(m, d)

1614

1615 except IntersectionError as x:

1616 if _concentric_ in str(x): # XXX ConcentricError?

1617 pc += 1

1618

1619 p1, r1, p2, r2, p3, r3 = p2, r2, p3, r3, p1, r1 # rotate

1620

1621 if t: # get min, max, points and count ...

1622 t = tuple(sorted(t))

1623 n = len(t), # as 1-tuple

1624 # ... or for a single trilaterated result,

1625 # min *is* max, min- *is* maxPoint and n=1, 2 or 3

1626 return Trilaterate5Tuple(t[0] + t[-1] + n) # *(t[0] + ...)

1627

1628 elif area and pc == 3: # all pairwise concentric ...

1629 r, p = min((r1, p1), (r2, p2), (r3, p3))

1630 m = max(r1, r2, r3)

1631 # ... return "smallest" point twice, the smallest

1632 # and largest distance and n=0 for concentric

1633 return Trilaterate5Tuple(float(r), p, float(m), p, 0)

1634

1635 n, f = (_overlap_, max) if area else (_intersection_, min)

1636 t = _COMMASPACE_(_no_(n), '%s %.3g' % (f.__name__, m))

1637 raise IntersectionError(area=area, eps=eps, wrap=wrap, txt=t)

1638

1639

1640__all__ += _ALL_DOCS(LatLonBase)

1641

1642# **) MIT License

1643#

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

1645#

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

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

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

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

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

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

1652#

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

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

1655#

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

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

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

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

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

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

1662# OTHER DEALINGS IN THE SOFTWARE.