1

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

3

4 u'''Named tuples.

5

6 Tuples returned by C{pygeodesy} functions and class methods

7 are all instances of some C{Named...Tuple} class, all sub-classes

8 of C{_NamedTuple} defined in C{pygeodesy.named}.

9'''

10

11 from pygeodesy.basics import map1, _xinstanceof

12# from pygeodesy.constants import INT0 # from .units

13 from pygeodesy.errors import _ALL_LAZY, _MODS, _xattr, _xkwds_not # _xkwds

14 from pygeodesy.interns import NN, _1_, _2_, _a_, _A_, _area_, _angle_, _b_, \

15 _B_, _band_, _c_, _C_, _datum_, _D_, _distance_, \

16 _E_, _easting_, _end_, _fi_, _gamma_, _height_, \

17 _j_, _h_, _hemipole_, _initial_, _lam_, _lat_, \

18 _lon_, _n_, _northing_, _number_, _outside_, \

19 _phi_, _point_, _precision_, _radius_, _points_, \

20 _scale_, _start_, _x_, _y_, _z_, _zone_

21# from pygeodesy.lazily import _ALL_LAZY, _ALL_MODS as _MODS # from .errors

22 from pygeodesy.named import _NamedTuple, _Pass

23 from pygeodesy.props import deprecated_property_RO, property_RO

24 from pygeodesy.units import Band, Bearing, Degrees, Degrees2, Easting, \

25 FIx, Height, Int, INT0, Lam, Lat, Lon, Meter, \

26 Meter2, Northing, Number_, Phi, Precision_, \

27 Radians, Radius, Scalar, Str

28

29__all__ = _ALL_LAZY.namedTuples

30__version__ = '23.07.21'

31

32# __DUNDER gets mangled in class

33_closest_ = 'closest'

34_destination_ = 'destination'

35_elel_ = 'll'

36_final_ = 'final'

37_fraction_ = 'fraction'

38_normal_ = 'normal'

39

40

41 class Bearing2Tuple(_NamedTuple):

42 '''2-Tuple C{(initial, final)} bearings, both in compass C{degrees360}.

43 '''

44 _Names_ = (_initial_, _final_)

45 _Units_ = ( Bearing, Bearing)

46

47

48 class Bounds2Tuple(_NamedTuple): # .geohash.py, .latlonBase.py, .points.py

49 '''2-Tuple C{(latlonSW, latlonNE)} with the bounds' lower-left and

50 upper-right corner as C{LatLon} instance.

51 '''

52 _Names_ = ('latlonSW', 'latlonNE')

53 _Units_ = (_Pass, _Pass)

54

55

56 class Bounds4Tuple(_NamedTuple): # .geohash.py, .points.py

57 '''4-Tuple C{(latS, lonW, latN, lonE)} with the bounds' lower-left

58 C{(LatS, LowW)} and upper-right C{(latN, lonE)} corner lat- and

59 longitudes.

60 '''

61 _Names_ = ('latS', 'lonW', 'latN', 'lonE')

62 _Units_ = ( Lat, Lon, Lat, Lon)

63

64 def enclosures(self, S_other, *W_N_E):

65 '''Get the enclosures of this around an other L{Bounds4Tuple}.

66

67 @arg S_other: Bottom C{latS} (C{scalar}) or an other

68 L{Bounds4Tuple} instance.

69 @arg W_N_E: Left C{lonW}, top C{latN} and right C{lonE},

70 each a (C{scalar}) for C{scalar B{S_other}}.

71

72 @return: A L{Bounds4Tuple} with the I{margin} at each of

73 the 4 sides, positive if this side I{encloses}

74 (is on the I{outside} of) the other, negative

75 if not or zero if abutting.

76 '''

77 s, w, n, e = self

78 S, W, N, E = map1(float, S_other, *W_N_E) if W_N_E else S_other

79 return Bounds4Tuple(map1(float, S - s, W - w, n - N, e - E)) # *map1

80

81 def overlap(self, S_other, *W_N_E):

