1

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

3

4 u'''Named, I{Local Tangent Plane} (LTP) tuples.

5

6 Local coordinate classes L{XyzLocal}, L{Enu}, L{Ned} and L{Aer}

7 and local coordinate tuples L{Local9Tuple}, L{Xyz4Tuple}, L{Enu4Tuple},

8 L{Ned4Tuple}, L{Aer4Tuple}, L{ChLV9Tuple}, L{ChLVEN2Tuple},

9 L{ChLVYX2Tuple}, L{ChLVyx2Tuple} and L{Footprint5Tuple}.

10

11@see: References in module L{ltp}.

12'''

13

14# from pygeodesy.basics import issubclassof # _MODS

15 from pygeodesy.constants import _0_0, _1_0, _90_0, _N_90_0

16# from pygeodesy.dms import F_D, toDMS # _MODS

17 from pygeodesy.errors import _TypeError, _TypesError, _xattr, _xkwds, \

18 _xkwds_item2

19 from pygeodesy.fmath import hypot, hypot_

20 from pygeodesy.interns import NN, _4_, _azimuth_, _center_, _COMMASPACE_, \

21 _ecef_, _elevation_, _height_, _lat_, _lon_, \

22 _ltp_, _M_, _name_, _up_, _X_, _x_, _xyz_, \

23 _Y_, _y_, _z_

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

25 from pygeodesy.named import _name__, _name1__, _name2__, _NamedBase, \

26 _NamedTuple, _Pass, _xnamed

27 from pygeodesy.namedTuples import LatLon2Tuple, PhiLam2Tuple, Vector3Tuple

28 from pygeodesy.props import deprecated_method, deprecated_Property_RO, \

29 Property_RO, property_RO

30 from pygeodesy.streprs import Fmt, fstr, strs, _xzipairs

31 from pygeodesy.units import Bearing, Degrees, Degrees_, Height, _isDegrees, \

32 _isMeter, Lat, Lon, Meter, Meter_

33 from pygeodesy.utily import atan2d, atan2b, sincos2_, sincos2d_, cos, radians

34 from pygeodesy.vector3d import Vector3d

35

36# from math import cos, radians # from .utily

37

38__all__ = _ALL_LAZY.ltpTuples

39__version__ = '24.06.28'

40

41_aer_ = 'aer'

42_alt_ = 'alt'

43_down_ = 'down'

44_east_ = 'east'

45_enu_ = 'enu'

46_h__ = 'h_'

47_ltp = _MODS.into(ltp=__name__)

48_ned_ = 'ned'

49_north_ = 'north'

50_local_ = 'local'

51_roll_ = 'roll'

52_slantrange_ = 'slantrange'

53_tilt_ = 'tilt'

54_uvw_ = 'uvw'

55_yaw_ = 'yaw'

56

57

58 def _er2gr(e, r):

59 '''(INTERNAL) Elevation and slant range to ground range.

60 '''

61 c = cos(radians(e))

62 return Meter_(groundrange=r * c)

63

64

65 def _init(inst, abc, ltp, name):

66 '''(INTERNAL) Complete C{__init__}.

67 '''

68 if abc is None:

69 n = _name__(**name)

70 else:

71 n = abc._name__(name)

72 ltp = _xattr(abc, ltp=ltp)

73 if ltp:

74 inst._ltp = _ltp._xLtp(ltp)

75 if n:

76 inst.name = n

77

78

79 def _toStr2(inst, prec=None, fmt=Fmt.SQUARE, sep=_COMMASPACE_):

80 '''(INTERNAL) Get attribute name and value strings, joined and bracketed.

81 '''

82 a = inst._toStr # 'aer', 'enu', 'ned', 'xyz'

83 t = getattr(inst, a + _4_, ())[:len(a)] or getattr(inst, a)

84 t = strs(t, prec=3 if prec is None else prec)

85 if sep:

86 t = sep.join(t)

87 if fmt:

88 t = fmt(t)

89 return a, t

90

91

92 def _xyz2aer4(inst):

93 '''(INTERNAL) Convert C{(x, y, z}) to C{(A, E, R)}.

94 '''

95 x, y, z, _ = inst.xyz4

96 A = Bearing(azimuth=atan2b(x, y))

97 E = Degrees(elevation=atan2d(z, hypot(x, y)))

98 R = Meter(slantrange=hypot_(x, y, z))

99 return Aer4Tuple(A, E, R, inst.ltp, name=inst.name)

100

101

102 def _xyzLocal(*Types, **name_inst):

103 '''(INTERNAL) Get C{inst} or C{inst.xyzLocal}.

104 '''

105 n, inst = _xkwds_item2(name_inst)

106 if isinstance(inst, Types):

107 return None

108 try:

109 return inst.xyzLocal

110 except (AttributeError, TypeError):

111 raise _TypeError(n, inst, txt_not_=_local_)

112

113

114 class _AbcBase(_NamedBase):

115 '''(INTERNAL) Base class for classes C{Aer} and C{Ned}.

116 '''

117 _ltp = None # local tangent plane (C{Ltp}), origin

118

119 @Property_RO

120 def ltp(self):

121 '''Get the I{local tangent plane} (L{Ltp}).

122 '''

123 return self._ltp

124

125 def toAer(self, Aer=None, **name_Aer_kwds):

126 '''Get the I{local} I{Azimuth, Elevation, slant Range} (AER) components.

127

128 @kwarg Aer: Class to return AER (L{Aer}) or C{None}.

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

130 additional B{L{Aer}} keyword arguments, ignored if

131 C{B{Aer} is None}.

132

133 @return: AER as an L{Aer} instance or if C{B{Aer} is None}, an

134 L{Aer4Tuple}C{(azimuth, elevation, slantrange, ltp)}.

135

136 @raise TypeError: Invalid B{C{Aer}} or B{C{name_Aer_kwds}}.

137 '''

138 return self.xyz4._toXyz(Aer, name_Aer_kwds)

139

140 def toEnu(self, Enu=None, **name_Enu_kwds):

141 '''Get the I{local} I{East, North, Up} (ENU) components.

142

143 @kwarg Enu: Class to return ENU (L{Enu}) or C{None}.

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

145 additional B{L{Enu}} keyword arguments, ignored if

146 C{B{Enu} is None}.

147

148 @return: ENU as an L{Enu} instance or if C{B{Enu} is None}, an

149 L{Enu4Tuple}C{(east, north, up, ltp)}.

150

151 @raise TypeError: Invalid B{C{Enu}} or B{C{name_Enu_kwds}}.

152 '''

153 return self.xyz4._toXyz(Enu, name_Enu_kwds)

154

155 def toNed(self, Ned=None, **name_Ned_kwds):

156 '''Get the I{local} I{North, East, Down} (NED) components.

157

158 @kwarg Ned: Class to return NED (L{Ned}) or C{None}.

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

160 additional B{L{Ned}} keyword arguments, ignored if

161 C{B{Ned} is None}.

162

163 @return: NED as an L{Ned} instance or if C{B{Ned} is None}, an

164 L{Ned4Tuple}C{(north, east, down, ltp)}.

165

166 @raise TypeError: Invalid B{C{Ned}} or B{C{name_Ned_kwds}}.

167 '''

168 return self.xyz4._toXyz(Ned, name_Ned_kwds)

169

170 def toXyz(self, Xyz=None, **name_Xyz_kwds):

171 '''Get the local I{X, Y, Z} (XYZ) components.

172

173 @kwarg Xyz: Class to return XYZ (L{XyzLocal}, L{Enu}, L{Ned}, L{Aer})

174 or C{None}.

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

176 additional B{C{Xyz}} keyword arguments, ignored if

177 C{B{Xyz} is None}.

178

179 @return: XYZ as an B{C{Xyz}} instance or if C{B{Xyz} is None}, an

180 L{Xyz4Tuple}C{(x, y, z, ltp)}.

181

182 @raise TypeError: Invalid B{C{Xyz}} or B{C{name_Xyz_kwds}}.

183 '''

184 return self.xyz4._toXyz(Xyz, name_Xyz_kwds)

185

186 @Property_RO

187 def xyz(self):

188 '''Get the I{local} C{(X, Y, Z)} coordinates (L{Vector3Tuple}C{(x, y, z)}).

189 '''

190 return Vector3Tuple(self.x, self.y, self.z, name=self.name) # like Ecef9Tuple.xyz, Local6tuple.xyz

191

192 @property_RO

193 def xyz4(self): # PYCHOK no cover

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

195 self._notOverloaded()

196

197 @Property_RO

198 def xyzLocal(self):

199 '''Get this AER or NED as an L{XyzLocal}.

200 '''

