Coverage for pygeodesy/latlonBase.py: 92%

464 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-12-02 13:46 -0500

1 

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

3 

4u'''(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 

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

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

15 _EPSqrt as _TOL, _0_0, _0_5, _1_0, \ 

16 _360_0, _umod_360 

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

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

19# from pygeodesy.ecef import EcefKarney # _MODS 

20from pygeodesy.errors import _AttributeError, _incompatible, \ 

21 _IsnotError, IntersectionError, \ 

22 _ValueError, _xattr, _xdatum, \ 

23 _xError, _xkwds, _xkwds_not 

24# from pygeodesy.fmath import favg # _MODS 

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

26 cosineForsytheAndoyerLambert_, cosineLaw, \ 

27 equirectangular, euclidean, flatLocal_, \ 

28 flatPolar, _hartzell, haversine, isantipode, \ 

29 _isequalTo, isnormal, normal, philam2n_xyz, \ 

30 thomas_, vincentys, _spherical_datum 

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

32 _intersection_, _LatLon_, _m_, _negative_, \ 

33 _no_, _overlap_, _too_, _point_ # PYCHOK used! 

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

35# from pygeodesy.karney import Caps # _MODS 

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

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

38from pygeodesy.named import _NamedBase, notImplemented, notOverloaded, Fmt 

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

40 Trilaterate5Tuple, Vector3Tuple 

41# from pygeodesy.nvectorBase import _N_vector_ # _MODS 

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

43 property_RO, _update_all 

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

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

46 Scalar, Scalar_ 

47from pygeodesy.utily import _unrollon, _unrollon3, _Wrap 

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

49 Circum3Tuple, _radii11ABC 

50from pygeodesy.vector3d import nearestOn6, Vector3d, PointsIter 

51 

52from contextlib import contextmanager 

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

54 

55__all__ = _ALL_LAZY.latlonBase 

56__version__ = '23.12.02' 

57 

58 

59class LatLonBase(_NamedBase): 

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

61 ellipsoidal earth models. 

62 ''' 

63 _clipid = INT0 # polygonal clip, see .booleans 

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

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

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

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

68 

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

70 '''New C{LatLon}. 

71 

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

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

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

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

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

77 (C{meter}, conventionally). 

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

79 (C{bool}). 

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

81 @kwarg datum: Optional datum (L{Datum}, L{Ellipsoid}, L{Ellipsoid2}, 

82 L{a_f2Tuple} or I{scalar} radius) or C{None}. 

83 

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

85 

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

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

88 

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

90 

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

92 

93 @example: 

94 

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

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

97 >>> r = LatLon(p) 

98 ''' 

99 if name: 

100 self.name = name 

101 

102 if lon is None: 

103 lat, lon, height = _latlonheight3(latlonh, height, wrap) 

104 elif wrap: 

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

106 else: 

107 lat = latlonh 

108 

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

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

111 if height: # elevation 

112 self._height = Height(height) 

113 if datum: 

114 self._datum = _spherical_datum(datum, name=self.name) 

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

469 ''' 

470 LatLonBase.Ecef = E = _MODS.ecef.EcefKarney # overwrite property_RO 

471 return E 

472 

473 @Property_RO 

474 def _Ecef_forward(self): 

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

476 ''' 

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

478 

479 @Property_RO 

480 def _ecef9(self): 

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

482 ''' 

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

484 

485 @property_RO 

486 def ellipsoidalLatLon(self): 

487 '''Get the C{LatLon type} iff ellipsoidal, overloaded in L{LatLonEllipsoidalBase}. 

488 ''' 

489 return False 

490 

491 @deprecated_method 

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

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

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

495 

496 @deprecated_method 

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

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

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

500 

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

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

503 using the U{Equirectangular Approximation / Projection 

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

505 

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

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

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

509 

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

511 @kwarg radius_adjust_limit_wrap: Optional keyword arguments 

512 for function L{pygeodesy.equirectangular}, 

513 overriding the default mean C{radius} of this 

514 point's datum ellipsoid. 

515 

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

517 

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

519 

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

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

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

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

524 ''' 

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

526 

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

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

529 an other point. 

530 

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

532 

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

534 @kwarg radius_adjust_wrap: Optional keyword arguments for function 

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

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

537 

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

539 

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

541 

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

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

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

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