82 '''Intersect this with an other L{Bounds4Tuple}.

83

84 @arg S_other: Bottom C{latS} (C{scalar}) or an other

85 L{Bounds4Tuple} instance.

86 @arg W_N_E: Left C{lonW}, top C{latN} and right C{lonE},

87 each a (C{scalar}) for C{scalar B{S_other}}.

88

89 @return: C{None} if the bounds do not overlap, otherwise

90 the intersection of both as a L{Bounds4Tuple}.

91 '''

92 s, w, n, e = self

93 S, W, N, E = map1(float, S_other, *W_N_E) if W_N_E else S_other

94 return None if s > N or n < S or w > E or e < W else \

95 Bounds4Tuple(max(s, S), max(w, W), min(n, N), min(e, E))

96

97

98 class Destination2Tuple(_NamedTuple): # .ellipsoidalKarney.py, -Vincenty.py

99 '''2-Tuple C{(destination, final)}, C{destination} in C{LatLon}

100 and C{final} bearing in compass C{degrees360}.

101 '''

102 _Names_ = (_destination_, _final_)

103 _Units_ = (_Pass, Bearing)

104

105

106 class Destination3Tuple(_NamedTuple): # .karney.py

107 '''3-Tuple C{(lat, lon, final)}, destination C{lat}, C{lon} in

108 C{degrees90} respectively C{degrees180} and C{final} bearing

109 in compass C{degrees360}.

110 '''

111 _Names_ = (_lat_, _lon_, _final_)

112 _Units_ = ( Lat, Lon, Bearing)

113

114

115 class Distance2Tuple(_NamedTuple): # .datum.py, .ellipsoidalBase.py

116 '''2-Tuple C{(distance, initial)}, C{distance} in C{meter} and

117 C{initial} bearing in compass C{degrees360}.

118 '''

119 _Names_ = (_distance_, _initial_)

120 _Units_ = ( Meter, Bearing)

121

122

123 class Distance3Tuple(_NamedTuple): # .ellipsoidalKarney.py, -Vincenty.py

124 '''3-Tuple C{(distance, initial, final)}, C{distance} in C{meter}

125 and C{initial} and C{final} bearing, both in compass C{degrees360}.

126 '''

127 _Names_ = (_distance_, _initial_, _final_)

128 _Units_ = ( Meter, Bearing, Bearing)

129

130

131 class Distance4Tuple(_NamedTuple): # .formy.py, .points.py

132 '''4-Tuple C{(distance2, delta_lat, delta_lon, unroll_lon2)} with

133 the distance in C{degrees squared}, the latitudinal C{delta_lat

134 = B{lat2} - B{lat1}}, the wrapped, unrolled and adjusted

135 longitudinal C{delta_lon = B{lon2} - B{lon1}} and C{unroll_lon2},

136 the unrolled or original B{C{lon2}}.

137

138 @note: Use Function L{pygeodesy.degrees2m} to convert C{degrees

139 squared} to C{meter} as M{degrees2m(sqrt(distance2), ...)}

140 or M{degrees2m(hypot(delta_lat, delta_lon), ...)}.

141 '''

142 _Names_ = ('distance2', 'delta_lat', 'delta_lon', 'unroll_lon2')

143 _Units_ = ( Degrees2, Degrees, Degrees, Degrees)

144

145

146 class EasNor2Tuple(_NamedTuple): # .css, .osgr, .ups, .utm, .utmupsBase

147 '''2-Tuple C{(easting, northing)}, both in C{meter}, conventionally.

148 '''

149 _Names_ = (_easting_, _northing_)

150 _Units_ = ( Easting, Northing)

151

152

153 class EasNor3Tuple(_NamedTuple): # .css.py, .lcc.py

154 '''3-Tuple C{(easting, northing, height)}, all in C{meter}, conventionally.

155 '''

156 _Names_ = (_easting_, _northing_, _height_)

157 _Units_ = ( Easting, Northing, Height)

158

159

160 class _Convergence(object):

161 '''(INTERNAL) DEPRECATED Property C{convergence}, use property C{gamma}.'''

162 @deprecated_property_RO

163 def convergence(self):