201 return XyzLocal(self.xyz4, name=self.name)

202

203

204 class _Abc4Tuple(_NamedTuple):

205 '''(INTERNAL) Base class for C{Aer4Tuple}, C{Enu4Tuple},

206 C{Ned4Tuple} and C{Xyz4Tuple}.

207 '''

208 def _2Cls(self, Abc, Cls, Cls_kwds):

209 '''(INTERNAL) Convert 4-Tuple to C{Cls} instance.

210 '''

211 kwds = _name1__(Cls_kwds, _or_nameof=self)

212 _is = _MODS.basics.issubclassof

213 if Cls is None:

214 n, _ = _name2__(Cls_kwds)

215 r = self.copy(name=n) if n else self

216 elif _is(Cls, Abc):

217 r = Cls(*self, **kwds)

218 elif _is(Cls, Aer):

219 r = self.xyzLocal.toAer(**_xkwds(kwds, Aer=Cls))

220 elif _is(Cls, Enu): # PYCHOK no cover

221 r = self.xyzLocal.toEnu(**_xkwds(kwds, Enu=Cls))

222 elif _is(Cls, Ned):

223 r = self.xyzLocal.toNed(**_xkwds(kwds, Ned=Cls))

224 elif _is(Cls, XyzLocal): # PYCHOK no cover

225 r = self.xyzLocal.toXyz(**_xkwds(kwds, Xyz=Cls))

226 elif Cls is Local9Tuple: # PYCHOK no cover

227 r = self.xyzLocal.toLocal9Tuple(**kwds)

228 else: # PYCHOK no cover

229 n = Abc.__name__[:3]

230 raise _TypesError(n, Cls, Aer, Enu, Ned, XyzLocal)

231 return r

232

233 @property_RO

234 def xyzLocal(self): # PYCHOK no cover

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

236 self._notOverloaded()

237

238

239 class Aer(_AbcBase):

240 '''Local C{Azimuth-Elevation-Range} (AER) in a I{local tangent plane}.

241 '''

242 _azimuth = _0_0 # bearing from North (C{degrees360})

243 _elevation = _0_0 # tilt, pitch from horizon (C{degrees}).

244# _ltp = None # local tangent plane (C{Ltp}), origin

245 _slantrange = _0_0 # distance (C{Meter})

246 _toStr = _aer_

247

248 def __init__(self, azimuth_aer, elevation=0, slantrange=0, ltp=None, **name):

249 '''New L{Aer}.

250

251 @arg azimuth_aer: Scalar azimuth, bearing from North (compass C{degrees})

252 or a previous I{local} instance (L{Aer}, L{Aer4Tuple},

253 L{Enu}, L{Enu4Tuple}, L{Local9Tuple}, L{Ned},

254 L{Ned4Tuple}, L{XyzLocal} or L{Xyz4Tuple}).

255 @kwarg elevation: Scalar angle I{above} the horizon, I{above} B{C{ltp}}

256 (C{degrees}, horizon is 0, zenith +90 and nadir -90),

257 only used with scalar B{C{azimuth_aer}}.

258 @kwarg slantrange: Scalar distance (C{meter}), only used with scalar

259 B{C{azimuth_aer}}.

260 @kwarg ltp: The I{local tangent plane}, (geodetic) origin (L{Ltp},

261 L{LocalCartesian}).

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

263

264 @raise TypeError: Invalid B{C{azimuth_aer}} or B{C{ltp}}.

265

266 @raise UnitError: Invalid B{C{azimuth_aer}}, B{C{elevation}} or

267 or B{C{slantrange}}.

268 '''

269 if _isDegrees(azimuth_aer):

270 aer = None

271 t = (Bearing(azimuth=azimuth_aer),

272 Degrees_(elevation=elevation, low=_N_90_0, high=_90_0),

273 Meter_(slantrange=slantrange), ltp)

274 else: # PYCHOK no cover

275 p = _xyzLocal(Aer, Aer4Tuple, Ned, azimuth_aer=azimuth_aer)

276 aer = p.toAer() if p else azimuth_aer

277 t = aer.aer4

278 self._azimuth, self._elevation, self._slantrange, _ = t

279 _init(self, aer, ltp, name)

280

281 @Property_RO

282 def aer4(self):

283 '''Get the C{(azimuth, elevation, slantrange, ltp)} components (L{Aer4Tuple}).

284 '''

285 return Aer4Tuple(self.azimuth, self.elevation, self.slantrange, self.ltp, name=self.name)

286

287 @Property_RO

288 def azimuth(self):

289 '''Get the Azimuth, bearing from North (C{degrees360}).

290 '''

291 return self._azimuth

292

293 @Property_RO

294 def down(self):

295 '''Get the Down component (C{meter}).

296 '''

297 return self.xyzLocal.down

298

299 @Property_RO

300 def east(self):

301 '''Get the East component (C{meter}).

302 '''

303 return self.xyzLocal.east

304

305 @Property_RO

306 def elevation(self):

307 '''Get the Elevation, tilt above horizon (C{degrees90}).

308 '''

309 return self._elevation

310

311 @Property_RO

312 def groundrange(self):

313 '''Get the I{ground range}, distance (C{meter}).

314 '''

315 return _er2gr(self._elevation, self._slantrange)

316

317 @Property_RO

318 def north(self):

319 '''Get the North component (C{meter}).

320 '''

321 return self.xyzLocal.north

322

323 @Property_RO

324 def slantrange(self):

325 '''Get the I{slant Range}, distance (C{meter}).

326 '''

327 return self._slantrange

328

329 def toRepr(self, prec=None, fmt=Fmt.SQUARE, sep=_COMMASPACE_, **unused): # PYCHOK expected

330 '''Return a string representation of this AER as azimuth

331 (bearing), elevation and slant range.

332

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

334 @kwarg fmt: Enclosing backets format (C{str}).

335 @kwarg sep: Optional separator between AERs (C{str}).

336

337 @return: This AER as "[A:degrees360, E:degrees90, R:meter]" (C{str}).

338 '''

339 m = _MODS.dms

340 t = (m.toDMS(self.azimuth, form=m.F_D, prec=prec, ddd=0),

341 m.toDMS(self.elevation, form=m.F_D, prec=prec, ddd=0),

342 fstr( self.slantrange, prec=3 if prec is None else prec))

343 return _xzipairs(self._toStr.upper(), t, sep=sep, fmt=fmt)

344

345 def toStr(self, **prec_fmt_sep): # PYCHOK expected

346 '''Return a string representation of this AER.

347

348 @kwarg prec_fmt_sep: Keyword arguments C{B{prec}=3} for the

349 number of (decimal) digits, unstripped

350 (C{int}), C{B{fmt}='[]'} the enclosing

351 backets format (C{str}) and separator

352 C{B{sep}=", "} to join (C{str}).

353

354 @return: This AER as "[degrees360, degrees90, meter]" (C{str}).

355 '''

356 _, t = _toStr2(self, **prec_fmt_sep)

357 return t

358

359 @Property_RO

360 def up(self):

361 '''Get the Up component (C{meter}).

362 '''

363 return self.xyzLocal.up

364

365 @Property_RO

366 def x(self):

367 '''Get the X component (C{meter}).

368 '''

369 return self.xyz4.x

370

371 @Property_RO

372 def xyz4(self):

373 '''Get the C{(x, y, z, ltp)} components (L{Xyz4Tuple}).

374 '''

375 sA, cA, sE, cE = sincos2d_(self._azimuth, self._elevation)

376 R = self._slantrange

377 r = cE * R # ground range

378 return Xyz4Tuple(sA * r, cA * r, sE * R, self.ltp, name=self.name)

379

380 @Property_RO

381 def y(self):

382 '''Get the Y component (C{meter}).

383 '''

384 return self.xyz4.y

385

386 @Property_RO

387 def z(self):

388 '''Get the Z component (C{meter}).

389 '''

390 return self.xyz4.z

391

392

393 class Aer4Tuple(_Abc4Tuple):

394 '''4-Tuple C{(azimuth, elevation, slantrange, ltp)},

395 all in C{meter} except C{ltp}.

396 '''

397 _Names_ = (_azimuth_, _elevation_, _slantrange_, _ltp_)

398 _Units_ = ( Meter, Meter, Meter, _Pass)

399

400 def _toAer(self, Cls, Cls_kwds):

401 '''(INTERNAL) Return C{Cls(..., **Cls_kwds)} instance.

402 '''

403 return self._2Cls(Aer, Cls, Cls_kwds)

404

405 @Property_RO

406 def groundrange(self):

407 '''Get the I{ground range}, distance (C{meter}).

408 '''