546 ''' 

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

548 

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

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

551 U{ellipsoidal Earth to plane projection 

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

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

554 

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

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

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

558 datum ellipsoid. 

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

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

561 

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

563 

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

565 

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

567 

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

569 L{cosineAndoyerLambertTo}, L{cosineForsytheAndoyerLambertTo}, 

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

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

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

573 ''' 

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

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

576 

577 hubenyTo = flatLocalTo # for Karl Hubeny 

578 

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

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

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

582 Geographical_distance#Polar_coordinate_flat-Earth_formula>} formula. 

583 

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

585 @kwarg radius_wrap: Optional keyword arguments for function 

586 L{pygeodesy.flatPolar}, overriding the 

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

588 datum ellipsoid. 

589 

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

591 

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

593 

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

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

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

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

598 ''' 

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

600 

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

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

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

604 

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

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

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

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

609 this point's C{datum} ellipsoid. 

610 

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

612 to the distance to this C{pov}. 

613 

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

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

616 outside or away from the ellipsoid. 

617 

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

619 

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

621 ''' 

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

623 

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

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

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

627 formula. 

628 

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

630 @kwarg radius_wrap: Optional keyword arguments for function 

631 L{pygeodesy.haversine}, overriding the 

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

633 datum ellipsoid. 

634 

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

636 

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

638 

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

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

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

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

643 ''' 

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

645 

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

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

648 

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

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

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

652 

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

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

655 ''' 

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

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

658 

659 @Property 

660 def height(self): 

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

662 ''' 

663 return self._height 

664 

665 @height.setter # PYCHOK setter! 

666 def height(self, height): 

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

668 

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

670 

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

672 ''' 

673 h = Height(height) 

674 if self._height != h: 

675 _update_all(self) 

676 self._height = h 

677 

678 def _heigHt(self, height): 

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

680 ''' 

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

682 

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

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

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

686 

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

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

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

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

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

692 ellipsoid's surface, otherwise the intersection of the 

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

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

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

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

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

698 

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

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

701 

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

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

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

705 

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

707 

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

709 

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

711 ''' 

712 c = self.toCartesian() 

713 if LatLon is None: 

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

715 else: 

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

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

718 return r 

719 

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

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

722 

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

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

725 

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

727 ''' 

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

729 

730 def intersecant2(self, *args, **kwds): # PYCHOK no cover 

731 '''B{Not implemented}, throws a C{NotImplementedError} always.''' 

732 notImplemented(self, *args, **kwds) 

733 

734 def _intersecend2(self, p, q, wrap, height, g_or_r, P, Q, unused): # in .LatLonEllipsoidalBaseDI.intersecant2 

735 '''(INTERNAL) Interpolate 2 heights along a geodesic or rhumb 

736 line and return the 2 intercant points accordingly. 

737 ''' 

738 if height is None: 

739 hp = hq = _xattr(p, height=INT0) 

740 h = _xattr(q, height=hp) # if isLatLon(q) else hp 

741 if h != hp: 

742 s = g_or_r._Inverse(p, q, wrap).s12 

743 if s: # fmath.fidw? 

744 s = (h - hp) / s # slope 

745 hq += s * Q.s12 

746 hp += s * P.s12 

747 else: 

748 hp = hq = _MODS.fmath.favg(hp, h) 

749 else: 

750 hp = hq = Height(height) 

751 

752# n = self.name or unused.__name__ 

753 p = q = self.classof(P.lat2, P.lon2, datum=g_or_r.datum, height=hp) # name=n 

754 p._iteration = P.iteration 

755 if P is not Q: 

756 q = self.classof(Q.lat2, Q.lon2, datum=g_or_r.datum, height=hq) # name=n 

757 q._iteration = Q.iteration 

758 return p, q 

759 

760 @deprecated_method 

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

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

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

764 

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

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

767 on diametrically opposite sides of the earth. 

768 

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

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

771 

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

773 tolerance, C{False} otherwise. 

774 ''' 

775 p = self.others(other) 

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

777 

778 @Property_RO 

779 def isEllipsoidal(self): 

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

781 ''' 

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

783 

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

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

786 

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

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

789 

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

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

792 

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

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

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

796 

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

798 

799 @see: Method L{isequalTo3}. 

800 ''' 

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

802 

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

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

805 

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

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

808 

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

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

811 

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

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

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

815 

816 @see: Method L{isequalTo}. 