164 '''DEPRECATED, use property C{gamma}.

165 '''

166 return self.gamma # PYCHOK self[.]

167

168

169 class Forward4Tuple(_NamedTuple, _Convergence):

170 '''4-Tuple C{(easting, northing, gamma, scale)} in

171 C{meter}, C{meter}, meridian convergence C{gamma} at

172 point in C{degrees} and the C{scale} of projection

173 at point C{scalar}.

174 '''

175 _Names_ = (_easting_, _northing_, _gamma_, _scale_)

176 _Units_ = ( Easting, Northing, Degrees, Scalar)

177

178

179 class Intersection3Tuple(_NamedTuple): # .css.py, .lcc.py

180 '''3-Tuple C{(point, outside1, outside2)} of an intersection

181 C{point} and C{outside1}, the position of the C{point},

182 C{-1} if before the start, C{+1} if after the end and C{0}

183 if on or between the start and end point of the first line.

184 Similarly, C{outside2} is C{-2}, C{+2} or C{0} to indicate

185 the position of C{point} on the second line or path. If a

186 path was specified with an initial bearing instead of an

187 end point, C{outside1} and/or C{outside2} will be C{0} if

188 the intersection C{point} is on the start point or C{+1}

189 respectively C{+2} if the intersection C{point} is after

190 the start point, in the direction of the bearing.

191 '''

192 _Names_ = (_point_, _outside_ + _1_, _outside_ + _2_)

193 _Units_ = (_Pass, Int, Int)

194

195

196 class LatLon2Tuple(_NamedTuple):

197 '''2-Tuple C{(lat, lon)} in C{degrees90} and C{degrees180}.

198 '''

199 _Names_ = (_lat_, _lon_)

200 _Units_ = ( Lat, Lon)

201

202 def to3Tuple(self, height):

203 '''Extend this L{LatLon2Tuple} to a L{LatLon3Tuple}.

204

205 @arg height: The height to add (C{scalar}).

206

207 @return: A L{LatLon3Tuple}C{(lat, lon, height)}.

208

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

210 '''

211 return self._xtend(LatLon3Tuple, height)

212

213 def to4Tuple(self, height, datum):

214 '''Extend this L{LatLon2Tuple} to a L{LatLon4Tuple}.

215

216 @arg height: The height to add (C{scalar}).

217 @arg datum: The datum to add (C{Datum}).

218

219 @return: A L{LatLon4Tuple}C{(lat, lon, height, datum)}.

220

221 @raise TypeError: If B{C{datum}} not a C{Datum}.

222

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

224 '''

225 return self.to3Tuple(height).to4Tuple(datum)

226

227

228 class LatLon3Tuple(_NamedTuple):

229 '''3-Tuple C{(lat, lon, height)} in C{degrees90}, C{degrees180}

230 and C{meter}, conventionally.

231 '''

232 _Names_ = (_lat_, _lon_, _height_)

233 _Units_ = ( Lat, Lon, Height)

234

235 def to4Tuple(self, datum):

236 '''Extend this L{LatLon3Tuple} to a L{LatLon4Tuple}.

237

238 @arg datum: The datum to add (C{Datum}).

239

240 @return: A L{LatLon4Tuple}C{(lat, lon, height, datum)}.

241

242 @raise TypeError: If B{C{datum}} not a C{Datum}.

243 '''

244 _xinstanceof(_MODS.datums.Datum, datum=datum)

245 return self._xtend(LatLon4Tuple, datum)

246

247

248 class LatLon4Tuple(LatLon3Tuple): # .cartesianBase.py, .css.py, .ecef.py, .lcc.py

249 '''4-Tuple C{(lat, lon, height, datum)} in C{degrees90},

250 C{degrees180}, C{meter} and L{Datum}.

251 '''

252 _Names_ = (_lat_, _lon_, _height_, _datum_)

253 _Units_ = ( Lat, Lon, Height, _Pass)

254

255

256 def _LL4Tuple(lat, lon, height, datum, LatLon, LatLon_kwds, inst=None,

257 iteration=None, name=NN):