409 return _er2gr(self.elevation, self.slantrange) # PYCHOK _Tuple

410

411 @Property_RO

412 def xyzLocal(self):

413 '''Get this L{Aer4Tuple} as an L{XyzLocal}.

414 '''

415 return Aer(self).xyzLocal

416

417

418 class Attitude4Tuple(_NamedTuple):

419 '''4-Tuple C{(alt, tilt, yaw, roll)} with C{altitude} in (positive)

420 C{meter} and C{tilt}, C{yaw} and C{roll} in C{degrees} representing

421 the attitude of a plane or camera.

422 '''

423 _Names_ = (_alt_, _tilt_, _yaw_, _roll_)

424 _Units_ = ( Meter, Bearing, Degrees, Degrees)

425

426 @Property_RO

427 def atyr(self):

428 '''Return this attitude (L{Attitude4Tuple}).

429 '''

430 return self

431

432 @Property_RO

433 def tyr3d(self):

434 '''Get this attitude's (3-D) directional vector (L{Vector3d}).

435 '''

436 return _ltp.Attitude(self).tyr3d

437

438

439 class Ned(_AbcBase):

440 '''Local C{North-Eeast-Down} (NED) location in a I{local tangent plane}.

441

442 @see: L{Enu} and L{Ltp}.

443 '''

444 _down = _0_0 # down, -XyzLocal.z (C{meter}).

445 _east = _0_0 # east, XyzLocal.y (C{meter}).

446# _ltp = None # local tangent plane (C{Ltp}), origin

447 _north = _0_0 # north, XyzLocal.x (C{meter})

448 _toStr = _ned_

449

450 def __init__(self, north_ned, east=0, down=0, ltp=None, **name):

451 '''New L{Ned} vector.

452

453 @arg north_ned: Scalar North component (C{meter}) or a previous

454 I{local} instance (L{Ned}, L{Ned4Tuple}, L{Aer},

455 L{Aer4Tuple}, L{Enu}, L{Enu4Tuple}, L{Local9Tuple},

456 L{XyzLocal} or L{Xyz4Tuple}).

457 @kwarg east: Scalar East component (C{meter}), only used with

458 scalar B{C{north_ned}}.

459 @kwarg down: Scalar Down component, normal to I{inside} surface

460 of the ellipsoid or sphere (C{meter}), only used with

461 scalar B{C{north_ned}}.

462 @kwarg ltp: The I{local tangent plane}, (geodetic) origin (L{Ltp},

463 L{LocalCartesian}).

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

465

466 @raise TypeError: Invalid B{C{north_ned}} or B{C{ltp}}.

467

468 @raise UnitError: Invalid B{C{north_ned}}, B{C{east}} or B{C{down}}.

469 '''

470 if _isMeter(north_ned):

471 ned = None

472 t = (Meter(north=north_ned or _0_0),

473 Meter(east=east or _0_0),

474 Meter(down=down or _0_0), ltp)

475 else: # PYCHOK no cover

476 p = _xyzLocal(Ned, Ned4Tuple, Aer, north_ned=north_ned)

477 ned = p.toNed() if p else north_ned

478 t = ned.ned4

479 self._north, self._east, self._down, _ = t

480 _init(self, ned, ltp, name)

481

482 @Property_RO

483 def aer4(self):

484 '''Get the C{(azimuth, elevation, slantrange, ltp)} components (L{Aer4Tuple}).

485 '''

486 return _xyz2aer4(self)

487

488 @Property_RO

489 def azimuth(self):

490 '''Get the Azimuth, bearing from North (C{degrees360}).

491 '''

492 return self.aer4.azimuth

493

494 @deprecated_Property_RO

495 def bearing(self):

496 '''DEPRECATED, use C{azimuth}.'''

497 return self.azimuth

498

499 @Property_RO

500 def down(self):

501 '''Get the Down component (C{meter}).

502 '''

503 return self._down

504

505 @Property_RO

506 def east(self):

507 '''Get the East component (C{meter}).

508 '''

509 return self._east

510

511 @Property_RO

512 def elevation(self):

513 '''Get the Elevation, tilt above horizon (C{degrees90}).

514 '''

515 return self.aer4.elevation # neg(degrees90(asin1(self.down / self.length))))

516

517 @Property_RO

518 def groundrange(self):

519 '''Get the I{ground range}, distance (C{meter}).

520 '''

521 return Meter(groundrange=hypot(self.north, self.east))

522

523 @deprecated_Property_RO

524 def length(self):

525 '''DEPRECATED, use C{slantrange}.'''

526 return self.slantrange

527

528 @deprecated_Property_RO

529 def ned(self):

530 '''DEPRECATED, use property C{ned4}.'''

531 return _MODS.deprecated.classes.Ned3Tuple(self.north, self.east, self.down, name=self.name)

532

533 @Property_RO

534 def ned4(self):

535 '''Get the C{(north, east, down, ltp)} components (L{Ned4Tuple}).

536 '''

537 return Ned4Tuple(self.north, self.east, self.down, self.ltp, name=self.name)

538

539 @Property_RO

540 def north(self):

541 '''Get the North component (C{meter}).

542 '''

543 return self._north

544

545 @Property_RO

546 def slantrange(self):

547 '''Get the I{slant Range}, distance (C{meter}).

548 '''

549 return self.aer4.slantrange

550

551 @deprecated_method

552 def to3ned(self): # PYCHOK no cover

553 '''DEPRECATED, use property L{ned4}.'''

554 return self.ned # XXX deprecated too

555

556 def toRepr(self, prec=None, fmt=Fmt.SQUARE, sep=_COMMASPACE_, **unused): # PYCHOK expected

557 '''Return a string representation of this NED.

558

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

560 @kwarg fmt: Enclosing backets format (C{str}).

561 @kwarg sep: Separator to join (C{str}).

562

563 @return: This NED as "[N:meter, E:meter, D:meter]" (C{str}).

564 '''

565 a, t = _toStr2(self, prec=prec, fmt=NN, sep=NN)

566 return _xzipairs(a.upper(), t, sep=sep, fmt=fmt)

567

568 def toStr(self, **prec_fmt_sep): # PYCHOK expected

569 '''Return a string representation of this NED.

570

571 @kwarg prec_fmt_sep: Keyword arguments C{B{prec}=3} for the

572 number of (decimal) digits, unstripped

573 (C{int}), C{B{fmt}='[]'} the enclosing

574 backets format (C{str}) and separator

575 C{B{sep}=", "} to join (C{str}).

576

577 @return: This NED as "[meter, meter, meter]" (C{str}).

578 '''

579 _, t = _toStr2(self, **prec_fmt_sep)

580 return t

581

582 @deprecated_method

583 def toVector3d(self):

584 '''DEPRECATED, use property L{xyz}.'''

585 return self.xyz

586

587 @Property_RO

588 def up(self):

589 '''Get the Up component (C{meter}).

590 '''

591 return Meter(up=-self._down) # negated

592

593 @Property_RO

594 def x(self):

595 '''Get the X component (C{meter}).

596 '''

597 return Meter(x=self._east) # 2nd arg, E

598

599 @Property_RO

600 def xyz4(self):

601 '''Get the C{(x, y, z, ltp)} components (L{Xyz4Tuple}).

602 '''

603 return Xyz4Tuple(self.x, self.y, self.z, self.ltp, name=self.name)

604

605 @Property_RO

606 def y(self):

607 '''Get the Y component (C{meter}).

608 '''

609 return Meter(y=self._north) # 1st arg N

610

611 @Property_RO

612 def z(self):

613 '''Get the Z component (C{meter}).

614 '''

615 return Meter(z=-self._down) # negated

616

617

618 class Ned4Tuple(_Abc4Tuple):

619 '''4-Tuple C{(north, east, down, ltp)}, all in C{meter} except C{ltp}.

620 '''

621 _Names_ = (_north_, _east_, _down_, _ltp_)

622 _Units_ = ( Meter, Meter, Meter, _Pass)

623

624 def _toNed(self, Cls, Cls_kwds):

625 '''(INTERNAL) Return C{Cls(..., **Cls_kwds)} instance.

626 '''

627 return self._2Cls(Ned, Cls, Cls_kwds)

628

629 @Property_RO

630 def xyzLocal(self):

631 '''Get this L{Ned4Tuple} as an L{XyzLocal}.

632 '''

633 return Ned(self).xyzLocal

634

635

636 class _Vector3d(Vector3d):

637

638 _toStr = _xyz_

639

640 def toRepr(self, prec=None, fmt=Fmt.SQUARE, sep=_COMMASPACE_, **unused): # PYCHOK expected

