Coverage for pygeodesy/latlonBase.py: 94%

477 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2024-06-10 14:08 -0400

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 isstr, map1, _xinstanceof, _passarg 

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 

17from pygeodesy.datums import _spherical_datum 

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

19# from pygeodesy.ecef import EcefKarney # _MODS 

20from pygeodesy.errors import _AttributeError, IntersectionError, \ 

21 _incompatible, _IsnotError, _TypeError, \ 

22 _ValueError, _xattr, _xdatum, _xError, \ 

23 _xkwds, _xkwds_item2, _xkwds_not 

24# from pygeodesy.fmath import favg # _MODS 

25# from 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 # as _formy 

31# from pygeodesy.internals import _passarg # from .basics 

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

33 _intersection_, _LatLon_, _m_, _negative_, \ 

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

35# from pygeodesy.iters import PointsIter, points2 # _MODS 

36# from pygeodesy.karney import Caps # _MODS 

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

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

39from pygeodesy.named import _name2__, _NamedBase, Fmt 

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

41 Trilaterate5Tuple 

42# from pygeodesy.nvectorBase import _N_vector_ # _MODS 

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

44 property_RO, _update_all 

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

46from pygeodesy.units import _isDegrees, _isRadius, Distance_, Lat, Lon, \ 

47 Height, Radius, Radius_, Scalar, Scalar_ 

48from pygeodesy.utily import _unrollon, _unrollon3, _Wrap 

49# from pygeodesy.vector2d import _circin6, Circin6Tuple, _circum3, circum4_, \ 

50# Circum3Tuple, _radii11ABC # _MODS 

51# from pygeodesy.vector3d import nearestOn6, Vector3d # _MODS 

52 

53from contextlib import contextmanager 

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

55 

56__all__ = _ALL_LAZY.latlonBase 

57__version__ = '24.06.07' 

58 

59_formy = _MODS.into(formy=__name__) 

60 

61 

62class LatLonBase(_NamedBase): 

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

64 ellipsoidal earth models. 

65 ''' 

66 _clipid = INT0 # polygonal clip, see .booleans 

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

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

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

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

71 

72 def __init__(self, latlonh, lon=None, height=0, datum=None, **wrap_name): 

73 '''New C{LatLon}. 

74 

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

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

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

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

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

80 (C{meter}, conventionally). 

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

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

83 @kwarg wrap_name: Optional C{B{name}=NN} (C{str}) and optional keyword 

84 argument C{B{wrap}=False}, if C{True}, wrap or I{normalize} 

85 B{C{lat}} and B{C{lon}} (C{bool}). 

86 

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

88 

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

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

91 

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

93 

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

95 ''' 

96 w, n = self._wrap_name2(**wrap_name) 

97 if n: 

98 self.name = n 

99 

100 if lon is None: 

101 lat, lon, height = _latlonheight3(latlonh, height, w) 

102 elif w: 

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

104 else: 

105 lat = latlonh 

106 

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

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

109 if height: # elevation 

110 self._height = Height(height) 

111 if datum is not None: 

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

113 

114 def __eq__(self, other): 

115 return self.isequalTo(other) 

116 

117 def __ne__(self, other): 

118 return not self.isequalTo(other) 

119 

120 def __str__(self): 

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

122 

123 def antipode(self, height=None): 

124 '''Return the antipode, the point diametrically opposite to 

125 this point. 

126 

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

128 this point's height otherwise. 

129 

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

131 ''' 

132 a = _formy.antipode(*self.latlon) 

133 h = self._heigHt(height) 

134 return self.classof(*a, height=h) 

135 

136 @deprecated_method 

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

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

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

140 

141 def boundsOf(self, wide, tall, radius=R_M, height=None, **name): 

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

143 bounding box centered at this location. 

144 

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

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

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

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

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

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

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

152 overriding the point's height. 

153 @kwarg name: Optional C{B{name}=NN} (C{str}). 

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__(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 if C{None}, use 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, V3d=_MODS.vector3d.Vector3d): 

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

191 return V3d(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_name): 

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_name: Optional C{B{name}=NN} (C{str}) and optional keyword 

206 argument C{B{wrap}=False}, if C{True}, wrap or I{normalize} 

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

208 

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

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

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

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

213 

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

215 than version 1.10. 

216 

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

218 a trilateration or C{numpy} issue. 

219 

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

221 

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

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

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

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

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

227 height)} representing the differences between both results from 

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

229 

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

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

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

233 ''' 

234 w, n = self._wrap_name2(**wrap_name) 

235 

236 with _toCartesian3(self, point2, point3, w) as cs: 

237 m = _MODS.vector2d 

238 r, c, d, A, B, C = m._circin6(*cs, eps=eps, useZ=True, dLL3=True, 

239 datum=self.datum) # PYCHOK unpack 