258 '''(INTERNAL) Return a L{LatLon4Tuple} or a B{C{LatLon}} instance.

259 '''

260 if LatLon is None: # ignore LatLon_kwds

261 r = LatLon4Tuple(lat, lon, height, datum, name=name)

262 else:

263 kwds = {} if inst is None else _xkwds_not(None,

264# datum=_xattr(inst, datum=None),

265 epoch=_xattr(inst, epoch=None),

266 reframe=_xattr(inst, reframe=None)) # PYCHOK indent

267 kwds.update(datum=datum, height=height, name=name)

268 if LatLon_kwds:

269 kwds.update(LatLon_kwds)

270 r = LatLon(lat, lon, **kwds)

271 if iteration is not None: # like .named._namedTuple.__new__

272 r._iteration = iteration

273 return r

274

275

276 class LatLonDatum3Tuple(_NamedTuple): # .lcc.py, .osgr.py

277 '''3-Tuple C{(lat, lon, datum)} in C{degrees90}, C{degrees180}

278 and L{Datum}.

279 '''

280 _Names_ = (_lat_, _lon_, _datum_)

281 _Units_ = ( Lat, Lon, _Pass)

282

283

284 class LatLonDatum5Tuple(LatLonDatum3Tuple, _Convergence): # .ups.py, .utm.py, .utmupsBase.py

285 '''5-Tuple C{(lat, lon, datum, gamma, scale)} in C{degrees90},

286 C{degrees180}, L{Datum}, C{degrees} and C{float}.

287 '''

288 _Names_ = LatLonDatum3Tuple._Names_ + (_gamma_, _scale_)

289 _Units_ = LatLonDatum3Tuple._Units_ + ( Degrees, Scalar)

290

291

292 class LatLonPrec3Tuple(_NamedTuple): # .gars.py, .wgrs.py

293 '''3-Tuple C{(lat, lon, precision)} in C{degrees}, C{degrees}

294 and C{int}.

295 '''

296 _Names_ = (_lat_, _lon_, _precision_)

297 _Units_ = ( Lat, Lon, Precision_)

298

299 def to5Tuple(self, height, radius):

300 '''Extend this L{LatLonPrec3Tuple} to a L{LatLonPrec5Tuple}.

301

302 @arg height: The height to add (C{float} or C{None}).

303 @arg radius: The radius to add (C{float} or C{None}).

304

305 @return: A L{LatLonPrec5Tuple}C{(lat, lon, precision,

306 height, radius)}.

307 '''

308 return self._xtend(LatLonPrec5Tuple, height, radius)

309

310

311 class LatLonPrec5Tuple(LatLonPrec3Tuple): # .wgrs.py

312 '''5-Tuple C{(lat, lon, precision, height, radius)} in C{degrees},

313 C{degrees}, C{int} and C{height} or C{radius} in C{meter} (or

314 C{None} if missing).

315 '''

316 _Names_ = LatLonPrec3Tuple._Names_ + (_height_, _radius_)

317 _Units_ = LatLonPrec3Tuple._Units_ + ( Height, Radius)

318

319

320 class NearestOn2Tuple(_NamedTuple): # .ellipsoidalBaseDI.py

321 '''2-Tuple C{(closest, fraction)} of the C{closest} point

322 on and C{fraction} along a line (segment) between two

323 points. The C{fraction} is C{0} if the closest point

324 is the first or C{1} the second of the two points.

325 Negative C{fraction}s indicate the closest point is

326 C{before} the first point. For C{fraction > 1.0}

327 the closest point is after the second point.

328 '''

329 _Names_ = (_closest_, _fraction_)

330 _Units_ = (_Pass, _Pass)

331

332

333 class NearestOn3Tuple(_NamedTuple): # .points.py, .sphericalTrigonometry.py

334 '''3-Tuple C{(closest, distance, angle)} of the C{closest}

335 point on the polygon, either a C{LatLon} instance or a

336 L{LatLon3Tuple}C{(lat, lon, height)} and the C{distance}

337 and C{angle} to the C{closest} point are in C{meter}

338 respectively compass C{degrees360}.

339 '''

