1

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

3

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

5

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

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

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

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

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

11'''

12

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

14 from 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

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

19# from pygeodesy.ecef import EcefKarney # _MODS

20 from 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

32 from 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

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

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

39 from pygeodesy.named import _name2__, _NamedBase, Fmt

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

41 Trilaterate5Tuple

42# from pygeodesy.nvectorBase import _N_vector_ # _MODS

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

44 property_RO, property_ROnce, _update_all

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

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

47 Height, Radius, Radius_, Scalar, Scalar_

48 from 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

53 from contextlib import contextmanager

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

55

56__all__ = _ALL_LAZY.latlonBase

57__version__ = '24.10.19'

58

59_formy = _MODS.into(formy=__name__)

60

61

62 class 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 C{B{radius} is None}).

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

148 B{C{radius}} or C{degrees} if C{B{radius} is 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 lower-left

156 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_ROnce

479 def Ecef(self):

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

481 '''

482 return _MODS.ecef.EcefKarney

483

484 @Property_RO

485 def _Ecef_forward(self):

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

487 '''

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

489

490 @Property_RO

491 def _ecef9(self):

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

493 '''

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

495

496 @property_RO

497 def ellipsoidalLatLon(self):

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

499 '''

500 return False

501

502 @deprecated_method

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

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

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

506

507 @deprecated_method

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

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

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

511

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

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

514 using the U{Equirectangular Approximation / Projection

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

516

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

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

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

520

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

522 @kwarg radius_adjust_limit_wrap: Optional keyword arguments

523 for function L{pygeodesy.equirectangular},

524 overriding the default mean C{radius} of this

525 point's datum ellipsoid.

526

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

528

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

530

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

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

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

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

535 '''

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

537

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

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

540 an other point.

541

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

543

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

545 @kwarg radius_adjust_wrap: Optional keyword arguments for function

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

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

548

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

550

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

552

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

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

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

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

557 '''

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

559

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

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

562 U{ellipsoidal Earth to plane projection

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

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

565

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

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

568 radius} of this point's datum ellipsoid.

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

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

571

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

573

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

575

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

577

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

579 L{cosineAndoyerLambertTo}, L{cosineForsytheAndoyerLambertTo},

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

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

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

583 '''

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

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

586

587 hubenyTo = flatLocalTo # for Karl Hubeny

588

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

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

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

592 Geographical_distance#Polar_coordinate_flat-Earth_formula>} formula.

593

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

595 @kwarg radius_wrap: Optional keyword arguments for function

596 L{pygeodesy.flatPolar}, overriding the

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

598 datum ellipsoid.

599

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

601

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

603

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

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

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

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

608 '''

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

610

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

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

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

614

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

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

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

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

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

620 ellipsoid.

621

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

623 this C{pov}.

624

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

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

627 the ellipsoid.

628

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

630

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

632 '''

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

634

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

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

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

638 formula.

639

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

641 @kwarg radius_wrap: Optional keyword arguments for function

642 L{pygeodesy.haversine}, overriding the

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

644 datum ellipsoid.

645

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

647

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

649

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

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

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

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

654 '''

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

656

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

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

659

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

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

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

663

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

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

666 '''

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

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

669

670 @Property

671 def height(self):

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

673 '''

674 return self._height

675

676 @height.setter # PYCHOK setter!

677 def height(self, height):

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

679

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

681

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

683 '''

684 h = Height(height)

685 if self._height != h:

686 _update_all(self)

687 self._height = h

688

689 def _heigHt(self, height):

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

691 '''

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

693

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

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

696 this datum's ellipsoid surface.

697

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

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

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

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

702 @kwarg normal: If C{True}, the projection is the normal to this ellipsoid's

703 surface, otherwise the intersection of the I{radial} line to

704 this ellipsoid's center (C{bool}).

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

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

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

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

709

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

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

712

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

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

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

716

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

718

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

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

721

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

723 '''