641 '''Return a string representation of this ENU/NED/XYZ.

642

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

644 @kwarg fmt: Enclosing backets format (C{str}).

645 @kwarg sep: Separator to join (C{str}).

646

647 @return: This XYZ/ENU as "[E:meter, N:meter, U:meter]",

648 "[N:meter, E:meter, D:meter]",

649 "[U:meter, V:meter, W:meter]" respectively

650 "[X:meter, Y:meter, Z:meter]" (C{str}).

651 '''

652 a, t = _toStr2(self, prec=prec, fmt=NN, sep=NN)

653 return _xzipairs(a.upper(), t, sep=sep, fmt=fmt)

654

655 def toStr(self, **prec_fmt_sep): # PYCHOK expected

656 '''Return a string representation of this XYZ.

657

658 @kwarg prec_fmt_sep: Keyword arguments C{B{prec}=3} for the

659 number of (decimal) digits, unstripped

660 (C{int}), C{B{fmt}='[]'} the enclosing

661 backets format (C{str}) and separator

662 C{B{sep}=", "} to join (C{str}).

663

664 @return: This XYZ as "[meter, meter, meter]" (C{str}).

665 '''

666 _, t = _toStr2(self, **prec_fmt_sep)

667 return t

668

669

670 class XyzLocal(_Vector3d):

671 '''Local C{(x, y, z)} in a I{local tangent plane} (LTP),

672 also base class for local L{Enu}.

673 '''

674 _ltp = None # local tangent plane (C{Ltp}), origin

675

676 def __init__(self, x_xyz, y=0, z=0, ltp=None, **name):

677 '''New L{XyzLocal}.

678

679 @arg x_xyz: Scalar X component (C{meter}), C{positive east} or a

680 previous I{local} instance (L{XyzLocal}, L{Xyz4Tuple},

681 L{Aer}, L{Aer4Tuple}, L{Enu}, L{Enu4Tuple},

682 L{Local9Tuple}, L{Ned} or L{Ned4Tuple}).

683 @kwarg y: Scalar Y component (C{meter}), only used with scalar

684 B{C{x_xyz}}, C{positive north}.

685 @kwarg z: Scalar Z component, normal C{positive up} from the

686 surface of the ellipsoid or sphere (C{meter}), only

687 used with scalar B{C{x_xyz}}.

688 @kwarg ltp: The I{local tangent plane}, (geodetic) origin (L{Ltp},

689 L{LocalCartesian}).

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

691

692 @raise TypeError: Invalid B{C{x_xyz}} or B{C{ltp}}.

693

694 @raise UnitError: Invalid scalar B{C{x_xyz}}, B{C{y}} or B{C{z}}.

695 '''

696 if _isMeter(x_xyz):

697 xyz = None

698 t = (Meter(x=x_xyz or _0_0),

699 Meter(y=y or _0_0),

700 Meter(z=z or _0_0), ltp)

701 else:

702 xyz = _xyzLocal(XyzLocal, Xyz4Tuple, Local9Tuple, x_xyz=x_xyz) or x_xyz

703 t = xyz.xyz4 # xyz.x, xyz.y, xyz.z, xyz.ltp

704 self._x, self._y, self._z, _ = t

705 _init(self, xyz, ltp, name)

706

707 def __str__(self):

708 return self.toStr()

709

710 @Property_RO

711 def aer4(self):

712 '''Get the C{(azimuth, elevation, slantrange, ltp)} components (L{Aer4Tuple}).

713 '''

714 return _xyz2aer4(self)

715

716 @Property_RO

717 def azimuth(self):

718 '''Get the Azimuth, bearing from North (C{degrees360}).

719

720 @see: U{Azimuth<https://GSSC.ESA.int/navipedia/index.php/

721 Transformations_between_ECEF_and_ENU_coordinates>}.

722 '''

723 return self.aer4.azimuth

724

725 def classof(self, *args, **kwds): # PYCHOK no cover

726 '''Create another instance of this very class.

727

728 @arg args: Optional, positional arguments.

729 @kwarg kwds: Optional, keyword arguments.

730

731 @return: New instance (C{self.__class__}).

732 '''

733 kwds = _name1__(kwds, _or_nameof=self)

734 return self.__class__(*args, **_xkwds(kwds, ltp=self.ltp))

735

736 @Property_RO

737 def down(self):

738 '''Get the Down component (C{meter}).

739 '''

740 return Meter(down=-self.z)

741

742 @property_RO

743 def ecef(self):

744 '''Get this LTP's ECEF converter (C{Ecef...} I{instance}).

745 '''

746 return self.ltp.ecef

747

748 @Property_RO

749 def east(self):

750 '''Get the East component (C{meter}).

751 '''

752 return Meter(east=self.x)

753

754 @Property_RO

755 def elevation(self):

756 '''Get the Elevation, tilt above horizon (C{degrees90}).

757

758 @see: U{Elevation<https://GSSC.ESA.int/navipedia/index.php/

759 Transformations_between_ECEF_and_ENU_coordinates>}.

760 '''

761 return self.aer4.elevation # neg(degrees90(asin1(self.down / self.length))))

762

763 @Property_RO

764 def enu4(self):

765 '''Get the C{(east, north, up, ltp)} components (L{Enu4Tuple}).

766 '''

767 return Enu4Tuple(self.east, self.north, self.up, self.ltp, name=self.name)

768

769 @Property_RO

770 def groundrange(self):

771 '''Get the I{ground range}, distance (C{meter}).

772 '''

773 return Meter(groundrange=hypot(self.x, self.y))

774

775 @Property_RO

776 def ltp(self):

777 '''Get the I{local tangent plane} (L{Ltp}).

778 '''

779 return self._ltp

780

781 def _ltp_kwds_name3(self, ltp, kwds):

782 '''(INTERNAL) Helper for methods C{toCartesian} and C{toLatLon}.

783 '''

784 ltp = _ltp._xLtp(ltp, self.ltp)

785 kwds = _name1__(kwds, _or_nameof=self)

786 kwds = _name1__(kwds, _or_nameof=ltp)

787 return ltp, kwds, kwds.get(_name_, NN)

788

789 @Property_RO

790 def ned4(self):

791 '''Get the C{(north, east, down, ltp)} components (L{Ned4Tuple}).

792 '''

793 return Ned4Tuple(self.north, self.east, self.down, self.ltp, name=self.name)

794

795 @Property_RO

796 def north(self):

797 '''Get the North component (C{meter}).

798 '''

799 return Meter(north=self.y)

800

801 @Property_RO

802 def slantrange(self):

803 '''Get the I{slant Range}, distance (C{meter}).

804 '''

805 return self.aer4.slantrange

806

807 def toAer(self, Aer=None, **name_Aer_kwds):

808 '''Get the local I{Azimuth, Elevation, slant Range} components.

809

810 @kwarg Aer: Class to return AER (L{Aer}) or C{None}.

811 @kwarg name_Aer_kwds: Optional C{B{name}=NN} (C{str}) and

812 optional, additional B{C{Aer}} keyword arguments,

813 ignored if C{B{Aer} is None}.

814

815 @return: AER as an L{Aer} instance or if C{B{Aer} is None}, an

816 L{Aer4Tuple}C{(azimuth, elevation, slantrange, ltp)}.

817

818 @raise TypeError: Invalid B{C{Aer}} or B{C{name_Aer_kwds}}.

819 '''

820 return self.aer4._toAer(Aer, name_Aer_kwds)

821

822 def toCartesian(self, Cartesian=None, ltp=None, **name_Cartesian_kwds):

823 '''Get the geocentric C{(x, y, z)} (ECEF) coordinates of this local.

824

825 @kwarg Cartesian: Optional class to return C{(x, y, z)} (C{Cartesian})

826 or C{None}.

827 @kwarg ltp: Optional I{local tangent plane} (LTP) (L{Ltp}), overriding

828 this C{ltp}.

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

830 additional B{C{Cartesian}} keyword arguments, ignored if

831 C{B{Cartesian} is None}.

832

833 @return: A B{C{Cartesian}} instance of if C{B{Cartesian} is None}, an

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

835 C{M=None}, always.

836

837 @raise TypeError: Invalid B{C{ltp}}, B{C{Cartesian}} or B{C{name_Cartesian_kwds}}.

838 '''

839 ltp, kwds, n = self._ltp_kwds_name3(ltp, name_Cartesian_kwds)

840 if Cartesian is None:

841 t = ltp._local2ecef(self, nine=True)

842 r = _xnamed(t, n) if n else t

843 else:

844 kwds = _xkwds(kwds, datum=ltp.datum)