340 _Names_ = (_closest_, _distance_, _angle_)

341 _Units_ = (_Pass, Meter, Degrees)

342

343

344 class NearestOn4Tuple(_NamedTuple):

345 '''4-Tuple C{(lat, lon, distance, normal)} with the C{lat}- and

346 C{lon}gitude of the nearest point, the C{distance} in C{meter}

347 and the azimuth of the C{normal}, perpendicular line.

348 '''

349 _Names_ = (_lat_, _lon_, _distance_, _normal_)

350 _Units_ = ( Lat, Lon, Meter, Bearing)

351

352

353 class NearestOn5Tuple(_NamedTuple):

354 '''5-Tuple C{(lat, lon, distance, angle, height)} all in C{degrees},

355 except C{height}. The C{distance} is the L{pygeodesy.equirectangular}

356 distance between the closest and the reference B{C{point}} in C{degrees}.

357 The C{angle} from the reference B{C{point}} to the closest point is in

358 compass C{degrees360}, see function L{pygeodesy.compassAngle}. The

359 C{height} is the (interpolated) height at the closest point in C{meter}

360 or C{0}.

361 '''

362 _Names_ = (_lat_, _lon_, _distance_, _angle_, _height_)

363 _Units_ = ( Lat, Lon, Degrees, Degrees, Meter)

364

365

366 class NearestOn6Tuple(_NamedTuple): # .latlonBase.py, .vector3d.py

367 '''6-Tuple C{(closest, distance, fi, j, start, end)} with the C{closest}

368 point, the C{distance} in C{meter}, conventionally and the C{start}

369 and C{end} point of the path or polygon edge. Fractional index C{fi}

370 (an L{FIx} instance) and index C{j} indicate the path or polygon edge

371 and the fraction along that edge with the C{closest} point. The

372 C{start} and C{end} points may differ from the given path or polygon

373 points at indices C{fi} respectively C{j}, when unrolled (C{wrap} is

374 C{True}). Also, the C{start} and/or C{end} point may be the same

375 instance as the C{closest} point, for example when the very first

376 path or polygon point is the nearest.

377 '''

378 _Names_ = (_closest_, _distance_, _fi_, _j_, _start_, _end_)

379 _Units_ = (_Pass, Meter, FIx, Number_, _Pass , _Pass)

380

381

382 class NearestOn8Tuple(_NamedTuple): # .ellipsoidalBaseDI.py

383 '''8-Tuple C{(closest, distance, fi, j, start, end, initial, final)},

384 like L{NearestOn6Tuple} but extended with the C{initial} and the

385 C{final} bearing at the reference respectively the C{closest}

386 point, both in compass C{degrees}.

387 '''

388 _Names_ = NearestOn6Tuple._Names_ + Distance3Tuple._Names_[-2:]

389 _Units_ = NearestOn6Tuple._Units_ + Distance3Tuple._Units_[-2:]

390

391

392 class PhiLam2Tuple(_NamedTuple): # .frechet.py, .hausdorff.py, .latlonBase.py, .points.py, .vector3d.py

393 '''2-Tuple C{(phi, lam)} with latitude C{phi} in C{radians[PI_2]}

394 and longitude C{lam} in C{radians[PI]}.

395

396 @note: Using C{phi/lambda} for lat-/longitude in C{radians}

397 follows Chris Veness' U{convention

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

399 '''

400 _Names_ = (_phi_, _lam_)

401 _Units_ = ( Phi, Lam)

402

403 def to3Tuple(self, height):

404 '''Extend this L{PhiLam2Tuple} to a L{PhiLam3Tuple}.

405

406 @arg height: The height to add (C{scalar}).

407

408 @return: A L{PhiLam3Tuple}C{(phi, lam, height)}.

409

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

411 '''

412 return self._xtend(PhiLam3Tuple, height)

413

414 def to4Tuple(self, height, datum):

415 '''Extend this L{PhiLam2Tuple} to a L{PhiLam4Tuple}.

416

417 @arg height: The height to add (C{scalar}).

418 @arg datum: The datum to add (C{Datum}).

419

420 @return: A L{PhiLam4Tuple}C{(phi, lam, height, datum)}.

421

422 @raise TypeError: If B{C{datum}} not a C{Datum}.

423

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

425 '''