724 c = self.toCartesian()

725 if LatLon is None:

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

727 else:

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

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

730 if r.datum != c.datum:

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

732 return r

733

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

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

736

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

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

739

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

741 '''

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

743

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

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

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

747

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

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

750 line and return the 2 intercant points accordingly.

751 '''

752 if height is None:

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

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

755 if h != hp:

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

757 if s: # fmath.fidw?

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

759 hq += s * Q.s12

760 hp += s * P.s12

761 else:

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

763 else:

764 hp = hq = Height(height)

765

766# n = self.name or unused.__name__

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

768 p._iteration = P.iteration

769 if P is not Q:

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

771 q._iteration = Q.iteration

772 return p, q

773

774 @deprecated_method

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

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

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

778

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

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

781 on diametrically opposite sides of the earth.

782

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

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

785

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

787 tolerance, C{False} otherwise.

788 '''

789 p = self.others(other)

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

791

792 @Property_RO

793 def isEllipsoidal(self):

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

795 '''

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

797

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

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

800

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

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

803

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

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

806

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

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

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

810

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

812

813 @see: Method L{isequalTo3}.

814 '''

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

816

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

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

819

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

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

822

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

824 height, C{False} otherwise.

825

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

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

828 C{class} or C{type}.

829

830 @see: Method L{isequalTo}.

831 '''

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

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

834

835 @Property_RO

836 def isnormal(self):

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

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

839

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

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

842 '''

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

844

845 @Property_RO

846 def isSpherical(self):

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

848 '''

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

850

851 @Property_RO

852 def lam(self):

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

854 '''

855 return radians(self.lon)

856

857 @Property

858 def lat(self):

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

860 '''

861 return self._lat

862

863 @lat.setter # PYCHOK setter!

864 def lat(self, lat):

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

866

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

868 '''

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

870 if self._lat != lat:

871 _update_all(self)

872 self._lat = lat

873

874 @Property

875 def latlon(self):

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

877 '''

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

879

880 @latlon.setter # PYCHOK setter!

881 def latlon(self, latlonh):

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

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

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

885

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

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

888

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

890

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

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

893 '''

894 if isstr(latlonh):

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

896 else:

897 _xinstanceof(list, tuple, latlonh=latlonh)

898 if len(latlonh) == 3:

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

900 elif len(latlonh) != 2:

901 raise _ValueError(latlonh=latlonh)

902 else:

903 h = self.height

904

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

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

907 _update_all(self)

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

909

910 def latlon2(self, ndigits=0):

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

912

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

914

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

916 and rounded away from zero.

917

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

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

920 '''

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

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

923

924 @deprecated_method

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

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

927 return self.latlon2(ndigits=ndigits)

928

929 latlon2round = latlon_ # PYCHOK no cover

930

931 @Property

932 def latlonheight(self):

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

934 '''

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

936

937 @latlonheight.setter # PYCHOK setter!

938 def latlonheight(self, latlonh):

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

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

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

942

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

944 '''

945 self.latlon = latlonh

946

947 @Property

948 def lon(self):

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

950 '''

951 return self._lon

952

953 @lon.setter # PYCHOK setter!

954 def lon(self, lon):

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

956

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

958 '''

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

960 if self._lon != lon:

961 _update_all(self)

962 self._lon = lon

963

964 @Property_RO

965 def _Ltp(self):

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

967 '''

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

969

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

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

972

973 Points are converted to and distances are computed in

974 I{geocentric}, cartesian space.

975

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

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

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

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

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

981 account for distances.

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

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

984

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

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

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

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

989 units as the cartesian axes.

990

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

992

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

994 C{Ecef} invalid.

995

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

997

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

999 '''

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

1001 p = None # not used

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

1003 if w and i:

1004 q = _unrollon(p, q)

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

1006 p = q

1007

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

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

1010

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

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

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

1014

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