240 return m.Circin6Tuple(r, c.toLatLon(), d, A.toLatLon(), 

241 B.toLatLon(), 

242 C.toLatLon(), name=n) 

243 

244 def circum3(self, point2, point3, circum=True, eps=EPS4, **wrap_name): 

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

246 this and two other points. 

247 

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

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

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

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

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

253 @kwarg wrap_name: Optional C{B{name}=NN} (C{str}) and optional keyword 

254 argument C{B{wrap}=False}, if C{True}, wrap or I{normalize} 

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

256 

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

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

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

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

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

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

263 

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

265 version 1.10. 

266 

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

268 incompatible C{Ecef} classes or a trilateration 

269 or C{numpy} issue. 

270 

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

272 

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

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

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

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

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

278 height)} representing the difference between both results from 

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

280 

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

282 ''' 

283 w, n = self._wrap_name2(**wrap_name) 

284 

285 with _toCartesian3(self, point2, point3, w, circum=circum) as cs: 

286 m = _MODS.vector2d 

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

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

289 return m.Circum3Tuple(r, c.toLatLon(), d, name=n) 

290 

291 def circum4_(self, *points, **wrap_name): 

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

293 

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

295 @kwarg wrap_name: Optional C{B{name}=NN} (C{str}) and optional keyword argument 

296 C{B{wrap}=False}, if C{True}, wrap or I{normalize} the B{C{points}} 

297 (C{bool}). 

298 

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

300 instance of this (sub-)class. 

301 

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

303 version 1.10. 

304 

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

306 

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

308 

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

310 

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

312 ''' 

313 w, n = self._wrap_name2(**wrap_name) 

314 

315 def _cs(ps, C, w): 

316 _wp = _Wrap.point if w else _passarg 

317 for i, p in enumerate(ps): 

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

319 

320 C = self._toCartesianEcef 

321 c = C(point=self) 

322 t = _MODS.vector2d.circum4_(c, Vector=c.classof, *_cs(points, C, w)) 

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

324 return t.dup(center=c, name=n) 

325 

326 @property 

327 def clipid(self): 

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

329 ''' 

330 return self._clipid 

331 

332 @clipid.setter # PYCHOK setter! 

333 def clipid(self, clipid): 

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

335 ''' 

336 self._clipid = int(clipid) 

337 

338 @deprecated_method 

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

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

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

342 

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

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

345 this and an other point. 

346 

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

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

349 larger distances. 

350 

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

352 @kwarg adjust_wrap: Optional keyword arguments for function 

353 L{pygeodesy.compassAngle}. 

354 

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

356 

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

358 

359 @note: Courtesy of Martin Schultz. 

360 