845 xyz = ltp._local2ecef(self) # [:3]

846 r = Cartesian(*xyz, **kwds)

847 return r

848

849 def toEnu(self, Enu=None, **name_Enu_kwds):

850 '''Get the local I{East, North, Up} (ENU) components.

851

852 @kwarg Enu: Class to return ENU (L{Enu}) or C{None}.

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

854 additional B{C{Enu}} keyword arguments, ignored if

855 C{B{Enu} is None}.

856

857 @return: ENU as an L{Enu} instance or if C{B{Enu} is None}, an

858 L{Enu4Tuple}C{(east, north, up, ltp)}.

859

860 @raise TypeError: Invalid B{C{Enu}} or B{C{name_Enu_kwds}}.

861 '''

862 return self.enu4._toEnu(Enu, name_Enu_kwds)

863

864 def toLatLon(self, LatLon=None, ltp=None, **name_LatLon_kwds):

865 '''Get the geodetic C{(lat, lon, height)} coordinates if this local.

866

867 @kwarg LatLon: Optional class to return C{(x, y, z)} (C{LatLon}) or

868 C{None}.

869 @kwarg ltp: Optional I{local tangent plane} (LTP) (L{Ltp}), overriding

870 this ENU/NED/AER/XYZ's LTP.

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

872 additional B{C{LatLon}} keyword arguments, ignored if

873 C{B{LatLon} is None}.

874

875 @return: An B{C{LatLon}} instance of if C{B{LatLon} is None}, an

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

877 C{M=None}, always.

878

879 @raise TypeError: Invalid B{C{LatLon}}, B{C{ltp}} or B{C{name_LatLon_kwds}}.

880 '''

881 ltp, kwds, n = self._ltp_kwds_name3(ltp, name_LatLon_kwds)

882 t = ltp._local2ecef(self, nine=True)

883 if LatLon is None:

884 r = _xnamed(t, n) if n else t

885 else:

886 kwds = _xkwds(kwds, height=t.height, datum=t.datum)

887 r = LatLon(t.lat, t.lon, **kwds) # XXX ltp?

888 return r

889

890 def toLocal9Tuple(self, M=False, **name):

891 '''Get this local as a C{Local9Tuple}.

892

893 @kwarg M: Optionally include the rotation matrix (C{bool}).

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

895

896 @return: L{Local9Tuple}C{(x, y, z, lat, lon, height, ltp, ecef, M)}

897 with C{ltp} this C{Ltp}, C{ecef} an L{Ecef9Tuple} and C{M}

898 an L{EcefMatrix} or C{None}.

899 '''

900 ltp = self.ltp # see C{self.toLatLon}

901 t = ltp._local2ecef(self, nine=True, M=M)

902 return Local9Tuple(self.x, self.y, self.z,

903 t.lat, t.lon, t.height,

904 ltp, t, t.M, name=t._name__(name))

905

906 def toNed(self, Ned=None, **name_Ned_kwds):

907 '''Get the local I{North, East, Down} (Ned) components.

908

909 @kwarg Ned: Class to return NED (L{Ned}) or C{None}.

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

911 additional B{C{Ned}} keyword arguments, ignored if

912 C{B{Ned} is None}.

913

914 @return: NED as an L{Ned} instance or if C{B{Ned} is None}, an

915 L{Ned4Tuple}C{(north, east, down, ltp)}.

916

917 @raise TypeError: Invalid B{C{Ned}} or B{C{name_Ned_kwds}}.

918 '''

919 return self.ned4._toNed(Ned, name_Ned_kwds)

920

921 def toXyz(self, Xyz=None, **name_Xyz_kwds):

922 '''Get the local I{X, Y, Z} (XYZ) components.

923

924 @kwarg Xyz: Class to return XYZ (L{XyzLocal}, L{Enu}, L{Ned}, L{Aer})

925 or C{None}.

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

927 additional B{C{Xyz}} keyword arguments, ignored if

928 C{B{Xyz} is None}.

929

930 @return: XYZ as an B{C{Xyz}} instance or if C{B{Xyz} is None}, an

931 L{Xyz4Tuple}C{(x, y, z, ltp)}.

932

933 @raise TypeError: Invalid B{C{Xyz}} or B{C{name_EXyz_kwds}}.

934 '''

935 return self.xyz4._toXyz(Xyz, name_Xyz_kwds)

936

937 @Property_RO

938 def up(self):

939 '''Get the Up component (C{meter}).

940 '''

941 return Meter(up=self.z)

942

943# @Property_RO

944# def x(self): # see: Vector3d.x

945# '''Get the X component (C{meter}).

946# '''

947# return self._x

948

949# @Property_RO

950# def xyz(self): # see: Vector3d.xyz

951# '''Get the I{local} C{(X, Y, Z)} coordinates (L{Vector3Tuple}C{(x, y, z)}).

952# '''

953# return Vector3Tuple(self.x, self.y, self.z, name=self.name) # like Ecef9Tuple.xyz, Local6tuple.xyz

954

955 @Property_RO

956 def xyz4(self):

957 '''Get the C{(x, y, z, ltp)} components (L{Xyz4Tuple}).

958 '''

959 return Xyz4Tuple(self.x, self.y, self.z, self.ltp, name=self.name)

960

961 @Property_RO

962 def xyzLocal(self):

963 '''Get this L{XyzLocal}.

964 '''

965 return self

966

967# @Property_RO

968# def y(self): # see: Vector3d.y

969# '''Get the Y component (C{meter}).

970# '''

971# return self._y

972

973# @Property_RO

974# def z(self): # see: Vector3d.z

975# '''Get the Z component (C{meter}).

976# '''

977# return self._z

978

979

980 class Xyz4Tuple(_Abc4Tuple):

981 '''4-Tuple C{(x, y, z, ltp)}, all in C{meter} except C{ltp}.

982 '''

983 _Names_ = (_x_, _y_, _z_, _ltp_)

984 _Units_ = ( Meter, Meter, Meter, _Pass)

985

986 def _toXyz(self, Cls, Cls_kwds):

987 '''(INTERNAL) Return C{Cls(..., **Cls_kwds)} instance.

988 '''

989 return self._2Cls(XyzLocal, Cls, Cls_kwds)

990

991 @property_RO

992 def xyz4(self):

993 '''Get the C{(x, y, z, ltp)} components (L{Xyz4Tuple}).

994 '''

995 return self

996

997 @Property_RO

998 def xyzLocal(self):

999 '''Get this L{Xyz4Tuple} as an L{XyzLocal}.

1000 '''

1001 return XyzLocal(*self, name=self.name)

1002

1003

1004 class Enu(XyzLocal):

1005 '''Local C{Eeast-North-Up} (ENU) location in a I{local tangent plane}.

1006

1007 @see: U{East, North, Up (ENU)<https://GSSC.ESA.int/navipedia/index.php/

1008 Transformations_between_ECEF_and_ENU_coordinates>} coordinates.

1009 '''

1010 _toStr = _enu_

1011

1012 def __init__(self, east_enu, north=0, up=0, ltp=None, **name):

1013 '''New L{Enu}.

1014

1015 @arg east_enu: Scalar East component (C{meter}) or a previous

1016 I{local} instance (L{Enu}, L{Enu4Tuple}, L{Aer},

1017 L{Aer4Tuple}, L{Local9Tuple}, L{Ned}, L{Ned4Tuple},

1018 L{XyzLocal} or L{Xyz4Tuple}).

1019 @kwarg north: Scalar North component (C{meter}) only used with

1020 scalar B{C{east_enu}}.

1021 @kwarg up: Scalar Up component only used with scalar B{C{east_enu}},

1022 normal from the surface of the ellipsoid or sphere (C{meter}).

1023 @kwarg ltp: The I{local tangent plane}, (geodetic) origin (L{Ltp},

1024 L{LocalCartesian}).

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

1026

1027 @raise TypeError: Invalid B{C{east_enu}} or B{C{ltp}}.

1028

1029 @raise UnitError: Invalid B{C{east_enu}}, B{C{north}} or B{C{up}}.

1030 '''

1031 XyzLocal.__init__(self, east_enu, north, up, ltp=ltp, **name)

1032

1033 def toUvw(self, location, Uvw=None, **name_Uvw_kwds):