1016 height=height)

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

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

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

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

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

1022

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

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

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

1026

1027 def normal(self):

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

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

1030

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

1032 wasn't (but is now).

1033

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

1035 '''

1036 n = self.isnormal

1037 if not n:

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

1039 return n

1040

1041 @property_RO

1042 def _N_vector(self):

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

1044 '''

1045 _N = _MODS.nvectorBase._N_vector_

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

1047

1048 @Property_RO

1049 def _n_xyz3(self):

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

1051 '''

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

1053

1054 @Property_RO

1055 def phi(self):

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

1057 '''

1058 return radians(self.lat)

1059

1060 @Property_RO

1061 def philam(self):

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

1063 '''

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

1065

1066 def philam2(self, ndigits=0):

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

1068

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

1070

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

1072 and rounded away from zero.

1073

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

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

1076 '''

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

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

1079

1080 @Property_RO

1081 def philamheight(self):

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

1083 '''

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

1085

1086 @deprecated_method

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

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

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

1090

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

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

1093

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

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

1096 ignoring any duplicate or closing final

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

1098

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

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

1101

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

1103

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

1105 '''

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

1107

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

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

1110

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

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

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

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

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

1116

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

1118

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

1120 '''

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

1122 dedup=dedup, wrap=wrap)

1123

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

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

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

1127

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

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

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

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

1132

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

1134

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

1136

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

1138

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

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

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

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

1143 '''

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

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

1146

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

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

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

1150 '''

1151 try:

1152 d = self._rhumb3dict

1153 t = d[(exact, radius)]

1154 except KeyError:

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

1156 _spherical_datum(radius) # ellipsoidal OK

1157 try:

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

1159 except AttributeError as x:

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

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

1162 if len(d) > 2:

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

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

1165 return t

1166

1167 @Property_RO

1168 def _rhumb3dict(self): # in ._update

1169 return {} # 3-item cache

1170

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

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

1173 and an other (ellipsoidal) point.

1174

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

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

1177 method L{Ellipsoid.rhumb_}.

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

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

1180 this point's datum.

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

1182 point (C{bool}).

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

1184 degrees (C{bool}).

1185

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

1187

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

1189 is invalid.

1190 '''

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

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

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

1194

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

1196 exact=False, **name):

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

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

1199

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

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

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

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

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

1205 this point's datum.

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

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

1208 method L{Ellipsoid.rhumb_}.

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

1210

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

1212

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

1214

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

1216 or B{C{height}}.

1217 '''

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

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

1220 h = self._heigHt(height)

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

1222

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

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

1225 (loxodrome).

1226

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

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

1229 method L{Ellipsoid.rhumb_}.

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

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

1232 this point's datum.

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

1234 point (C{bool}).

1235

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

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

1238

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

1240 is invalid.

1241

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

1243 '''

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

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

1246

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

1248 **exact_radius_wrap_eps_tol):

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

1250 points or as a point and azimuth.

1251

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

1253 or a point on the circle (same C{LatLon} class).

1254 @arg point: The start point of the rhumb line (same C{LatLon} class).

1255 @arg other: An other point I{on} (same C{LatLon} class) or the azimuth

1256 I{of} (compass C{degrees}) the rhumb line.

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

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

1259 @kwarg exact_radius_wrap_eps_tol: Optional keyword arguments, see

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

1261 or L{RhumbLine.Intersecant2}.

1262

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

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

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

1266

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

1268

1269 @raise TypeError: Invalid B{C{point}}, B{C{circle}} or B{C{other}}.

1270

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

1272 or B{C{exact_radius_wrap}}.

1273

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