817 ''' 

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

819 _isequalTo(self, other, eps=eps) 

820 

821 @Property_RO 

822 def isnormal(self): 

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

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

825 

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

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

828 ''' 

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

830 

831 @Property_RO 

832 def isSpherical(self): 

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

834 ''' 

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

836 

837 @Property_RO 

838 def lam(self): 

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

840 ''' 

841 return radians(self.lon) 

842 

843 @Property 

844 def lat(self): 

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

846 ''' 

847 return self._lat 

848 

849 @lat.setter # PYCHOK setter! 

850 def lat(self, lat): 

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

852 

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

854 ''' 

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

856 if self._lat != lat: 

857 _update_all(self) 

858 self._lat = lat 

859 

860 @Property 

861 def latlon(self): 

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

863 ''' 

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

865 

866 @latlon.setter # PYCHOK setter! 

867 def latlon(self, latlonh): 

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

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

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

871 

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

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

874 

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

876 

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

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

879 ''' 

880 if isstr(latlonh): 

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

882 else: 

883 _xinstanceof(list, tuple, latlonh=latlonh) 

884 if len(latlonh) == 3: 

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

886 elif len(latlonh) != 2: 

887 raise _ValueError(latlonh=latlonh) 

888 else: 

889 h = self.height 

890 

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

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

893 _update_all(self) 

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

895 

896 def latlon2(self, ndigits=0): 

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

898 

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

900 

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

902 and rounded away from zero. 

903 

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

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

906 ''' 

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

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

909 

910 @deprecated_method 

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

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

913 return self.latlon2(ndigits=ndigits) 

914 

915 latlon2round = latlon_ # PYCHOK no cover 

916 

917 @Property 

918 def latlonheight(self): 

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

920 ''' 

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

922 

923 @latlonheight.setter # PYCHOK setter! 

924 def latlonheight(self, latlonh): 

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

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

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

928 

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

930 ''' 

931 self.latlon = latlonh 

932 

933 @Property 

934 def lon(self): 

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

936 ''' 

937 return self._lon 

938 

939 @lon.setter # PYCHOK setter! 

940 def lon(self, lon): 

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

942 

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

944 ''' 

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

946 if self._lon != lon: 

947 _update_all(self) 

948 self._lon = lon 

949 

950 @Property_RO 

951 def _ltp(self): 

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

953 ''' 

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

955 

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

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

958 

959 Points are converted to and distances are computed in 

960 I{geocentric}, cartesian space. 

961 

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

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

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

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

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

967 account for distances. 

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

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

970 

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

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

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

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

975 units as the cartesian axes. 

976 

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

978 

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

980 C{Ecef} invalid. 

981 

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

983 

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

985 ''' 

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

987 p = None # not used 

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

989 if w and i: 

990 q = _unrollon(p, q) 

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

992 p = q 

993 

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

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

996 

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

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

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

1000 

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

1002 height=height) 

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

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

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

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

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

1008 

1009 def nearestTo(self, *args, **kwds): # PYCHOK no cover 

1010 '''B{Not implemented}, throws a C{NotImplementedError} always.''' 

1011 notImplemented(self, *args, **kwds) 

1012 

1013 def normal(self): 

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

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

1016 

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

1018 wasn't (but is now). 

1019 

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

1021 ''' 

1022 n = self.isnormal 

1023 if not n: 

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

1025 return n 

1026 

1027 @Property_RO 

1028 def _N_vector(self): 

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

1030 ''' 

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

1032 

1033 @Property_RO 

1034 def phi(self): 

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

1036 ''' 

1037 return radians(self.lat) 

1038 

1039 @Property_RO 

1040 def philam(self): 

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

1042 ''' 

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

1044 

1045 def philam2(self, ndigits=0): 

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

1047 

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

1049 

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

1051 and rounded away from zero. 

1052 

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

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

1055 ''' 

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

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

1058 

1059 @Property_RO 

1060 def philamheight(self): 

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

1062 ''' 

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

1064 

1065 @deprecated_method 

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

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

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

1069 

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

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

1072 

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

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

1075 ignoring any duplicate or closing final 

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

1077 

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

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

1080 

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

1082 

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

1084 ''' 

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

1086 

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

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

1089 

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

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

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

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

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

1095 

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

1097 

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

1099 ''' 

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

1101 

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

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

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

1105 

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

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

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

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

1110 

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

1112 

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

1114 

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

1116 

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

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

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

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

1121 ''' 

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

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