1034 '''Get the I{u, v, w} (UVW) components at a location.

1035

1036 @arg location: The geodetic (C{LatLon}) or geocentric (C{Cartesian},

1037 L{Vector3d}) location, like a Point-Of-View.

1038 @kwarg Uvw: Class to return UWV (L{Uvw}) or C{None}.

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

1040 additional B{L{Uvw}} keyword arguments, ignored if

1041 C{B{Uvw} is None}.

1042

1043 @return: UVW as a L{Uvw} instance or if C{B{Uvw} is None}, a

1044 L{Uvw3Tuple}C{(u, v, w)}.

1045

1046 @raise TypeError: Invalid B{C{location}} or B{C{name_Uvw_kwds}}.

1047

1048 @see: Function U{lookAtSpheroid<https://PyPI.org/project/pymap3d>}.

1049 '''

1050 try:

1051 sa, ca, sb, cb = sincos2_(*location.philam)

1052 except Exception as x:

1053 raise _TypeError(location=location, cause=x)

1054 e, n, u, _ = self.enu4

1055

1056 t = ca * u - sa * n

1057 U = cb * t - sb * e

1058 V = cb * e + sb * t

1059 W = ca * n + sa * u

1060

1061 n, kwds = _name2__(name_Uvw_kwds, _or_nameof=self)

1062 return Uvw3Tuple(U, V, W, name=n) if Uvw is None else \

1063 Uvw(U, V, W, name=n, **kwds)

1064

1065 @Property_RO

1066 def xyzLocal(self):

1067 '''Get this ENU as an L{XyzLocal}.

1068 '''

1069 return XyzLocal(*self.xyz4, name=self.name)

1070

1071

1072 class Enu4Tuple(_Abc4Tuple):

1073 '''4-Tuple C{(east, north, up, ltp)}, in C{meter} except C{ltp}.

1074 '''

1075 _Names_ = (_east_, _north_, _up_, _ltp_)

1076 _Units_ = ( Meter, Meter, Meter, _Pass)

1077

1078 def _toEnu(self, Cls, Cls_kwds):

1079 '''(INTERNAL) Return C{Cls(..., **Cls_kwds)} instance.

1080 '''

1081 return self._2Cls(Enu, Cls, Cls_kwds)

1082

1083 @Property_RO

1084 def xyzLocal(self):

1085 '''Get this L{Enu4Tuple} as an L{XyzLocal}.

1086 '''

1087 return XyzLocal(*self, name=self.name)

1088

1089

1090 class Local9Tuple(_NamedTuple):

1091 '''9-Tuple C{(x, y, z, lat, lon, height, ltp, ecef, M)} with I{local} C{x},

1092 C{y}, C{z} all in C{meter}, I{geodetic} C{lat}, C{lon}, C{height}, I{local

1093 tangent plane} C{ltp} (L{Ltp}), C{ecef} (L{Ecef9Tuple}) with I{geocentric}

1094 C{x}, C{y}, C{z}, I{geodetic} C{lat}, C{lon}, C{height} and I{concatenated}

1095 rotation matrix C{M} (L{EcefMatrix}) or C{None}.

1096 '''

1097 _Names_ = (_x_, _y_, _z_, _lat_, _lon_, _height_, _ltp_, _ecef_, _M_)

1098 _Units_ = ( Meter, Meter, Meter, Lat, Lon, Height, _Pass, _Pass, _Pass)

1099

1100 @Property_RO

1101 def azimuth(self):

1102 '''Get the I{local} Azimuth, bearing from North (C{degrees360}).

1103 '''

1104 return self.xyzLocal.aer4.azimuth

1105

1106 @Property_RO

1107 def down(self):

1108 '''Get the I{local} Down, C{-z} component (C{meter}).

1109 '''

1110 return -self.z

1111

1112 @Property_RO

1113 def east(self):

1114 '''Get the I{local} East, C{x} component (C{meter}).

1115 '''

1116 return self.x

1117

1118 @Property_RO

1119 def elevation(self):

1120 '''Get the I{local} Elevation, tilt I{above} horizon (C{degrees90}).

1121 '''

1122 return self.xyzLocal.aer4.elevation

1123

1124 @Property_RO

1125 def groundrange(self):

1126 '''Get the I{local} ground range, distance (C{meter}).

1127 '''

1128 return self.xyzLocal.aer4.groundrange

1129

1130 @Property_RO

1131 def lam(self):

1132 '''Get the I{geodetic} longitude in C{radians} (C{float}).

1133 '''

1134 return self.philam.lam

1135

1136 @Property_RO

1137 def latlon(self):

1138 '''Get the I{geodetic} lat-, longitude in C{degrees} (L{LatLon2Tuple}C{(lat, lon)}).

1139 '''

1140 return LatLon2Tuple(self.lat, self.lon, name=self.name)

1141

1142 @Property_RO

1143 def latlonheight(self):

1144 '''Get the I{geodetic} lat-, longitude in C{degrees} and height (L{LatLon3Tuple}C{(lat, lon, height)}).

1145 '''

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

1147

1148 @Property_RO

1149 def north(self):

1150 '''Get the I{local} North, C{y} component (C{meter}).

1151 '''

1152 return self.y

1153

1154 @Property_RO

1155 def phi(self):

1156 '''Get the I{geodetic} latitude in C{radians} (C{float}).

1157 '''

1158 return self.philam.phi

1159

1160 @Property_RO

1161 def philam(self):

1162 '''Get the I{geodetic} lat-, longitude in C{radians} (L{PhiLam2Tuple}C{(phi, lam)}).

1163 '''

1164 return PhiLam2Tuple(radians(self.lat), radians(self.lon), name=self.name)

1165

1166 @Property_RO

1167 def philamheight(self):

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

1169 '''

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

1171

1172 @Property_RO

1173 def slantrange(self):

1174 '''Get the I{local} slant Range, distance (C{meter}).

1175 '''

1176 return self.xyzLocal.aer4.slantrange

1177

1178 def toAer(self, Aer=None, **name_Aer_kwds):

1179 '''Get the I{local} I{Azimuth, Elevation, slant Range} (AER) components.

1180

1181 @kwarg Aer: Class to return AER (L{Aer}) or C{None}.

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

1183 additional B{L{Aer}} keyword arguments, ignored if

1184 C{B{Aer} is None}.

1185

1186 @return: AER as an L{Aer} instance or if C{B{Aer} is None}, an

1187 L{Aer4Tuple}C{(azimuth, elevation, slantrange, ltp)}.

1188

1189 @raise TypeError: Invalid B{C{Aer}} or B{C{name_Aer_kwds}}.

1190 '''

1191 return self.xyzLocal.toAer(Aer=Aer, **name_Aer_kwds)

1192

1193 def toCartesian(self, Cartesian=None, **name_Cartesian_kwds):

1194 '''Convert this I{local} to I{geocentric} C{(x, y, z)} (ECEF).

1195

1196 @kwarg Cartesian: Optional class to return C{(x, y, z)} (C{Cartesian})

1197 or C{None}.

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

1199 additional B{C{Cartesian}} keyword arguments, ignored if

1200 C{B{Cartesian} is None}.

1201

1202 @return: A C{B{Cartesian}(x, y, z, **B{Cartesian_kwds})} instance or

1203 if C{B{Cartesian} is None}, a L{Vector4Tuple}C{(x, y, z, h)} .

1204

1205 @raise TypeError: Invalid B{C{Cartesian}} or B{C{name_Cartesian_kwds}}.

1206 '''

1207 return self.ecef.toCartesian(Cartesian=Cartesian, **name_Cartesian_kwds) # PYCHOK _Tuple

1208

1209 def toEnu(self, Enu=None, **name_Enu_kwds):

1210 '''Get the I{local} I{East, North, Up} (ENU) components.

1211

1212 @kwarg Enu: Class to return ENU (L{Enu}) or C{None}.

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

1214 additional B{L{Enu}} keyword arguments, ignored if

1215 C{B{Enu} is None}.

1216

1217 @return: ENU as an L{Enu} instance or if C{B{Enu} is None}, an

1218 L{Enu4Tuple}C{(east, north, up, ltp)}.

1219

1220 @raise TypeError: Invalid B{C{Enu}} or B{C{name_Enu_kwds}}.

1221 '''

1222 return self.xyzLocal.toEnu(Enu=Enu, **name_Enu_kwds)

1223

1224 def toLatLon(self, LatLon=None, **name_LatLon_kwds):

1225 '''Convert this I{local} to I{geodetic} C{(lat, lon, height)}.

1226

1227 @kwarg LatLon: Optional class to return C{(lat, lon, height)}

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

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

1230 additional B{C{LatLon}} keyword arguments, ignored if

1231 C{B{LatLon} is None}.

1232

1233 @return: An instance of C{B{LatLon}(lat, lon, **B{LatLon_kwds})}

1234 or if C{B{LatLon} is None}, a L{LatLon3Tuple}C{(lat, lon,

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

1236 datum)} depending on whether C{datum} is un-/specified.