426 return self.to3Tuple(height).to4Tuple(datum)

427

428

429 class PhiLam3Tuple(_NamedTuple): # .nvector.py, extends -2Tuple

430 '''3-Tuple C{(phi, lam, height)} with latitude C{phi} in

431 C{radians[PI_2]}, longitude C{lam} in C{radians[PI]} and

432 C{height} in C{meter}.

433

434 @note: Using C{phi/lambda} for lat-/longitude in C{radians}

435 follows Chris Veness' U{convention

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

437 '''

438 _Names_ = (_phi_, _lam_, _height_)

439 _Units_ = ( Phi, Lam, Height)

440

441 def to4Tuple(self, datum):

442 '''Extend this L{PhiLam3Tuple} to a L{PhiLam4Tuple}.

443

444 @arg datum: The datum to add (C{Datum}).

445

446 @return: A L{PhiLam4Tuple}C{(phi, lam, height, datum)}.

447

448 @raise TypeError: If B{C{datum}} not a C{Datum}.

449 '''

450 _xinstanceof(_MODS.datums.Datum, datum=datum)

451 return self._xtend(PhiLam4Tuple, datum)

452

453

454 class PhiLam4Tuple(_NamedTuple): # extends -3Tuple

455 '''4-Tuple C{(phi, lam, height, datum)} with latitude C{phi} in

456 C{radians[PI_2]}, longitude C{lam} in C{radians[PI]}, C{height}

457 in C{meter} and L{Datum}.

458

459 @note: Using C{phi/lambda} for lat-/longitude in C{radians}

460 follows Chris Veness' U{convention

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

462 '''

463 _Names_ = (_phi_, _lam_, _height_, _datum_)

464 _Units_ = ( Phi, Lam, Height, _Pass)

465

466

467 class Point3Tuple(_NamedTuple):

468 '''3-Tuple C{(x, y, ll)} in C{meter}, C{meter} and C{LatLon}.

469 '''

470 _Names_ = (_x_, _y_, _elel_)

471 _Units_ = ( Meter, Meter, _Pass)

472

473

474 class Points2Tuple(_NamedTuple): # .formy.py, .latlonBase.py

475 '''2-Tuple C{(number, points)} with the C{number} of points

476 and -possible reduced- C{list} or C{tuple} of C{points}.

477 '''

478 _Names_ = (_number_, _points_)

479 _Units_ = ( Number_, _Pass)

480

481

482 class Reverse4Tuple(_NamedTuple, _Convergence):

483 '''4-Tuple C{(lat, lon, gamma, scale)} with C{lat}- and

484 C{lon}gitude in C{degrees}, meridian convergence C{gamma}

485 at point in C{degrees} and the C{scale} of projection at

486 point C{scalar}.

487 '''

488 _Names_ = (_lat_, _lon_, _gamma_, _scale_)

489 _Units_ = ( Lat, Lon, Degrees, Scalar)

490

491

492 class Triangle7Tuple(_NamedTuple):

493 '''7-Tuple C{(A, a, B, b, C, c, area)} with interior angles C{A},

494 C{B} and C{C} in C{degrees}, spherical sides C{a}, C{b} and C{c}

495 in C{meter} conventionally and the C{area} of a (spherical)

496 triangle in I{square} C{meter} conventionally.

497 '''

498 _Names_ = (_A_, _a_, _B_, _b_, _C_, _c_, _area_)

499 _Units_ = ( Degrees, Meter, Degrees, Meter, Degrees, Meter, Meter2)

500

501

502 class Triangle8Tuple(_NamedTuple):

503 '''8-Tuple C{(A, a, B, b, C, c, D, E)} with interior angles C{A},

504 C{B} and C{C}, spherical sides C{a}, C{b} and C{c}, the I{spherical

505 deficit} C{D} and the I{spherical excess} C{E} of a (spherical)

506 triangle, all in C{radians}.

507 '''