1124 

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

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

1127 earth model iff non-C{None}. 

1128 ''' 

1129 try: 

1130 d = self._rhumb3dict 

1131 t = d[(exact, radius)] 

1132 except KeyError: 

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

1134 try: 

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

1136 except AttributeError as x: 

1137 raise _AttributeError(datum=D, radius=radius, cause=x) 

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

1139 while d: 

1140 d.popitem() 

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

1142 return t 

1143 

1144 @Property_RO 

1145 def _rhumb3dict(self): # in rhumbIntersecant2 below 

1146 return {} # single-item cache 

1147 

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

1149 '''Return the azimuth (bearing) of a rhumb line (loxodrome) between this 

1150 and an other (ellipsoidal) point. 

1151 

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

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

1154 method L{Ellipsoid.rhumb_}. 

1155 @kwarg radius: Optional earth radius (C{meter}) or earth model (L{Datum}, 

1156 L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}), overriding 

1157 this point's datum. 

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

1159 point (C{bool}). 

1160 @kwarg b360: If C{True}, return the azimuth in the bearing range. 

1161 

1162 @return: Rhumb azimuth (compass C{degrees180} or C{degrees360}). 

1163 

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

1165 is invalid. 

1166 ''' 

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

1168 z = r._Inverse(self, other, wrap, outmask=Cs.AZIMUTH).azi12 

1169 return _umod_360(z + _360_0) if b360 else z 

1170 

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

1172 '''Return the destination point having travelled the given distance from 

1173 this point along a rhumb line (loxodrome) of the given azimuth. 

1174 

1175 @arg distance: Distance travelled (C{meter}, same units as this point's 

1176 datum (ellipsoid) axes or B{C{radius}}, may be negative. 

1177 @arg azimuth: Azimuth (bearing) of the rhumb line (compass C{degrees}). 

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

1179 method L{Ellipsoid.rhumb_}. 

1180 @kwarg radius: Optional earth radius (C{meter}) or earth model (L{Datum}, 

1181 L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}), overriding 

1182 this point's datum. 

1183 @kwarg height: Optional height, overriding the default height (C{meter}). 

1184 

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

1186 

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

1188 

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

1190 or B{C{height}}. 

1191 ''' 

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

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

1194 h = self._heigHt(height) 

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

1196 

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

1198 '''Return the distance from this to an other point along a rhumb line 

1199 (loxodrome). 

1200 

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

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

1203 method L{Ellipsoid.rhumb_}. 

1204 @kwarg radius: Optional earth radius (C{meter}) or earth model (L{Datum}, 

1205 L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}), overriding 

1206 this point's datum. 

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

1208 point (C{bool}). 

1209 

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

1211 (ellipsoid) axes or B{C{radius}}. 

1212 

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

1214 is invalid. 

1215 

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

1217 ''' 

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

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

1220 

1221 def rhumbIntersecant2(self, circle, point, other, height=None, 

1222 **exact_radius_wrap_eps_tol): 

1223 '''Compute the intersections of a circle and a rhumb line given as two 

1224 points or as a point and azimuth. 

1225 

1226 @arg circle: Radius of the circle centered at this location (C{meter}), 

1227 or a point on the circle (this C{LatLon}). 

1228 @arg point: The start point of the rhumb line (this C{LatLon}). 

1229 @arg other: An other point I{on} (this C{LatLon}) or the azimuth I{of} 

1230 (compass C{degrees}) the rhumb line. 

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

1232 conventionally) or C{None} for interpolated heights. 

1233 @kwarg exact_radius_wrap_eps_tol: Optional keyword arguments, see 

1234 methods L{rhumbLine} and L{RhumbLineAux.Intersecant2} 

1235 or L{RhumbLine.Intersecant2}. 

1236 

1237 @return: 2-Tuple of the intersection points (representing a chord), 

1238 each an instance of this class. Both points are the same 

1239 instance if the rhumb line is tangent to the circle. 

1240 

1241 @raise IntersectionError: The circle and rhumb line do not intersect. 

1242 

1243 @raise TypeError: If B{C{point}} is not this C{LatLon} or B{C{circle}} 

1244 or B{C{other}} invalid. 

1245 

1246 @raise ValueError: Invalid B{C{circle}}, B{C{other}}, B{C{height}} 