1237

1238 @raise TypeError: Invalid B{C{LatLon}} or B{C{name_LatLon_kwds}}.

1239 '''

1240 return self.ecef.toLatLon(LatLon=LatLon, **name_LatLon_kwds) # PYCHOK _Tuple

1241

1242 def toNed(self, Ned=None, **name_Ned_kwds):

1243 '''Get the I{local} I{North, East, Down} (NED) components.

1244

1245 @kwarg Ned: Class to return NED (L{Ned}) or C{None}.

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

1247 additional B{L{Ned}} keyword arguments, ignored if

1248 C{B{Ned} is None}.

1249

1250 @return: NED as an L{Ned} instance or if C{B{Ned} is None}, an

1251 L{Ned4Tuple}C{(north, east, down, ltp)}.

1252

1253 @raise TypeError: Invalid B{C{Ned}} or B{C{name_Ned_kwds}}.

1254 '''

1255 return self.xyzLocal.toNed(Ned=Ned, **name_Ned_kwds)

1256

1257 def toXyz(self, Xyz=None, **name_Xyz_kwds):

1258 '''Get the I{local} I{X, Y, Z} (XYZ) components.

1259

1260 @kwarg Xyz: Class to return XYZ (L{XyzLocal}) or C{None}.

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

1262 additional B{C{Xyz}} keyword arguments, ignored if

1263 C{B{Xyz} is None}.

1264

1265 @return: XYZ as an B{C{Xyz}} instance or if C{B{Xyz} is None},

1266 an L{Xyz4Tuple}C{(x, y, z, ltp)}.

1267

1268 @raise TypeError: Invalid B{C{Xyz}} or B{C{name_Xyz_kwds}}.

1269 '''

1270 return self.xyzLocal.toXyz(Xyz=Xyz, **name_Xyz_kwds)

1271

1272 @Property_RO

1273 def up(self):

1274 '''Get the I{local} Up, C{z} component (C{meter}).

1275 '''

1276 return self.z

1277

1278 @Property_RO

1279 def xyz(self):

1280 '''Get the I{local} C{(X, Y, Z)} components (L{Vector3Tuple}C{(x, y, z)}).

1281 '''

1282 return Vector3Tuple(self.x, self.y, self.z, name=self.name) # like Ecef9Tuple.xyz

1283

1284 @Property_RO

1285 def xyzLocal(self):

1286 '''Get this L{Local9Tuple} as an L{XyzLocal}.

1287 '''

1288 return XyzLocal(*self.xyz, ltp=self.ltp, name=self.name) # PYCHOK .ltp

1289

1290

1291_XyzLocals4 = XyzLocal, Enu, Ned, Aer # PYCHOK in .ltp

1292_XyzLocals5 = _XyzLocals4 + (Local9Tuple,) # PYCHOK in .ltp

1293

1294

1295 class Uvw(_Vector3d):

1296 '''3-D C{u-v-w} (UVW) components.

1297 '''

1298 _toStr = _uvw_

1299

1300 def __init__(self, u_uvw, v=0, w=0, **name):

1301 '''New L{Uvw}.

1302

1303 @arg u_uvw: Scalar U component (C{meter}) or a previous instance

1304 (L{Uvw}, L{Uvw3Tuple}, L{Vector3d}).

1305 @kwarg v: V component (C{meter}) only used with scalar B{C{u_uvw}}.

1306 @kwarg w: W component (C{meter}) only used with scalar B{C{u_uvw}}.

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

1308

1309 @raise TypeError: Invalid B{C{east_enu}}.

1310

1311 @raise UnitError: Invalid B{C{east_enu}}, B{C{v}} or B{C{w}}.

1312 '''

1313 Vector3d.__init__(self, u_uvw, v, w, **name)

1314

1315 def toEnu(self, location, Enu=Enu, **name_Enu_kwds):

1316 '''Get the I{East, North, Up} (ENU) components at a location.

1317

1318 @arg location: The geodetic (C{LatLon}) or geocentric (C{Cartesian},

1319 L{Vector3d}) location from where to cast the L{Los}.

1320 @kwarg Enu: Class to return ENU (L{Enu}) or C{None}.

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

1322 additional B{L{Enu}} keyword arguments, ignored if

1323 C{B{Enu} is None}.

1324

1325 @return: ENU as an L{Enu} instance or if C{B{Enu} is None}, an

1326 L{Enu4Tuple}C{(east, north, up, ltp)} with C{ltp=None}.

1327

1328 @raise TypeError: Invalid B{C{location}} or B{C{name_Enu_kwds}}.

1329