361 @see: U{Local, flat earth approximation 

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

363 ''' 

364 p = self.others(other) 

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

366 

367 def cosineAndoyerLambertTo(self, other, **wrap): 

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

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

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

371 

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

373 @kwarg wrap: Optional keyword argument C{B{wrap}=False}, if C{True}, wrap 

374 or I{normalize} and unroll the B{C{other}} point (C{bool}). 

375 

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

377 ellipsoid). 

378 

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

380 

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

382 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, 

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

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

385 L{thomasTo} and L{vincentysTo}. 

386 ''' 

387 return self._distanceTo_(_formy.cosineAndoyerLambert_, other, **wrap) 

388 

389 def cosineForsytheAndoyerLambertTo(self, other, **wrap): 

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

391 the U{Forsythe-Andoyer-Lambert correction 

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

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

394 formula. 

395 

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

397 @kwarg wrap: Optional keyword argument C{B{wrap}=False}, if C{True}, wrap 

398 or I{normalize} and unroll the B{C{other}} point (C{bool}). 

399 

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

401 ellipsoid). 

402 

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

404 

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

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

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

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

409 ''' 

410 return self._distanceTo_(_formy.cosineForsytheAndoyerLambert_, other, **wrap) 

411 

412 def cosineLawTo(self, other, radius=None, **wrap): 

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

414 U{spherical Law of Cosines 

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

416 formula. 

417 

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

419 @kwarg radius: Mean earth radius (C{meter}) or C{None} for the mean radius 

420 of this point's datum ellipsoid. 

421 @kwarg wrap: Optional keyword argument C{B{wrap}=False}, if C{True}, wrap 

422 or I{normalize} and unroll the B{C{other}} point (C{bool}). 

423 

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

425 

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

427 

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

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

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

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

432 ''' 

433 return self._distanceTo(_formy.cosineLaw, other, radius, **wrap) 

434 

435 @property_RO 

436 def datum(self): # PYCHOK no cover 

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

438 self._notOverloaded() 

439 

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

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

442 

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

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

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

446 or C{None}. 

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

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

449 

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

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

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

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

454 is un-/specified. 

455 

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

457 ''' 

458 t = self._Ltp._local2ecef(delta, nine=True) 

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

460 

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

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

463 ''' 

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

465 if r is None: 

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

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

468 

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

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

471 ''' 

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

473 D = self.datum 

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

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

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

477 

478 @property_RO 

479 def Ecef(self): 

480 '''Get the ECEF I{class} (L{EcefKarney}), I{once}. 

481 ''' 

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

483 return E 

484 

485 @Property_RO 

486 def _Ecef_forward(self): 

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

488 ''' 

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

490 

491 @Property_RO 

492 def _ecef9(self): 

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

494 ''' 

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

496 

497 @property_RO 

498 def ellipsoidalLatLon(self): 

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

500 ''' 

501 return False 

502 

503 @deprecated_method 

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

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

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

507 

508 @deprecated_method 

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

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

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

512 

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

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

515 using the U{Equirectangular Approximation / Projection 

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

517 

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

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

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

521 

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

523 @kwarg radius_adjust_limit_wrap: Optional keyword arguments 

524 for function L{pygeodesy.equirectangular}, 

525 overriding the default mean C{radius} of this 

526 point's datum ellipsoid. 

527 

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

529 

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

531 

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

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

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

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

536 ''' 

537 return self._distanceTo(_formy.equirectangular, other, **radius_adjust_limit_wrap) 

538 

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

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

541 an other point. 

542 

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

544 

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

546 @kwarg radius_adjust_wrap: Optional keyword arguments for function 

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

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

549 

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

551 

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

553 

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

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

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

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

558 ''' 

559 return self._distanceTo(_formy.euclidean, other, **radius_adjust_wrap) 

560 

561 def flatLocalTo(self, other, radius=None, **wrap): 

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

563 U{ellipsoidal Earth to plane projection 

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

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

566 

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

568 @kwarg radius: Mean earth radius (C{meter}) or C{None} for the I{equatorial 

569 radius} of this point's datum ellipsoid. 

570 @kwarg wrap: Optional keyword argument C{B{wrap}=False}, if C{True}, wrap 

571 or I{normalize} and unroll the B{C{other}} point (C{bool}). 

572 

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

574 

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

576 

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

578 

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

580 L{cosineAndoyerLambertTo}, L{cosineForsytheAndoyerLambertTo}, 

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

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

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

584 ''' 

585 r = radius if radius in (None, R_M, _1_0, 1) else Radius(radius) 

586 return self._distanceTo_(_formy.flatLocal_, other, radius=r, **wrap) # PYCHOK kwargs 

587 

588 hubenyTo = flatLocalTo # for Karl Hubeny 

589 

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

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

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

593 Geographical_distance#Polar_coordinate_flat-Earth_formula>} formula. 

594 

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

596 @kwarg radius_wrap: Optional keyword arguments for function 

597 L{pygeodesy.flatPolar}, overriding the 

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

599 datum ellipsoid. 

600 

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

602 

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

604 

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

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

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

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

609 ''' 

610 return self._distanceTo(_formy.flatPolar, other, **radius_wrap) 

611 

612 def hartzell(self, los=False, earth=None): 

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

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

615 

616 @kwarg los: Line-Of-Sight, I{direction} to the ellipsoid (L{Los}, L{Vector3d}), 

617 C{True} for the I{normal, plumb} onto the surface or I{False} or 

618 C{None} to point to the center of the ellipsoid. 

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

620 or C{scalar} radius in C{meter}), overriding this point's C{datum} 

621 ellipsoid. 

622 

623 @return: The intersection (C{LatLon}) with C{.height} set to the distance to 

624 this C{pov}. 

625 

626 @raise IntersectionError: Null or bad C{pov} or B{C{los}}, this C{pov} is inside 

627 the ellipsoid or B{C{los}} points outside or away from 

628 the ellipsoid. 

629 

630 @raise TypeError: Invalid B{C{los}} or invalid or undefined B{C{earth}} or C{datum}. 

631 

632 @see: Function L{hartzell<pygeodesy.formy.hartzell>} for further details. 

633 ''' 

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

635 

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

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

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

639 formula. 

640 

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

642 @kwarg radius_wrap: Optional keyword arguments for function 

643 L{pygeodesy.haversine}, overriding the 

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

645 datum ellipsoid. 

646 

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

648 

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

650 

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

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

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

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

655 ''' 

656 return self._distanceTo(_formy.haversine, other, **radius_wrap) 

657 

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

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

660 

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

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

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

664 

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

666 the overriding height B{C{h}} (C{Height}). 

667 ''' 

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

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

670 

671 @Property 

672 def height(self): 

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

674 ''' 

675 return self._height 

676 

677 @height.setter # PYCHOK setter! 

678 def height(self, height): 

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

680 

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

682 

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

684 ''' 

685 h = Height(height) 

686 if self._height != h: 

687 _update_all(self) 

688 self._height = h 

689 

690 def _heigHt(self, height): 

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

692 ''' 

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

694 

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

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

697 this datum's ellipsoid surface. 

698 

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

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

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

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

703 @kwarg normal: If C{True} the projection is the normal to this 

704 ellipsoid's surface, otherwise the intersection of the 

705 I{radial} line to this ellipsoid's center (C{bool}). 

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

707 datum (C{LatLon}) or C{None}. 

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

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

710 

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

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

713 

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

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

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

717 

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

719 

720 @raise TypeError: Invalid B{C{earth}} or triaxial B{C{earth}} couldn't be 

721 converted to biaxial B{C{LatLon}} datum. 

722 

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

724 ''' 

725 c = self.toCartesian() 

726 if LatLon is None: 

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

728 else: 

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

730 r = c.toLatLon(LatLon=LatLon, **_xkwds(LatLon_kwds, datum=c.datum, height=c.height)) 

731 if r.datum != c.datum: 

732 raise _TypeError(earth=earth, datum=r.datum) 

733 return r 

734 

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

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

737 

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

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

740 

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

742 ''' 

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

744 

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

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

747 self._notImplemented(*args, **kwds) 

748 

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

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

751 line and return the 2 intercant points accordingly. 

752 ''' 

753 if height is None: 

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

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

756 if h != hp: 

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

758 if s: # fmath.fidw? 

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

760 hq += s * Q.s12 

761 hp += s * P.s12 

762 else: 

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

764 else: 

765 hp = hq = Height(height) 

766 

767# n = self.name or unused.__name__ 

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

769 p._iteration = P.iteration 

770 if P is not Q: 

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

772 q._iteration = Q.iteration 

773 return p, q 

774 

775 @deprecated_method 

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

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

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

779 

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

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

782 on diametrically opposite sides of the earth. 

783 

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

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

786 

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

788 tolerance, C{False} otherwise. 

789 ''' 

790 p = self.others(other) 

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

792 

793 @Property_RO 

794 def isEllipsoidal(self): 

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

796 ''' 

797 return _xattr(self.datum, isEllipsoidal=None) 

798 

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

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

801 

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

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

804 

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

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

807 

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

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

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

811 

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

813 

814 @see: Method L{isequalTo3}. 

815 ''' 

816 return _formy._isequalTo(self, self.others(other), eps=eps) 

817 

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

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

820 

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

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

823 

824 @return: C{True} if both points are identical I{including} 

825 height, C{False} otherwise. 

826 

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

828 or mismatch of the B{C{other}} and this 

829 C{class} or C{type}. 

830 

831 @see: Method L{isequalTo}. 

832 ''' 

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

834 _formy._isequalTo(self, other, eps=eps) 

835 

836 @Property_RO 

837 def isnormal(self): 

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

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

840 

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

842 <pygeodesy.isnormal>} and L{normal<pygeodesy.normal>}. 

843 ''' 

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

845 

846 @Property_RO 

847 def isSpherical(self): 

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

849 ''' 

850 return _xattr(self.datum, isSpherical=None) 

851 

852 @Property_RO 

853 def lam(self): 

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

855 ''' 

856 return radians(self.lon) 

857 

858 @Property 

859 def lat(self): 

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

861 ''' 

862 return self._lat 

863 

864 @lat.setter # PYCHOK setter! 

865 def lat(self, lat): 

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

867 

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

869 ''' 

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

871 if self._lat != lat: 

872 _update_all(self) 

873 self._lat = lat 

874 

875 @Property 

876 def latlon(self): 

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

878 ''' 

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

880 

881 @latlon.setter # PYCHOK setter! 

882 def latlon(self, latlonh): 

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

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

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

886 

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

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

889 

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

891 

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

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

894 ''' 

895 if isstr(latlonh): 

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

897 else: 

898 _xinstanceof(list, tuple, latlonh=latlonh) 

899 if len(latlonh) == 3: 

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

901 elif len(latlonh) != 2: 

902 raise _ValueError(latlonh=latlonh) 

903 else: 

904 h = self.height 

905 

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

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

908 _update_all(self) 

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

910 

911 def latlon2(self, ndigits=0): 

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

913 

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

915 

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

917 and rounded away from zero. 

918 

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

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

921 ''' 

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

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

924 

925 @deprecated_method 

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

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

928 return self.latlon2(ndigits=ndigits) 

929 

930 latlon2round = latlon_ # PYCHOK no cover 

931 

932 @Property 

933 def latlonheight(self): 

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

935 ''' 

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

937 

938 @latlonheight.setter # PYCHOK setter! 

939 def latlonheight(self, latlonh): 

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

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

942 C{degrees90}, C{degrees180} and C{meter}). 

943 

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

945 ''' 

946 self.latlon = latlonh 

947 

948 @Property 

949 def lon(self): 

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

951 ''' 

952 return self._lon 

953 

954 @lon.setter # PYCHOK setter! 

955 def lon(self, lon): 

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

957 

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

959 ''' 

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

961 if self._lon != lon: 

962 _update_all(self) 

963 self._lon = lon 

964 

965 @Property_RO 

966 def _Ltp(self): 

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

968 ''' 

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

970 

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

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

973 

974 Points are converted to and distances are computed in 

975 I{geocentric}, cartesian space. 

976 

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

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

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

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

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

982 account for distances. 

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

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

985 

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

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

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

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

990 units as the cartesian axes. 

991 

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

993 

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

995 C{Ecef} invalid. 

996 

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

998 

999 @see: Function L{nearestOn6<pygeodesy.nearestOn6>}. 

1000 ''' 

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

1002 p = None # not used 

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

1004 if w and i: 

1005 q = _unrollon(p, q) 

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

1007 p = q 

1008 

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

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

1011 

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

1013 t = _MODS.vector3d.nearestOn6(c, _cs(Ps, height, wrap, C), closed=closed) 

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

1015 

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

1017 height=height) 

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

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

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

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

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

1023 

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

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

1026 self._notImplemented(*args, **kwds) 

1027 

1028 def normal(self): 

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

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

1031 

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

1033 wasn't (but is now). 

1034 

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

1036 ''' 

1037 n = self.isnormal 

1038 if not n: 

1039 self.latlon = _formy.normal(*self.latlon) 

1040 return n 

1041 

1042 @property_RO 

1043 def _N_vector(self): 

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

1045 ''' 

1046 _N = _MODS.nvectorBase._N_vector_ 

1047 return _N(*self._n_xyz3, h=self.height, name=self.name) 

1048 

1049 @Property_RO 

1050 def _n_xyz3(self): 

1051 '''(INTERNAL) Get the n-vector components as L{Vector3Tuple}. 

1052 ''' 

1053 return _formy.philam2n_xyz(self.phi, self.lam, name=self.name) 

1054 

1055 @Property_RO 

1056 def phi(self): 

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

1058 ''' 

1059 return radians(self.lat) 

1060 

1061 @Property_RO 

1062 def philam(self): 

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

1064 ''' 

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

1066 

1067 def philam2(self, ndigits=0): 

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

1069 

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

1071 

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

1073 and rounded away from zero. 

1074 

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

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

1077 ''' 

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

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

1080 

1081 @Property_RO 

1082 def philamheight(self): 

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

1084 ''' 

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

1086 

1087 @deprecated_method 

1088 def points(self, points, **closed): # PYCHOK no cover 

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

1090 return self.points2(points, **closed) 

1091 

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

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

1094 

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

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

1097 ignoring any duplicate or closing final 

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

1099 

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

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

1102 

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

1104 

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

1106 ''' 

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

1108 

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

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

1111 

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

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

1114 @kwarg dedup: If C{True}, skip duplicate points (C{bool}). 

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

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

1117 

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

1119 

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

1121 ''' 

1122 return _MODS.iters.PointsIter(points, base=self, loop=loop, 

1123 dedup=dedup, wrap=wrap) 

1124 

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

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

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

1128 

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

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

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

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

1133 

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

1135 

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

1137 

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

1139 

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

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

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

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

1144 ''' 

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

1146 return _MODS.vector2d._radii11ABC(*cs, useZ=True)[0] 

1147 

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

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

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

1151 ''' 

1152 try: 

1153 d = self._rhumb3dict 

1154 t = d[(exact, radius)] 

1155 except KeyError: 

1156 D = self.datum if radius is None else \ 

1157 _spherical_datum(radius) # ellipsoidal OK 

1158 try: 

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

1160 except AttributeError as x: 

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

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

1163 if len(d) > 2: 

1164 d.clear() # d[:] = {} 

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

1166 return t 

1167 

1168 @Property_RO 

1169 def _rhumb3dict(self): # in ._update 

1170 return {} # 3-item cache 

1171 

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

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

1174 and an other (ellipsoidal) point. 

1175 

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

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

1178 method L{Ellipsoid.rhumb_}. 

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

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

1181 this point's datum. 

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

1183 point (C{bool}). 

1184 @kwarg b360: If C{True}, return the azimuth as bearing in compass 

1185 degrees (C{bool}). 

1186 

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

1188 

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

1190 is invalid. 

1191 ''' 

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

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

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

1195 

1196 def rhumbDestination(self, distance, azimuth, radius=None, height=None, 

1197 exact=False, **name): 

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

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

1200 

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

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

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

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 height: Optional height, overriding the default height (C{meter}). 

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

1209 method L{Ellipsoid.rhumb_}. 

1210 @kwarg name: Optional C{B{name}=NN} (C{str}). 

1211 

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

1213 

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

1215 

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

1217 or B{C{height}}. 

1218 ''' 

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

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

1221 h = self._heigHt(height) 

1222 return self.classof(d.lat2, d.lon2, datum=D, height=h, **name) 

1223 

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

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

1226 (loxodrome). 

1227 

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

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

1230 method L{Ellipsoid.rhumb_}. 

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

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

1233 this point's datum. 

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

1235 point (C{bool}). 

1236 

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

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

1239 

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

1241 is invalid. 

1242 

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

1244 ''' 

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

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

1247 

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

1249 **exact_radius_wrap_eps_tol): 

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