508 _Names_ = (_A_, _a_, _B_, _b_, _C_, _c_, _D_, _E_)

509 _Units_ = ( Radians, Radians, Radians, Radians, Radians, Radians, Radians, Radians)

510

511

512 class Trilaterate5Tuple(_NamedTuple): # .latlonBase.py, .nvector.py

513 '''5-Tuple C{(min, minPoint, max, maxPoint, n)} with C{min} and C{max}

514 in C{meter}, the corresponding trilaterated C{minPoint} and C{maxPoint}

515 as C{LatLon} and the number C{n}. For area overlap, C{min} and C{max}

516 are the smallest respectively largest overlap found. For perimeter

517 intersection, C{min} and C{max} represent the closest respectively

518 farthest intersection margin. Count C{n} is the total number of

519 trilaterated overlaps or intersections found, C{0, 1, 2...6} with

520 C{0} meaning concentric.

521

522 @see: The C{ellipsoidalKarney-}, C{ellipsoidalVincenty-} and

523 C{sphericalTrigonometry.LatLon.trilaterate5} method for further

524 details on corner cases, like concentric or single trilaterated

525 results.

526 '''

527 _Names_ = (min.__name__, 'minPoint', max.__name__, 'maxPoint', _n_)

528 _Units_ = (Meter, _Pass, Meter, _Pass, Number_)

529

530

531 class UtmUps2Tuple(_NamedTuple): # .epsg.py

532 '''2-Tuple C{(zone, hemipole)} as C{int} and C{str}, where

533 C{zone} is C{1..60} for UTM or C{0} for UPS and C{hemipole}

534 C{'N'|'S'} is the UTM hemisphere or the UPS pole.

535 '''

536 _Names_ = (_zone_, _hemipole_)

537 _Units_ = ( Number_, Str)

538

539

540 class UtmUps5Tuple(_NamedTuple): # .mgrs.py, .ups.py, .utm.py, .utmups.py

541 '''5-Tuple C{(zone, hemipole, easting, northing, band)} as C{int},

542 C{str}, C{meter}, C{meter} and C{band} letter, where C{zone} is

543 C{1..60} for UTM or C{0} for UPS, C{hemipole} C{'N'|'S'} is the UTM

544 hemisphere or the UPS pole and C{band} is C{""} or the I{longitudinal}

545 UTM band C{'C'|'D'|..|'W'|'X'} or I{polar} UPS band C{'A'|'B'|'Y'|'Z'}.

546 '''

547 _Names_ = (_zone_, _hemipole_, _easting_, _northing_, _band_)

548 _Units_ = ( Number_, Str, Easting, Northing, Band)

549

550 def __new__(cls, z, h, e, n, B, Error=None, name=NN):

551 if Error is not None:

552 e = Easting( e, Error=Error)

553 n = Northing(n, Error=Error)

554 return _NamedTuple.__new__(cls, z, h, e, n, B, name=name)

555

556

557 class UtmUps8Tuple(_NamedTuple, _Convergence): # .ups.py, .utm.py, .utmups.py

558 '''8-Tuple C{(zone, hemipole, easting, northing, band, datum,

559 gamma, scale)} as C{int}, C{str}, C{meter}, C{meter}, C{band}

560 letter, C{Datum}, C{degrees} and C{scalar}, where C{zone} is

561 C{1..60} for UTM or C{0} for UPS, C{hemipole} C{'N'|'S'} is

562 the UTM hemisphere or the UPS pole and C{band} is C{""} or

563 the I{longitudinal} UTM band C{'C'|'D'|..|'W'|'X'} or

564 I{polar} UPS band C{'A'|'B'|'Y'|'Z'}.

565 '''

566 _Names_ = (_zone_, _hemipole_, _easting_, _northing_,

567 _band_, _datum_, _gamma_, _scale_)

568 _Units_ = ( Number_, Str, Easting, Northing,

569 Band, _Pass, Degrees, Scalar)

570

571 def __new__(cls, z, h, e, n, B, d, g, s, Error=None, name=NN): # PYCHOK 11 args

572 if Error is not None:

573 e = Easting( e, Error=Error)

574 n = Northing(n, Error=Error)

575 g = Degrees(gamma=g, Error=Error)

576 s = Scalar(scale=s, Error=Error)

577 return _NamedTuple.__new__(cls, z, h, e, n, B, d, g, s, name=name)

578

579

580 class UtmUpsLatLon5Tuple(_NamedTuple): # .ups.py, .utm.py, .utmups.py

581 '''5-Tuple C{(zone, band, hemipole, lat, lon)} as C{int},

582 C{str}, C{str}, C{degrees90} and C{degrees180}, where

583 C{zone} is C{1..60} for UTM or C{0} for UPS, C{band} is

584 C{""} or the I{longitudinal} UTM band C{'C'|'D'|..|'W'|'X'}

585 or I{polar} UPS band C{'A'|'B'|'Y'|'Z'} and C{hemipole}

586 C{'N'|'S'} is the UTM hemisphere or the UPS pole.

587 '''

588 _Names_ = (_zone_, _band_, _hemipole_, _lat_, _lon_)

589 _Units_ = ( Number_, Band, Str, Lat, Lon)

590

591 def __new__(cls, z, B, h, lat, lon, Error=None, name=NN):

592 if Error is not None:

593 lat = Lat(lat, Error=Error)

594 lon = Lon(lon, Error=Error)

595 return _NamedTuple.__new__(cls, z, B, h, lat, lon, name=name)

596

597

598 class Vector2Tuple(_NamedTuple):

599 '''2-Tuple C{(x, y)} of (geocentric) components, each in

600 C{meter} or the same C{units}.

601 '''

602 _Names_ = (_x_, _y_)

603 _Units_ = ( Scalar, Scalar)

604

605 def to3Tuple(self, z=INT0):

606 '''Extend this L{Vector2Tuple} to a L{Vector3Tuple}.

607

608 @kwarg z: The Z component add (C{scalar}).

609

610 @return: A L{Vector3Tuple}C{(x, y, z)}.

611

612 @raise ValueError: Invalid B{C{z}}.

613 '''

614 return self._xtend(Vector3Tuple, z)

615

616

617 class Vector3Tuple(_NamedTuple):

618 '''3-Tuple C{(x, y, z)} of (geocentric) components, all in

619 C{meter} or the same C{units}.

620 '''

621 _Names_ = (_x_, _y_, _z_)

622 _Units_ = ( Scalar, Scalar, Scalar)

623

624 def to4Tuple(self, h):

625 '''Extend this L{Vector3Tuple} to a L{Vector4Tuple}.

626

627 @arg h: The height to add (C{scalar}).

628

629 @return: A L{Vector4Tuple}C{(x, y, z, h)}.

630

631 @raise ValueError: Invalid B{C{h}}.

632 '''

633 return self._xtend(Vector4Tuple, h)

634

635 @property_RO

636 def xyz(self):

637 '''Get X, Y and Z components (C{Vector3Tuple}).

638 '''

639 return self

640

641

642 class Vector4Tuple(_NamedTuple): # .nvector.py

643 '''4-Tuple C{(x, y, z, h)} of (geocentric) components, all

644 in C{meter} or the same C{units}.

645 '''

646 _Names_ = (_x_, _y_, _z_, _h_)

647 _Units_ = ( Scalar, Scalar, Scalar, Height)

648

649 def to3Tuple(self):

650 '''Reduce this L{Vector4Tuple} to a L{Vector3Tuple}.

651

652 @return: A L{Vector3Tuple}C{(x, y, z)}.

653 '''

654 return self.xyz

655

656 @property_RO

657 def xyz(self):

658 '''Get X, Y and Z components (L{Vector3Tuple}).

659 '''

660 return Vector3Tuple(*self[:3])

661

662# **) MIT License

663#

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

665#

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

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

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

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

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

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

672#

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

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

675#

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

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

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

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

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

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

682# OTHER DEALINGS IN THE SOFTWARE.

683

684# % env PYGEODESY_FOR_DOCS=1 python -m pygeodesy.named

685# all 71 locals OK