1330 @see: Function U{lookAtSpheroid<https://PyPI.org/project/pymap3d>}.

1331 '''

1332 try:

1333 sa, ca, sb, cb = sincos2_(*location.philam)

1334 except Exception as x:

1335 raise _TypeError(location=location, cause=x)

1336 u, v, w = self.uvw

1337

1338 t = cb * u + sb * v

1339 E = cb * v - sb * u

1340 N = ca * w - sa * t

1341 U = ca * t + sa * w

1342

1343 n, kwds = _name2__(name_Enu_kwds, _or_nameof=self)

1344 return Enu4Tuple(E, N, U, name=n) if Enu is None else \

1345 Enu(E, N, U, name=n, **kwds)

1346

1347 u = Vector3d.x

1348

1349 @Property_RO

1350 def uvw(self):

1351 '''Get the C{(U, V, W)} components (L{Uvw3Tuple}C{(u, v, w)}).

1352 '''

1353 return Uvw3Tuple(self.u, self.v, self.w, name=self.name)

1354

1355 v = Vector3d.y

1356 w = Vector3d.z

1357

1358

1359 class Uvw3Tuple(_NamedTuple):

1360 '''3-Tuple C{(u, v, w)}, in C{meter}.

1361 '''

1362 _Names_ = ('u', 'v', 'w')

1363 _Units_ = ( Meter, Meter, Meter)

1364

1365

1366 class Los(Aer):

1367 '''A Line-Of-Sight (LOS) from a C{LatLon} or C{Cartesian} location.

1368 '''

1369

1370 def __init__(self, azimuth_aer, elevation=0, **name):

1371 '''New L{Los}.

1372

1373 @arg azimuth_aer: Scalar azimuth, bearing from North (compass C{degrees})

1374 or a previous instance (L{Aer}, L{Aer4Tuple}, L{Enu},

1375 L{Enu4Tuple} or L{Los}).

1376 @kwarg elevation: Scalar angle I{above} the horizon (C{degrees}, horizon

1377 is 0, zenith +90, nadir -90), only used with scalar

1378 B{C{azimuth_aer}}.

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

1380

1381 @raise TypeError: Invalid B{C{azimuth_aer}}.

1382

1383 @raise UnitError: Invalid B{C{azimuth_aer}} or B{C{elevation}}.

1384 '''

1385 t = Aer(azimuth_aer, elevation)

1386 Aer.__init__(self, t.azimuth, t.elevation, slantrange=_1_0, **name)

1387

1388 def toUvw(self, location, Uvw=Uvw, **name_Uvw_kwds):

1389 '''Get this LOS' I{target} (UVW) components from a location.

1390

1391 @arg location: The geodetic (C{LatLon}) or geocentric (C{Cartesian},

1392 L{Vector3d}) location from where to cast this LOS.

1393

1394 @see: Method L{Enu.toUvw} for further details.

1395 '''

1396 return self.toEnu().toUvw(location, Uvw=Uvw, **name_Uvw_kwds)

1397

1398 def toEnu(self, Enu=Enu, **name_Enu_kwds):

1399 '''Get this LOS as I{East, North, Up} (ENU) components.

1400

1401 @see: Method L{Aer.toEnu} for further details.

1402 '''

1403 return Aer.toEnu(self, Enu=Enu, **name_Enu_kwds)

1404

1405

1406 class ChLV9Tuple(Local9Tuple):

1407 '''9-Tuple C{(Y, X, h_, lat, lon, height, ltp, ecef, M)} with I{B{unfalsed} Swiss

1408 (Y, X, h_)} coordinates and height, all in C{meter}, C{ltp} either a L{ChLV},

1409 L{ChLVa} or L{ChLVe} instance and C{ecef} (L{EcefKarney} I{at Bern, Ch}),

1410 otherwise like L{Local9Tuple}.

1411 '''

1412 _Names_ = (_Y_, _X_, _h__) + Local9Tuple._Names_[3:]

1413

1414 @Property_RO

1415 def E_LV95(self):

1416 '''Get the B{falsed} I{Swiss E_LV95} easting (C{meter}).

1417 '''

1418 return self.EN2_LV95.E_LV95

1419

1420 @Property_RO

1421 def EN2_LV95(self):

1422 '''Get the I{falsed Swiss (E_LV95, N_LV95)} easting and northing (L{ChLVEN2Tuple}).

1423 '''

1424 return ChLVEN2Tuple(*_ltp.ChLV.false2(self.Y, self.X, True), name=self.name)

1425

1426 @Property_RO

1427 def h_LV03(self):

1428 '''Get the I{Swiss h_} height (C{meter}).

1429 '''

1430 return self.h_

1431

1432 @Property_RO

1433 def h_LV95(self):

1434 '''Get the I{Swiss h_} height (C{meter}).

1435 '''

1436 return self.h_

1437

1438 @property_RO

1439 def isChLV(self):

1440 '''Is this a L{ChLV}-generated L{ChLV9Tuple}?.

1441 '''

1442 return self.ltp.__class__ is _ltp.ChLV

1443

1444 @property_RO

1445 def isChLVa(self):

1446 '''Is this a L{ChLVa}-generated L{ChLV9Tuple}?.

1447 '''

1448 return self.ltp.__class__ is _ltp.ChLVa

1449

1450 @property_RO

1451 def isChLVe(self):

1452 '''Is this a L{ChLVe}-generated L{ChLV9Tuple}?.

1453 '''

1454 return self.ltp.__class__ is _ltp.ChLVe

1455

1456 @Property_RO

1457 def N_LV95(self):

1458 '''Get the B{falsed} I{Swiss N_LV95} northing (C{meter}).

1459 '''

1460 return self.EN2_LV95.N_LV95

1461

1462 @Property_RO

1463 def x(self):

1464 '''Get the I{local x, Swiss Y} easting (C{meter}).

1465 '''

1466 return self.Y

1467

1468 @Property_RO

1469 def x_LV03(self):

1470 '''Get the B{falsed} I{Swiss x_LV03} northing (C{meter}).

1471 '''

1472 return self.yx2_LV03.x_LV03

1473

1474 @Property_RO

1475 def y(self):

1476 '''Get the I{local y, Swiss X} northing (C{meter}).

1477 '''

1478 return self.X

1479

1480 @Property_RO

1481 def y_LV03(self):

1482 '''Get the B{falsed} I{Swisss y_LV03} easting (C{meter}).

1483 '''

1484 return self.yx2_LV03.y_LV03

1485

1486 @Property_RO

1487 def YX(self):

1488 '''Get the B{unfalsed} easting and northing (L{ChLVYX2Tuple}).

1489 '''

1490 return ChLVYX2Tuple(self.Y, self.X, name=self.name)

1491

1492 @Property_RO

1493 def yx2_LV03(self):

1494 '''Get the B{falsed} I{Swiss (y_LV03, x_LV03)} easting and northing (L{ChLVyx2Tuple}).

1495 '''

1496 return ChLVyx2Tuple(*_ltp.ChLV.false2(self.Y, self.X, False), name=self.name)

1497

1498 @Property_RO

1499 def z(self):

1500 '''Get the I{local z, Swiss h_} height (C{meter}).

1501 '''

1502 return self.h_

1503

1504

1505 class ChLVYX2Tuple(_NamedTuple):

1506 '''2-Tuple C{(Y, X)} with B{unfalsed} I{Swiss LV95} easting and norting

1507 in C{meter}.

1508 '''

1509 _Names_ = (_Y_, _X_)

1510 _Units_ = ( Meter, Meter)

1511

1512 def false2(self, LV95=True):

1513 '''Return the falsed C{Swiss LV95} or C{LV03} version of the projection.

1514

1515 @see: Function L{ChLV.false2} for more information.

1516 '''

1517 return _ltp.ChLV.false2(*self, LV95=LV95, name=self.name)

1518

1519

1520 class ChLVEN2Tuple(_NamedTuple):

1521 '''2-Tuple C{(E_LV95, N_LV95)} with B{falsed} I{Swiss LV95} easting and

1522 norting in C{meter (2_600_000, 1_200_000)} and origin at C{Bern, Ch}.

1523 '''

1524 _Names_ = ('E_LV95', 'N_LV95')

1525 _Units_ = ChLVYX2Tuple._Units_

1526

1527 def unfalse2(self):

1528 '''Return this projection as an B{unfalsed} L{ChLVYX2Tuple}.

1529

1530 @see: Function L{ChLV.unfalse2} for more information.

1531 '''

1532 return _ltp.ChLV.unfalse2(*self, LV95=True, name=self.name)

1533

1534

1535 class ChLVyx2Tuple(_NamedTuple):

1536 '''2-Tuple C{(y_LV03, x_LV03)} with B{falsed} I{Swiss LV03} easting and

1537 norting in C{meter (600_000, 200_000)} and origin at C{Bern, Ch}.

1538 '''

1539 _Names_ = ('y_LV03', 'x_LV03')

1540 _Units_ = ChLVYX2Tuple._Units_

1541

1542 def unfalse2(self):

1543 '''Return this projection as an B{unfalsed} L{ChLVYX2Tuple}.

1544

1545 @see: Function L{ChLV.unfalse2} for more information.

1546 '''

1547 return _ltp.ChLV.unfalse2(*self, LV95=False, name=self.name)

1548

1549

1550 class Footprint5Tuple(_NamedTuple):

1551 '''5-Tuple C{(center, upperleft, upperight, loweright, lowerleft)}

1552 with the C{center} and 4 corners of the I{local} projection of

1553 a C{Frustum}, each an L{Xyz4Tuple}, L{XyzLocal}, C{LatLon}, etc.

1554

1555 @note: Misspelling of C{upperight} and C{loweright} is I{intentional}.

1556 '''

1557 _Names_ = (_center_, 'upperleft', 'upperight', 'loweright', 'lowerleft')

1558 _Units_ = (_Pass, _Pass, _Pass, _Pass, _Pass)

1559

1560 def toLatLon5(self, ltp=None, LatLon=None, **name_LatLon_kwds):

1561 '''Convert this footprint's C{center} and 4 corners to I{geodetic}

1562 C{LatLon(lat, lon, height)}s or C{LatLon3-} or C{-4Tuple}s.

1563

1564 @kwarg ltp: The I{local tangent plane} (L{Ltp}), overriding this

1565 footprint's C{center} or C{frustrum} C{ltp}.

1566 @kwarg LatLon: Optional I{geodetic} class (C{LatLon}) or C{None}.

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

1568 additional B{C{LatLon}} keyword arguments, ignored if

1569 C{B{LatLon} is None}.

1570

1571 @return: A L{Footprint5Tuple} of 5 C{B{LatLon}(lat, lon,

1572 **B{name_LatLon_kwds})} instances or if C{B{LatLon} is None},

1573 5 L{LatLon3Tuple}C{(lat, lon, height)}s respectively

1574 5 L{LatLon4Tuple}C{(lat, lon, height, datum)}s depending

1575 on whether keyword argument C{datum} is un-/specified.

1576

1577 @raise TypeError: Invalid B{C{ltp}}, B{C{LatLon}} or B{C{name_LatLon_kwds}}.

1578

1579 @see: Methods L{XyzLocal.toLatLon} and L{Footprint5Tuple.xyzLocal5}.

1580 '''

1581 ltp = _ltp._xLtp(ltp, self.center.ltp) # PYCHOK .center

1582 kwds = _name1__(name_LatLon_kwds, _or_nameof=self)

1583 kwds = _xkwds(kwds, ltp=ltp, LatLon=LatLon)

1584 return Footprint5Tuple(t.toLatLon(**kwds) for t in self.xyzLocal5())

1585

1586 def xyzLocal5(self, ltp=None):

1587 '''Return this footprint's C{center} and 4 corners as 5 L{XyzLocal}s.

1588

1589 @kwarg ltp: The I{local tangent plane} (L{Ltp}), overriding

1590 the {center} and corner C{ltp}s.

1591

1592 @return: A L{Footprint5Tuple} of 5 L{XyzLocal} instances.

1593

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

1595 '''

1596 if ltp is None:

1597 p = self

1598 else:

1599 p = _ltp._xLtp(ltp)

1600 p = tuple(Xyz4Tuple(t.x, t.y, t.z, p) for t in self)

1601 return Footprint5Tuple(t.xyzLocal for t in p)

1602

1603

1604__all__ += _ALL_DOCS(_AbcBase)

1605

1606# **) MIT License

1607#

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

1609#

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

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

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

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

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

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

1616#

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

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

1619#

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

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

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

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

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

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

1626# OTHER DEALINGS IN THE SOFTWARE.