1251 points or as a point and azimuth. 

1252 

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

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

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

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

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

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

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

1260 @kwarg exact_radius_wrap_eps_tol: Optional keyword arguments, see 

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

1262 or L{RhumbLine.Intersecant2}. 

1263 

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

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

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

1267 

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

1269 

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

1271 or B{C{other}} invalid. 

1272 

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

1274 or B{C{exact_radius_wrap}}. 

1275 

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

1277 ''' 

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

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

1280 

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

1282 

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

1284 try: 

1285 r = Radius_(circle=circle) if _isRadius(circle) else \ 

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

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

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

1289 

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

1291 self.rhumbIntersecant2) 

1292 except (TypeError, ValueError) as x: 

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

1294 **exact_radius_wrap_eps_tol) 

1295 

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

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

1298 this and an other point. 

1299 

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

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

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

1303 method L{Ellipsoid.rhumb_}. 

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

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

1306 overriding this point's datum. 

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

1308 point (C{bool}). 

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

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

1311 

1312 @return: A C{RhumbLine} instance. 

1313 

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

1315 this C{LatLon}. 

1316 

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

1318 ''' 

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

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

1321 rl = r._DirectLine( self, other, **kwds) if _isDegrees(other) else \ 

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

1323 return rl 

1324 

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

1326 height=None, fraction=_0_5, **wrap_name): 

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