1275 '''

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

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

1278

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

1280

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

1282 try:

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

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

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

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

1287

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

1289 self.rhumbIntersecant2)

1290 except (TypeError, ValueError) as x:

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

1292 **exact_radius_wrap_eps_tol)

1293

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

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

1296 this and an other point.

1297

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

1299 I{on} (same C{LatLon} class) the rhumb line.

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

1301 method L{Ellipsoid.rhumb_}.

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

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

1304 overriding this point's datum.

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

1306 point (C{bool}).

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

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

1309

1310 @return: A C{RhumbLine} instance.

1311

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

1313 same C{LatLon} class.

1314

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

1316 '''

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

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

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

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

1321 return rl

1322

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

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

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

1326 an other point.

1327

1328 @arg other: The other point (same C{LatLon} class).

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

1330 method L{Ellipsoid.rhumb_}.

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

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

1333 this point's datum.

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

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

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

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

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

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

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

1341

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

1343 (same C{LatLon} class).

1344

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

1346 is invalid.

1347

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

1349 '''

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

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

1352 f = Scalar(fraction=fraction)

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

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

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

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

1357

1358 @property_RO

1359 def sphericalLatLon(self):

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

1361 '''

1362 return False

1363

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

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

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

1367

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

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

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

1371

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

1373 ellipsoid).

1374

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

1376

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

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

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

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

1381 '''

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

1383

1384 @deprecated_method

1385 def to2ab(self): # PYCHOK no cover

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

1387 return self.philam

1388

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

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

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

1392

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

1394 (C{meter}, conventionally).

1395 @kwarg Cartesian: Optional class to return the geocentric

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

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

1398 arguments, ignored if C{B{Cartesian} is None}.

1399

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

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

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

1403

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

1405

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

1407 '''

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

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

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

1411 _xdatum(r.datum, self.datum)

1412 return r

1413

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

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

1416 '''

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

1418 c = p.toCartesian(height=height)

1419 E = self.Ecef

1420 if E:

1421 for p in (p, c):

1422 e = _xattr(p, Ecef=None)

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

1424 n, _ = _xkwds_item2(name_point)

1425 n = Fmt.INDEX(n, i)

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

1427 return c

1428

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

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

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

1432

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

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

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

1436

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

1438 (C{meter}, conventionally).

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

1440

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

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

1443

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

1445 '''

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

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

1448

1449 @deprecated_method

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

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

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

1453 self.latlon.to3Tuple(height)

1454

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

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

1457

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

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

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

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

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

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

1464

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

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

1467

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

1469 '''

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

1471

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

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

1474

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

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

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

1478 '''

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

1480

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

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

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

1484

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

1486 copy (C{bool}).

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

1488

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

1490 optionally renamed.

1491

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

1493 L{pygeodesy.normal}.

1494 '''

1495 ll = self.copy(deep=deep)

1496 _ = ll.normal()

1497 if name:

1498 ll.rename(name)

1499 return ll

1500

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

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

1503 components, I{including height}.

1504

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

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

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

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

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

1510 C{B{Nvector} is None}.

1511

1512 @return: An named B{C{Nvector}} or if C{B{Nvector} is None} a named

1513 L{Vector4Tuple}C{(x, y, z, h)}.

1514

1515 @raise TypeError: Invalid B{C{h}}, B{C{Nvector}} or B{C{name_Nvector_kwds}}.

1516

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

1518 '''

1519 h = self._heigHt(h)

1520 if Nvector is None:

1521 r = self._n_xyz3.to4Tuple(h)

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

1523 if n:

1524 r.rename(n)

1525 else:

1526 x, y, z = self._n_xyz3

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

1528 return r

1529

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

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

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

1533

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

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

1536 @kwarg joined: Separator to join the lat-, longitude and height

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

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

1539 exclude height from the returned string.

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

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

1542 arguments, see function L{pygeodesy.toDMS} for details.

1543

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

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

1546 B{C{joined}} is C{NN} or C{None}).

1547

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

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

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

1551 '''

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

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

1554 if self.height and m is not None:

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

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

1557

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

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

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

1561

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

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

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

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

1566

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

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

1569

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

1571

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

1573 '''

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