1247 or B{C{exact_radius_wrap}}. 

1248 

1249 @see: Methods L{RhumbLineAux.Intersecant2} and L{RhumbLine.Intersecant2}. 

1250 ''' 

1251 def _kwds3(eps=EPS, tol=_TOL, wrap=False, **kwds): 

1252 return kwds, wrap, dict(eps=eps, tol=tol) 

1253 

1254 exact_radius, w, eps_tol = _kwds3(**exact_radius_wrap_eps_tol) 

1255 

1256 p = _unrollon(self, self.others(point=point), wrap=w) 

1257 try: 

1258 r = Radius_(circle=circle) if isscalar(circle) else \ 

1259 self.rhumbDistanceTo(self.others(circle=circle), wrap=w, **exact_radius) 

1260 rl = p.rhumbLine(other, wrap=w, **exact_radius) 

1261 P, Q = rl.Intersecant2(self.lat, self.lon, r, **eps_tol) 

1262 

1263 return self._intersecend2(p, other, w, height, rl.rhumb, P, Q, 

1264 self.rhumbIntersecant2) 

1265 

1266 except (TypeError, ValueError) as x: 

1267 raise _xError(x, center=self, circle=circle, point=point, other=other, 

1268 **exact_radius_wrap_eps_tol) 

1269 

1270 def rhumbLine(self, other, exact=False, radius=None, wrap=False, **name_caps): 

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

1272 this and an other point. 

1273 

1274 @arg other: The azimuth I{of} (compass C{degrees}) or an other point 

1275 I{on} (this C{LatLon}) the rhumb line. 

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

1277 method L{Ellipsoid.rhumb_}. 

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

1279 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}), 

1280 overriding this point's datum. 

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

1282 point (C{bool}). 

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

1284 or L{RhumbLineAux} C{B{caps}}. 

1285 

1286 @return: A C{RhumbLine} instance. 

1287 

1288 @raise TypeError: Invalid B{C{radius}} or B{C{other}} not C{scalar} nor 

1289 this C{LatLon}. 

1290 

1291 @see: Modules L{rhumb.aux_} and L{rhumb.ekx}. 

1292 ''' 

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

1294 kwds = _xkwds(name_caps, name=self.name, caps=Cs.LINE_OFF) 

1295 rl = r._DirectLine( self, other, **kwds) if isscalar(other) else \ 

1296 r._InverseLine(self, self.others(other), wrap, **kwds) 

1297 return rl 

1298 

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

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

1301 '''Return the (loxodromic) midpoint on the rhumb line between this and 

1302 an other point. 

1303 

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

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

1306 method L{Ellipsoid.rhumb_}. 

1307 @kwarg radius: Optional earth radius (C{meter}) or earth model (L{Datum}, 

1308 L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}), overriding 

1309 this point's datum. 

1310 @kwarg height: Optional height, overriding the mean height (C{meter}). 

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

1312 1 for the B{C{other}}, 0.5 for halfway between this and 

1313 the B{C{other}} point, may be negative or greater than 1. 

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

1315 point (C{bool}). 

1316 

1317 @return: The midpoint at the given B{C{fraction}} along the rhumb line 

1318 (this C{LatLon}). 

1319 

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

1321 is invalid. 

1322 

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

1324 ''' 

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

1326 f = Scalar(fraction=fraction) 

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

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

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

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

1331 

1332 @property_RO 

1333 def sphericalLatLon(self): 

1334 '''Get the C{LatLon type} iff spherical, overloaded in L{LatLonSphericalBase}. 

1335 ''' 

1336 return False 

1337 

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

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

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

1341 formula. 

1342 

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

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

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

1346 

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

1348 this point's datum ellipsoid). 

1349 

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

1351 

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

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

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

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

1356 ''' 

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

1358 

1359 @deprecated_method 

1360 def to2ab(self): # PYCHOK no cover 

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

1362 return self.philam 

1363 

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

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

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

1367 

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

1369 (C{meter}, conventionally). 

1370 @kwarg Cartesian: Optional class to return the geocentric 

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

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

1373 keyword arguments, ignored if 

1374 C{B{Cartesian} is None}. 

1375 

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

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

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

1379 

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

1381 ''' 

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

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

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

1385 _xdatum(r.datum, self.datum) 

1386 return r 

1387 

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

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