1328 an other point. 

1329 

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

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

1332 method L{Ellipsoid.rhumb_}. 

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

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

1335 this point's datum. 

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

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

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

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

1340 @kwarg wrap_name: Optional C{B{name}=NN} (C{str}) and optional keyword 

1341 argument C{B{wrap}=False}, if C{True}, wrap or I{normalize} 

1342 and unroll the B{C{other}} point (C{bool}). 

1343 

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

1345 (this C{LatLon}). 

1346 

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

1348 is invalid. 

1349 

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

1351 ''' 

1352 w, n = self._wrap_name2(**wrap_name) 

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

1354 f = Scalar(fraction=fraction) 

1355 d = r._Inverse(self, self.others(other), w) # C.AZIMUTH_DISTANCE 

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

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

1358 return self.classof(d.lat2, d.lon2, datum=D, height=h, name=n) 

1359 

1360 @property_RO 

1361 def sphericalLatLon(self): 

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

1363 ''' 

1364 return False 

1365 

1366 def thomasTo(self, other, **wrap): 

1367 '''Compute the distance between this and an other point using U{Thomas' 

1368 <https://apps.DTIC.mil/dtic/tr/fulltext/u2/703541.pdf>} formula. 

1369 

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

1371 @kwarg wrap: Optional keyword argument C{B{wrap}=False}, if C{True}, wrap 

1372 or I{normalize} and unroll the B{C{other}} point (C{bool}). 

1373 

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

1375 ellipsoid). 

1376 

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

1378 

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

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

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

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

1383 ''' 