1575

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

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

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

1579

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

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

1582

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

1584

1585 @raise TypeError: Invalid B{C{Vector3d_kwds}}.

1586

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

1588 '''

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

1590 if norm:

1591 r = r.unit(ll=self)

1592 return r

1593

1594 def toWm(self, **toWm_kwds):

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

1596

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

1598

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

1600

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

1602 '''

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

1604

1605 @deprecated_method

1606 def to3xyz(self): # PYCHOK no cover

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

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

1609 return self.xyz # self.toVector()

1610

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

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

1613# '''

1614# if updated:

1615# self._rhumb3dict.clear()

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

1617

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

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

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

1621 spherical formula.

1622

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

1624 @kwarg radius_wrap: Optional keyword arguments for function

1625 L{pygeodesy.vincentys}, overriding the

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

1627 datum ellipsoid.

1628

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

1630

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

1632

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

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

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

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

1637 '''

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

1639

1640 def _wrap_name2(self, wrap=False, **name):

1641 '''(INTERNAL) Return the C{wrap} and C{name} value.

1642 '''

1643 return wrap, (self._name__(name) if name else NN)

1644

1645 @property_RO

1646 def xyz(self):

1647 '''Get the I{geocentric} C{(x, y, z)} coordinates (L{Vector3Tuple}C{(x, y, z)})

1648 '''

1649 return self._ecef9.xyz

1650

1651 @property_RO

1652 def xyz3(self):

1653 '''Get the I{geocentric} C{(x, y, z)} coordinates as C{3-tuple}.

1654 '''

1655 return tuple(self.xyz)

1656

1657 @Property_RO

1658 def xyzh(self):

1659 '''Get the I{geocentric} C{(x, y, z)} coordinates and height (L{Vector4Tuple}C{(x, y, z, h)})

1660 '''

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

1662

1663

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

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

1666 '''

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

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

1669 try:

1670 if wrap:

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

1672 kwds = _xkwds(kwds, wrap=wrap)

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

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

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

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

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

1678

1679_toCartesian3 = _toCartesian3() # PYCHOK singleton

1680

1681

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

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

1684 '''

1685 try:

1686 lat, lon = latlonh.lat, latlonh.lon

1687 height = _xattr(latlonh, height=height)

1688 except AttributeError:

1689 raise _IsnotError(_LatLon_, latlonh=latlonh)

1690 if wrap:

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

1692 return lat, lon, height

1693

1694

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

1696 radius=R_M, wrap=False):

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

1698 I{perimeter intersection} of three circles.

1699

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

1701 C{sphericalTrigonometry.LatLon.distanceTo} methods and

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

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

1704 '''

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

1706

1707 r1 = Distance_(distance1=d1)

1708 r2 = Distance_(distance2=d2)

1709 r3 = Distance_(distance3=d3)

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

1711 pc = 0

1712 t = []

1713 for _ in range(3):

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

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

1716

1717 if area: # check overlap

1718 if c1 is c2: # abutting

1719 c = c1

1720 else: # nearest point on radical

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

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

1723 if d > eps: # sufficient overlap

1724 t.append((d, c))

1725 m = max(m, d)

1726

1727 else: # check intersection

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

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

1730 if d < eps: # below margin

1731 t.append((d, c))

1732 m = min(m, d)

1733

1734 except IntersectionError as x:

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

1736 pc += 1

1737

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

1739

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

1741 t = tuple(sorted(t))

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

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

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

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

1746

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

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

1749 m = max(r1, r2, r3)

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

1751 # and largest distance and n=0 for concentric

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

1753

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

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

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

1757

1758

1759__all__ += _ALL_DOCS(LatLonBase)

1760

1761# **) MIT License

1762#

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

1764#

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

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

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

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

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

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

1771#

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

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

1774#

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

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

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

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

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

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

1781# OTHER DEALINGS IN THE SOFTWARE.