1390 ''' 

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

1392 c = p.toCartesian(height=height) 

1393 E = self.Ecef 

1394 if E: 

1395 for p in (p, c): 

1396 e = _xattr(p, Ecef=None) 

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

1398 n, _ = name_point.popitem() 

1399 if i is not None: 

1400 n = Fmt.SQUARE(n, i) 

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

1402 return c 

1403 

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

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

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

1407 

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

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

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

1411 

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

1413 (C{meter}, conventionally). 

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

1415 

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

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

1418 

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

1420 ''' 

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

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

1423 

1424 @deprecated_method 

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

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

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

1428 self.latlon.to3Tuple(height) 

1429 

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

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

1432 

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

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

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

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

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

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

1439 

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

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

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

1443 

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

1445 ''' 

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

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

1448 

1449 def toLtp(self, Ecef=None): 

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

1451 

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

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

1454 ''' 

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

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

1457 

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

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

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

1461 

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

1463 shallow copy (C{bool}). 

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

1465 

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

1467 optionally renamed (C{LatLon}). 

1468 

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

1470 L{pygeodesy.normal}. 

1471 ''' 

1472 ll = self.copy(deep=deep) 

1473 _ = ll.normal() 

1474 if name: 

1475 ll.rename(name) 

1476 return ll 

1477 

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

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

1480 components, I{including height}. 

1481 

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

1483 height (C{meter}). 

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

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

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

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

1488 is None}. 

1489 

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

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

1492 

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

1494 ''' 

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

1496 ll=self, **Nvector_kwds) 

1497 

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

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

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

1501 

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

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

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

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

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

1507 exclude height from the returned string. 

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

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

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

1511 L{pygeodesy.lonDMS}. 

1512 

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

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

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

1516 

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

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

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

1520 

1521 @example: 

1522 

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

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

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

1526 ''' 

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

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

1529 if self.height and m is not None: 

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

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

1532 

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

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

1535 surface) components, I{ignoring height}. 

1536 

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

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

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

1540 keyword arguments, ignored if 

1541 C{B{Vector} is None}. 

1542 

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

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

1545 

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

1547 

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

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

1550 ''' 

1551 r = self._vector3tuple 

1552 if Vector is not None: 

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

1554 return r 

1555 

1556 def toVector3d(self): 

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

1558 surface) components, I{ignoring height}. 

1559 

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

1561 

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

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

1564 ''' 

1565 return self._vector3d # XXX .unit() 

1566 

1567 def toWm(self, **toWm_kwds): 

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

1569 

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

1571 

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

1573 

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

1575 ''' 

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

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

1578 

1579 @deprecated_method 

1580 def to3xyz(self): # PYCHOK no cover 

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

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

1583 return self.xyz # self.toVector() 

1584 

1585 @Property_RO 

1586 def _vector3d(self): 

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

1588 ''' 

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

1590 

1591 @Property_RO 

1592 def _vector3tuple(self): 

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

1594 ''' 

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

1596 

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

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

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

1600 spherical formula. 

1601 

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

1603 @kwarg radius_wrap: Optional keyword arguments for function 

1604 L{pygeodesy.vincentys}, overriding the 

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

1606 datum ellipsoid. 

1607 

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

1609 

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

1611 

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

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

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

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

1616 ''' 

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

1618 

1619 @Property_RO 

1620 def _wm(self): 

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

1622 ''' 

1623 return _MODS.webmercator.toWm(self) 

1624 

1625 @Property_RO 

1626 def xyz(self): 

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

1628 

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

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

1631 ''' 

1632 return self.toVector(Vector=Vector3Tuple) 

1633 

1634 @Property_RO 

1635 def xyzh(self): 

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

1637 

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

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

1640 ''' 

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

1642 

1643 

1644class _toCartesian3(object): # see also .formy._idllmn6, .geodesicw._wargs, .vector2d._numpy 

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

1646 ''' 

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

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

1649 try: 

1650 if wrap: 

1651 p2, p3 = map1(_Wrap.point, p2, p3) 

1652 kwds = _xkwds(kwds, wrap=wrap) 

1653 yield (p. toCartesian().copy(name=_point_), # copy to rename 

1654 p._toCartesianEcef(up=4, point2=p2), 

1655 p._toCartesianEcef(up=4, point3=p3)) 

1656 except (AssertionError, TypeError, ValueError) as x: # Exception? 

1657 raise _xError(x, point=p, point2=p2, point3=p3, **kwds) 

1658 

1659_toCartesian3 = _toCartesian3() # PYCHOK singleton 

1660 

1661 

1662def _latlonheight3(latlonh, height, wrap): # in .points.LatLon_.__init__ 

1663 '''(INTERNAL) Get 3-tuple C{(lat, lon, height)}. 