1384 return self._distanceTo_(_formy.thomas_, other, **wrap) 

1385 

1386 @deprecated_method 

1387 def to2ab(self): # PYCHOK no cover 

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

1389 return self.philam 

1390 

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

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

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

1394 

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

1396 (C{meter}, conventionally). 

1397 @kwarg Cartesian: Optional class to return the geocentric 

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

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

1400 keyword arguments, ignored if 

1401 C{B{Cartesian} is None}. 

1402 

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

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

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

1406 

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

1408 

1409 @see: Methods C{toNvector}, C{toVector} and C{toVector3d}. 

1410 ''' 

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

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

1413 r = Cartesian(r, **self._name1__(Cartesian_kwds)) 

1414 _xdatum(r.datum, self.datum) 

1415 return r 

1416 

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

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

1419 ''' 

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

1421 c = p.toCartesian(height=height) 

1422 E = self.Ecef 

1423 if E: 

1424 for p in (p, c): 

1425 e = _xattr(p, Ecef=None) 

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

1427 n, _ = _xkwds_item2(name_point) 

1428 n = Fmt.INDEX(n, i) 

1429 raise _ValueError(n, e, txt=_incompatible(E.__name__)) # txt__ 

1430 return c 

1431 

1432 def toDatum(self, datum2, height=None, **name): 

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

1434 self._notOverloaded(datum2, height=height, **name) 

1435 

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

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

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

1439 

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

1441 (C{meter}, conventionally). 

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

1443 

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

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

1446 

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

1448 ''' 

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

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

1451 

1452 @deprecated_method 

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

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

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

1456 self.latlon.to3Tuple(height) 

1457 

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

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

1460 

1461 @kwarg Xyz: Optional class to return C{X}, C{Y} and C{Z} (L{XyzLocal}, 

1462 L{Enu}, L{Ned}) or C{None}. 

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

1464 point's LTP (L{Ltp}). 

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

1466 ignored if C{B{Xyz} is None}. 

1467 

1468 @return: An B{C{Xyz}} instance or a L{Local9Tuple}C{(x, y, z, lat, lon, 

1469 height, ltp, ecef, M)} if C{B{Xyz} is None} (with C{M=None}). 

1470 

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

1472 ''' 

1473 return _MODS.ltp._toLocal(self, ltp, Xyz, Xyz_kwds) # self._ecef9 

1474 

1475 def toLtp(self, Ecef=None, **name): 

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

1477 

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

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

1480 @kwarg name: Optional C{B{name}=NN} (C{str}). 

1481 ''' 

1482 return _MODS.ltp._toLtp(self, Ecef, self, name) # self._Ltp 

1483 

1484 def toNormal(self, deep=False, **name): 

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

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

1487 

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

1489 shallow copy (C{bool}). 

1490 @kwarg name: Optional C{B{name}=NN} (C{str}). 

1491 

1492 @return: A copy of this point, I{normalized} (C{LatLon}), 

1493 optionally renamed. 

1494 

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

1496 L{pygeodesy.normal}. 

1497 ''' 

1498 ll = self.copy(deep=deep) 

1499 _ = ll.normal() 

1500 if name: 

1501 ll.rename(name) 

1502 return ll 

1503 

1504 def toNvector(self, h=None, Nvector=None, **name_Nvector_kwds): 

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

1506 components, I{including height}. 

1507 

1508 @kwarg h: Optional height, overriding this point's height (C{meter}). 

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

1510 (C{Nvector}) or C{None}. 

1511 @kwarg name_Nvector_kwds: Optional C{B{name}=NN} (C{str}) and optional, 

1512 additional B{C{Nvector}} keyword arguments, ignored if 

1513 C{B{Nvector} is None}. 

1514 

1515 @return: An B{C{Nvector}} or a L{Vector4Tuple}C{(x, y, z, h)} if 

1516 B{C{Nvector}} is C{None}. 

1517 

1518 @raise TypeError: Invalid B{C{h}}, B{C{Nvector}} or 

1519 B{C{name_Nvector_kwds}} item. 

1520 

1521 @see: Methods C{toCartesian}, C{toVector} and C{toVector3d}. 

1522 ''' 

1523 h = self._heigHt(h) 

1524 if Nvector is None: 

1525 r = self._n_xyz3.to4Tuple(h) 

1526 n, _ = _name2__(name_Nvector_kwds, _or_nameof=self) 

1527 if n: 

1528 r.rename(n) 

1529 else: 

1530 x, y, z = self._n_xyz3 

1531 r = Nvector(x, y, z, h=h, ll=self, **self._name1__(name_Nvector_kwds)) 

1532 return r 

1533 

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

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

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

1537 

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

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

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

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

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

1543 exclude height from the returned string. 

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

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

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

1547 L{pygeodesy.lonDMS}. 

1548 

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

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

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

1552 

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

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

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

1556 ''' 

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

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

1559 if self.height and m is not None: 

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

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

1562 

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

1564 '''Convert this point to a C{Vector} with the I{geocentric} C{(x, 

1565 y, z)} (ECEF) coordinates, I{ignoring height}. 

1566 

1567 @kwarg Vector: Optional class to return the I{geocentric} 

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

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

1570 arguments, ignored if C{B{Vector} is None}. 

1571 

1572 @return: A named B{C{Vector}} or if B{C{Vector}} is C{None} a 

1573 named L{Vector3Tuple}C{(x, y, z)}. 

1574 

1575 @raise TypeError: Invalid B{C{Vector}} or B{C{Vector_kwds}} item. 

1576 

1577 @see: Methods C{toCartesian}, C{toNvector} and C{toVector3d}. 

1578 ''' 

1579 return self._ecef9.toVector(Vector=Vector, **self._name1__(Vector_kwds)) 

1580 

1581 def toVector3d(self, norm=True, **Vector3d_kwds): 