1664 ''' 

1665 try: 

1666 lat, lon = latlonh.lat, latlonh.lon 

1667 height = _xattr(latlonh, height=height) 

1668 except AttributeError: 

1669 raise _IsnotError(_LatLon_, latlonh=latlonh) 

1670 if wrap: 

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

1672 return lat, lon, height 

1673 

1674 

1675def _trilaterate5(p1, d1, p2, d2, p3, d3, area=True, eps=EPS1, # MCCABE 13 

1676 radius=R_M, wrap=False): 

1677 '''(INTERNAL) Trilaterate three points by I{area overlap} or by 

1678 I{perimeter intersection} of three circles. 

1679 

1680 @note: The B{C{radius}} is only needed for both the n-vectorial 

1681 and C{sphericalTrigonometry.LatLon.distanceTo} methods and 

1682 silently ignored by the C{ellipsoidalExact}, C{-GeodSolve}, 

1683 C{-Karney} and C{-Vincenty.LatLon.distanceTo} methods. 

1684 ''' 

1685 p2, p3, w = _unrollon3(p1, p2, p3, wrap) 

1686 

1687 r1 = Distance_(distance1=d1) 

1688 r2 = Distance_(distance2=d2) 

1689 r3 = Distance_(distance3=d3) 

1690 m = 0 if area else (r1 + r2 + r3) 

1691 pc = 0 

1692 t = [] 

1693 for _ in range(3): 

1694 try: # intersection of circle (p1, r1) and (p2, r2) 

1695 c1, c2 = p1.intersections2(r1, p2, r2, wrap=w) 

1696 

1697 if area: # check overlap 

1698 if c1 is c2: # abutting 

1699 c = c1 

1700 else: # nearest point on radical 

1701 c = p3.nearestOn(c1, c2, within=True, wrap=w) 

1702 d = r3 - p3.distanceTo(c, radius=radius, wrap=w) 

1703 if d > eps: # sufficient overlap 

1704 t.append((d, c)) 

1705 m = max(m, d) 

1706 

1707 else: # check intersection 

1708 for c in ((c1,) if c1 is c2 else (c1, c2)): 

1709 d = fabs(r3 - p3.distanceTo(c, radius=radius, wrap=w)) 

1710 if d < eps: # below margin 

1711 t.append((d, c)) 

1712 m = min(m, d) 

1713 

1714 except IntersectionError as x: 

1715 if _concentric_ in str(x): # XXX ConcentricError? 

1716 pc += 1 

1717 

1718 p1, r1, p2, r2, p3, r3 = p2, r2, p3, r3, p1, r1 # rotate 

1719 

1720 if t: # get min, max, points and count ... 

1721 t = tuple(sorted(t)) 

1722 n = len(t), # as 1-tuple 

1723 # ... or for a single trilaterated result, 

1724 # min *is* max, min- *is* maxPoint and n=1, 2 or 3 

1725 return Trilaterate5Tuple(t[0] + t[-1] + n) # *(t[0] + ...) 

1726 

1727 elif area and pc == 3: # all pairwise concentric ... 

1728 r, p = min((r1, p1), (r2, p2), (r3, p3)) 

1729 m = max(r1, r2, r3) 

1730 # ... return "smallest" point twice, the smallest 

1731 # and largest distance and n=0 for concentric 

1732 return Trilaterate5Tuple(float(r), p, float(m), p, 0) 

1733 

1734 n, f = (_overlap_, max) if area else (_intersection_, min) 

1735 t = _COMMASPACE_(_no_(n), '%s %.3g' % (f.__name__, m)) 

1736 raise IntersectionError(area=area, eps=eps, wrap=wrap, txt=t) 

1737 

1738 

1739__all__ += _ALL_DOCS(LatLonBase) 

1740 

1741# **) MIT License 

1742# 

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

1744# 

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

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

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

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

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

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

1751# 

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

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

1754# 

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

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

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

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

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

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

1761# OTHER DEALINGS IN THE SOFTWARE.