1582 '''Convert this point to a L{Vector3d} with the I{geocentric} C{(x, y, 

1583 z)} (ECEF) coordinates, I{ignoring height}. 

1584 

1585 @kwarg norm: If C{False}, don't normalize the coordinates (C{bool}). 

1586 @kwarg Vector3d_kwds: Optional L{Vector3d} keyword arguments. 

1587 

1588 @return: Named, unit vector or vector (L{Vector3d}). 

1589 

1590 @raise TypeError: Invalid B{C{Vector3d_kwds}} item. 

1591 

1592 @see: Methods C{toCartesian}, C{toNvector} and C{toVector}. 

1593 ''' 

1594 r = self.toVector(Vector=_MODS.vector3d.Vector3d, **Vector3d_kwds) 

1595 if norm: 

1596 r = r.unit(ll=self) 

1597 return r 

1598 

1599 def toWm(self, **toWm_kwds): 

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

1601 

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

1603 

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

1605 

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

1607 ''' 

1608 return _MODS.webmercator.toWm(self, **self._name1__(toWm_kwds)) 

1609 

1610 @deprecated_method 

1611 def to3xyz(self): # PYCHOK no cover 

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

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

1614 return self.xyz # self.toVector() 

1615 

1616# def _update(self, updated, *attrs, **setters): 

1617# '''(INTERNAL) See C{_NamedBase._update}. 

1618# ''' 

1619# if updated: 

1620# self._rhumb3dict.clear() 

1621# return _NamedBase._update(self, updated, *attrs, **setters) 

1622 

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

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

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

1626 spherical formula. 

1627 

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

1629 @kwarg radius_wrap: Optional keyword arguments for function 

1630 L{pygeodesy.vincentys}, overriding the 

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

1632 datum ellipsoid. 

1633 

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

1635 

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

1637 

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

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

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

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

1642 ''' 

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

1644 

1645 def _wrap_name2(self, wrap=False, **name): 

1646 '''(INTERNAL) Return the C{wrap} and C{name} value. 

1647 ''' 

1648 return wrap, (self._name__(name) if name else NN) 

1649 

1650 @property_RO 

1651 def xyz(self): 

1652 '''Get the I{geocentric} C{(x, y, z)} coordinates (L{Vector3Tuple}C{(x, y, z)}) 

1653 ''' 

1654 return self._ecef9.xyz 

1655 

1656 @Property_RO 

1657 def xyzh(self): 

1658 '''Get the I{geocentric} C{(x, y, z)} coordinates and height (L{Vector4Tuple}C{(x, y, z, h)}) 

1659 ''' 

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

1661 

1662 

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

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

1665 ''' 

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

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

1668 try: 

1669 if wrap: 

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

1671 kwds = _xkwds(kwds, wrap=wrap) 

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

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

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

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

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

1677 

1678_toCartesian3 = _toCartesian3() # PYCHOK singleton 

1679 

1680 

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

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

1683 ''' 

1684 try: 

1685 lat, lon = latlonh.lat, latlonh.lon 

1686 height = _xattr(latlonh, height=height) 

1687 except AttributeError: 

1688 raise _IsnotError(_LatLon_, latlonh=latlonh) 

1689 if wrap: 

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

1691 return lat, lon, height 

1692 

1693 

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

1695 radius=R_M, wrap=False): 

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

1697 I{perimeter intersection} of three circles. 

1698 

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

1700 C{sphericalTrigonometry.LatLon.distanceTo} methods and 

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

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

1703 ''' 

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

1705 

1706 r1 = Distance_(distance1=d1) 

1707 r2 = Distance_(distance2=d2) 

1708 r3 = Distance_(distance3=d3) 

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

1710 pc = 0 

1711 t = [] 

1712 for _ in range(3): 

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

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

1715 

1716 if area: # check overlap 

1717 if c1 is c2: # abutting 

1718 c = c1 

1719 else: # nearest point on radical 

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

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

1722 if d > eps: # sufficient overlap 

1723 t.append((d, c)) 

1724 m = max(m, d) 

1725 

1726 else: # check intersection 

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

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

1729 if d < eps: # below margin 

1730 t.append((d, c)) 

1731 m = min(m, d) 

1732 

1733 except IntersectionError as x: 

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

1735 pc += 1 

1736 

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

1738 

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

1740 t = tuple(sorted(t)) 

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

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

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

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

1745 

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

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

1748 m = max(r1, r2, r3) 

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

1750 # and largest distance and n=0 for concentric 

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

1752 

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

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

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

1756 

1757 

1758__all__ += _ALL_DOCS(LatLonBase) 

1759 

1760# **) MIT License 

1761# 

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

1763# 

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

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

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

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

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

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

1770# 

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

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

1773# 

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

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

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

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

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

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

1780# OTHER DEALINGS IN THE SOFTWARE.