1

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

3

4 u'''(INTERNAL) Private base classes for elliposiodal, spherical and N-/vectorial

5 C{Cartesian}s.

6

7 After I{(C) Chris Veness 2011-2015} published under the same MIT Licence**,

8 see U{https://www.Movable-Type.co.UK/scripts/latlong.html},

9 U{https://www.Movable-Type.co.UK/scripts/latlong-vectors.html} and

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

11'''

12

13# from pygeodesy.basics import _xinstanceof # from .datums

14 from pygeodesy.constants import EPS, EPS0, isnear0, _1_0, _N_1_0, \

15 _2_0, _4_0, _6_0

16 from pygeodesy.datums import Datum, _earth_ellipsoid, _spherical_datum, \

17 _WGS84, _xinstanceof

18 from pygeodesy.errors import _IsnotError, _ValueError, _xdatum, _xkwds

19 from pygeodesy.fmath import cbrt, hypot_, hypot2, sqrt # hypot

20 from pygeodesy.fsums import Fmt, fsumf_

21 from pygeodesy.interns import NN, _COMMASPACE_, _height_, _not_

22 from pygeodesy.interns import _ellipsoidal_, _spherical_ # PYCHOK used!

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

24 from pygeodesy.namedTuples import LatLon4Tuple, Vector4Tuple, \

25 Bearing2Tuple # PYCHOK .sphericalBase

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

27 property_doc_, property_RO, _update_all

28# from pygeodesy.resections impoty cassini, collins5, pierlot, tienstra7

29# from pygeodesy.streprs import Fmt # from .fsums

30 from pygeodesy.units import Height, _heigHt

31 from pygeodesy.vector3d import Vector3d, _xyzhdn3

32

33# from math import sqrt # from .fmath

34

35__all__ = _ALL_LAZY.cartesianBase

36__version__ = '23.11.18'

37

38

39 class CartesianBase(Vector3d):

40 '''(INTERNAL) Base class for ellipsoidal and spherical C{Cartesian}.

41 '''

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

43 _height = None # height (L{Height}), set or approximated

44

45 def __init__(self, x_xyz, y=None, z=None, datum=None, ll=None, name=NN):

46 '''New C{Cartesian...}.

47

48 @arg x_xyz: Cartesian X coordinate (C{scalar}) or a C{Cartesian},

49 L{Ecef9Tuple}, L{Vector3Tuple} or L{Vector4Tuple}.

50 @kwarg y: Cartesian Y coordinate (C{scalar}), ignored if B{C{x_xyz}}

51 is not C{scalar}, otherwise same units as B{C{x_xyz}}.

52 @kwarg z: Cartesian Z coordinate (C{scalar}), ignored if B{C{x_xyz}}

53 is not C{scalar}, otherwise same units as B{C{x_xyz}}.

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

55 or L{a_f2Tuple}).

56 @kwarg ll: Optional, original latlon (C{LatLon}).

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

58

59 @raise TypeError: Non-scalar B{C{x_xyz}}, B{C{y}} or B{C{z}}

60 coordinate or B{C{x_xyz}} not an L{Ecef9Tuple},

61 L{Vector3Tuple} or L{Vector4Tuple}.

62 '''

63 h, d, n = _xyzhdn3(x_xyz, None, datum, ll)

64 Vector3d.__init__(self, x_xyz, y=y, z=z, ll=ll, name=name or n)

65 if h is not None:

66 self._height = Height(h)

67 if d is not None:

68 self.datum = d

69

70# def __matmul__(self, other): # PYCHOK Python 3.5+

71# '''Return C{NotImplemented} for C{c_ = c @ datum} and C{c_ = c @ transform}.

72# '''

73# return NotImplemented if isinstance(other, (Datum, Transform)) else \

74# _NotImplemented(self, other)

75

76 def cassini(self, pointB, pointC, alpha, beta, useZ=False):

77 '''3-Point resection between this and 2 other points using U{Cassini

78 <https://NL.WikiPedia.org/wiki/Achterwaartse_insnijding>}'s method.

79

80 @arg pointB: Second point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple},

81 C{Vector4Tuple} or C{Vector2Tuple} if C{B{useZ}=False}).

82 @arg pointC: Center point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple},

83 C{Vector4Tuple} or C{Vector2Tuple} if C{B{useZ}=False}).

84 @arg alpha: Angle subtended by triangle side C{b} from B{C{pointA}} to

85 B{C{pointC}} (C{degrees}, non-negative).

86 @arg beta: Angle subtended by triangle side C{a} from B{C{pointB}} to

87 B{C{pointC}} (C{degrees}, non-negative).

88 @kwarg useZ: If C{True}, use and interpolate the Z component, otherwise

89 force C{z=INT0} (C{bool}).

90

91 @note: Typically, B{C{pointC}} is between this and B{C{pointB}}.

92

93 @return: The survey point, an instance of this (sub-)class.

94

95 @raise ResectionError: Near-coincident, -colinear or -concyclic points

96 or negative or invalid B{C{alpha}} or B{C{beta}}.

97

98 @raise TypeError: Invalid B{C{pointA}}, B{C{pointB}} or B{C{pointM}}.

99

100 @see: Function L{pygeodesy.cassini} for references and more details.

101 '''

102 return _MODS.resections.cassini(self, pointB, pointC, alpha, beta,

103 useZ=useZ, datum=self.datum)

104

105 @deprecated_method

106 def collins(self, pointB, pointC, alpha, beta, useZ=False):

107 '''DEPRECATED, use method L{collins5}.'''

108 return self.collins5(pointB, pointC, alpha, beta, useZ=useZ)

109

110 def collins5(self, pointB, pointC, alpha, beta, useZ=False):

111 '''3-Point resection between this and 2 other points using U{Collins<https://Dokumen.tips/

112 documents/three-point-resection-problem-introduction-kaestner-burkhardt-method.html>}' method.

113

114 @arg pointB: Second point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple},

115 C{Vector4Tuple} or C{Vector2Tuple} if C{B{useZ}=False}).

116 @arg pointC: Center point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple},

117 C{Vector4Tuple} or C{Vector2Tuple} if C{B{useZ}=False}).

118 @arg alpha: Angle subtended by triangle side C{b} from B{C{pointA}} to

119 B{C{pointC}} (C{degrees}, non-negative).

120 @arg beta: Angle subtended by triangle side C{a} from B{C{pointB}} to

121 B{C{pointC}} (C{degrees}, non-negative).

122 @kwarg useZ: If C{True}, use and interpolate the Z component, otherwise

123 force C{z=INT0} (C{bool}).

124

125 @note: Typically, B{C{pointC}} is between this and B{C{pointB}}.

126

127 @return: L{Collins5Tuple}C{(pointP, pointH, a, b, c)} with survey C{pointP},

128 auxiliary C{pointH}, each an instance of this (sub-)class and

129 triangle sides C{a}, C{b} and C{c}.

130

131 @raise ResectionError: Near-coincident, -colinear or -concyclic points

132 or negative or invalid B{C{alpha}} or B{C{beta}}.

133

134 @raise TypeError: Invalid B{C{pointB}} or B{C{pointM}}.

135

136 @see: Function L{pygeodesy.collins5} for references and more details.

137 '''

138 return _MODS.resections.collins5(self, pointB, pointC, alpha, beta,

139 useZ=useZ, datum=self.datum)

140

141 @property_doc_(''' this cartesian's datum (L{Datum}).''')

142 def datum(self):

143 '''Get this cartesian's datum (L{Datum}).

144 '''

145 return self._datum

146

147 @datum.setter # PYCHOK setter!

148 def datum(self, datum):

149 '''Set this cartesian's C{datum} I{without conversion}

150 (L{Datum}), ellipsoidal or spherical.

151

152 @raise TypeError: The B{C{datum}} is not a L{Datum}.

153 '''

154 d = _spherical_datum(datum, name=self.name)

155 if self._datum: # is not None

156 if d.isEllipsoidal and not self._datum.isEllipsoidal:

157 raise _IsnotError(_ellipsoidal_, datum=datum)

158 elif d.isSpherical and not self._datum.isSpherical:

159 raise _IsnotError(_spherical_, datum=datum)

160 if self._datum != d:

161 _update_all(self)

162 self._datum = d

163

164 def destinationXyz(self, delta, Cartesian=None, **Cartesian_kwds):

165 '''Calculate the destination using a I{local} delta from this cartesian.

166

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

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

169 @kwarg Cartesian: Optional (geocentric) class to return the

170 destination or C{None}.

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

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

173

174 @return: Destination as a C{B{Cartesian}(x, y, z, **B{Cartesian_kwds})}

175 instance or if C{B{Cartesian} is None}, an L{Ecef9Tuple}C{(x, y,

176 z, lat, lon, height, C, M, datum)} with C{M=None} always.

177

178 @raise TypeError: Invalid B{C{delta}}, B{C{Cartesian}} or

179 B{C{Cartesian_kwds}}.

180 '''

181 if Cartesian is None:

182 r = self._ltp._local2ecef(delta, nine=True)

183 else:

184 r = self._ltp._local2ecef(delta, nine=False)

185 r = Cartesian(*r, **_xkwds(Cartesian_kwds, datum=self.datum))

186 return r._xnamed(r) if self.name else r

187

188 @property_RO

189 def Ecef(self):

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

191 '''

192 CartesianBase.Ecef = E = _MODS.ecef.EcefKarney # overwrite property_RO

193 return E

194

195 @Property_RO

196 def _ecef9(self):

197 '''(INTERNAL) Helper for L{toEcef}, L{toLocal} and L{toLtp} (L{Ecef9Tuple}).

198 '''

199 return self.Ecef(self.datum, name=self.name).reverse(self, M=True)

200

201 @property_RO

202 def ellipsoidalCartesian(self):

203 '''Get the C{Cartesian type} iff ellipsoidal, overloaded in L{CartesianEllipsoidalBase}.

204 '''

205 return False

206

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

208 '''Compute the intersection of a Line-Of-Sight (los) from this cartesian

209 Point-Of-View (pov) with this cartesian's ellipsoid surface.

210

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

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

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

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

215 this cartesian's C{datum} ellipsoid.

216

217 @return: The ellipsoid intersection (C{Cartesian}) with C{.height} set

218 to the distance to this C{pov}.

219

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

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

222 points outside or away from the ellipsoid.

223

224 @raise TypeError: Invalid B{C{los}} or no B{C{datum}}.

225

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

227 '''

228 return _MODS.formy._hartzell(self, los, earth)

229

230 @Property

231 def height(self):

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

233 '''

234 return self._height4.h if self._height is None else self._height

235

236 @height.setter # PYCHOK setter!

237 def height(self, height):

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

239

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

241

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

243 '''

244 h = Height(height)

245 if self._height != h:

246 _update_all(self)

247 self._height = h

248

249 @Property_RO

250 def _height4(self):

251 '''(INTERNAL) Get this C{height4}-tuple.

252 '''

253 try:

254 r = self.datum.ellipsoid.height4(self, normal=True)

255 except (AttributeError, ValueError): # no datum, null cartesian,

256 r = Vector4Tuple(self.x, self.y, self.z, 0, name=self.height4.__name__)

257 return r

258

259 def height4(self, earth=None, normal=True, Cartesian=None, **Cartesian_kwds):

260 '''Compute the height of this cartesian above or below and the projection

261 on this datum's ellipsoid surface.

262

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

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

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

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

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

268 ellipsoid's surface, otherwise the intersection of the

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

270 @kwarg Cartesian: Optional class to return the height and projection

271 (C{Cartesian}) or C{None}.

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

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

274

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

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

277

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

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

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

281

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

283

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

285

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

287 '''

288 d = self.datum if earth is None else earth

289 if normal and d is self.datum:

290 r = self._height4

291 elif isinstance(d, _MODS.triaxials.Triaxial_):

292 r = d.height4(self, normal=normal)

293 else:

294 r = _earth_ellipsoid(d).height4(self, normal=normal)

295 if Cartesian is not None:

296 kwds = Cartesian_kwds.copy()

297 h = kwds.pop(_height_, None)

298 r = Cartesian(r, **kwds)

299 if h is not None:

300 r.height = Height(height=h)

301 return r

302

303 @Property_RO

304 def isEllipsoidal(self):

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

306 '''

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

308

309 @Property_RO

310 def isSpherical(self):

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

312 '''

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

314

315 @Property_RO

316 def latlon(self):

317 '''Get this cartesian's (geodetic) lat- and longitude in C{degrees} (L{LatLon2Tuple}C{(lat, lon)}).

318 '''

319 return self.toEcef().latlon

320

321 @Property_RO

322 def latlonheight(self):

323 '''Get this cartesian's (geodetic) lat-, longitude in C{degrees} with height (L{LatLon3Tuple}C{(lat, lon, height)}).

324 '''

325 return self.toEcef().latlonheight

326

327 @Property_RO

328 def latlonheightdatum(self):

329 '''Get this cartesian's (geodetic) lat-, longitude in C{degrees} with height and datum (L{LatLon4Tuple}C{(lat, lon, height, datum)}).

330 '''

331 return self.toEcef().latlonheightdatum

332

333 @Property_RO

334 def _ltp(self):

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

336 '''

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

338

339 @Property_RO

340 def _N_vector(self):

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

342 '''

343 x, y, z, h = self._n_xyzh4(self.datum)

344 return _MODS.nvectorBase._N_vector_(x, y, z, h=h, name=self.name)

345

346 def _n_xyzh4(self, datum):

347 '''(INTERNAL) Get the n-vector components as L{Vector4Tuple}.

348 '''

349 def _ErrorEPS0(x):

350 return _ValueError(origin=self, txt=Fmt.PARENSPACED(EPS0=x))

351

352 _xinstanceof(Datum, datum=datum)

353 # <https://www.Movable-Type.co.UK/scripts/geodesy/docs/

354 # latlon-nvector-ellipsoidal.js.html#line309>,

355 # <https://GitHub.com/pbrod/nvector>/src/nvector/core.py>

356 # _equation23 and <https://www.NavLab.net/nvector>

357 E = datum.ellipsoid

358 x, y, z = self.xyz

359

360 # Kenneth Gade eqn 23

361 p = hypot2(x, y) * E.a2_

362 q = z**2 * E.e21 * E.a2_

363 r = fsumf_(p, q, -E.e4) / _6_0

364 s = (p * q * E.e4) / (_4_0 * r**3)

365 t = cbrt(fsumf_(_1_0, s, sqrt(s * (_2_0 + s))))

366 if isnear0(t):

367 raise _ErrorEPS0(t)

368 u = fsumf_(_1_0, t, _1_0 / t) * r

369 v = sqrt(u**2 + E.e4 * q)

370 t = v * _2_0

371 if t < EPS0: # isnear0

372 raise _ErrorEPS0(t)

373 w = fsumf_(u, v, -q) * E.e2 / t

374 k = sqrt(fsumf_(u, v, w**2)) - w

375 if isnear0(k):

376 raise _ErrorEPS0(k)

377 t = k + E.e2

378 if isnear0(t):

379 raise _ErrorEPS0(t)

380 e = k / t

381# d = e * hypot(x, y)

382# tmp = 1 / hypot(d, z) == 1 / hypot(e * hypot(x, y), z)

383 t = hypot_(x * e, y * e, z) # == 1 / tmp

384 if t < EPS0: # isnear0

385 raise _ErrorEPS0(t)

386 h = fsumf_(k, E.e2, _N_1_0) / k * t

387 s = e / t # == e * tmp

388 return Vector4Tuple(x * s, y * s, z / t, h, name=self.name)

389

390 @Property_RO

391 def philam(self):

392 '''Get this cartesian's (geodetic) lat- and longitude in C{radians} (L{PhiLam2Tuple}C{(phi, lam)}).

393 '''

394 return self.toEcef().philam

395

396 @Property_RO

397 def philamheight(self):

398 '''Get this cartesian's (geodetic) lat-, longitude in C{radians} with height (L{PhiLam3Tuple}C{(phi, lam, height)}).

399 '''

400 return self.toEcef().philamheight

401

402 @Property_RO

403 def philamheightdatum(self):

404 '''Get this cartesian's (geodetic) lat-, longitude in C{radians} with height and datum (L{PhiLam4Tuple}C{(phi, lam, height, datum)}).

405 '''

406 return self.toEcef().philamheightdatum

407

408 def pierlot(self, point2, point3, alpha12, alpha23, useZ=False, eps=EPS):

409 '''3-Point resection between this and two other points using U{Pierlot

410 <http://www.Telecom.ULg.ac.Be/triangulation>}'s method C{ToTal} with

411 I{approximate} limits for the (pseudo-)singularities.

412

413 @arg point2: Second point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple},

414 C{Vector4Tuple} or C{Vector2Tuple} if C{B{useZ}=False}).

415 @arg point3: Third point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple},

416 C{Vector4Tuple} or C{Vector2Tuple} if C{B{useZ}=False}).

417 @arg alpha12: Angle subtended from this point to B{C{point2}} or

418 B{C{alpha2 - alpha}} (C{degrees}).

419 @arg alpha23: Angle subtended from B{C{point2}} to B{C{point3}} or

420 B{C{alpha3 - alpha2}} (C{degrees}).

421 @kwarg useZ: If C{True}, interpolate the Z component, otherwise use C{z=INT0}

422 (C{bool}).

423 @kwarg eps: Tolerance for C{cot} (pseudo-)singularities (C{float}).

424

425 @note: This point, B{C{point2}} and B{C{point3}} are ordered counter-clockwise.

426

427 @return: The survey (or robot) point, an instance of this (sub-)class.

428

429 @raise ResectionError: Near-coincident, -colinear or -concyclic points

430 or invalid B{C{alpha12}} or B{C{alpha23}}.

431

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

433

434 @see: Function L{pygeodesy.pierlot} for references and more details.

435 '''

436 return _MODS.resections.pierlot(self, point2, point3, alpha12, alpha23,

437 useZ=useZ, eps=eps, datum=self.datum)

438

439 def pierlotx(self, point2, point3, alpha1, alpha2, alpha3, useZ=False):

440 '''3-Point resection between this and two other points using U{Pierlot

441 <http://www.Telecom.ULg.ac.Be/publi/publications/pierlot/Pierlot2014ANewThree>}'s

442 method C{ToTal} with I{exact} limits for the (pseudo-)singularities.

443

444 @arg point2: Second point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple},

445 C{Vector4Tuple} or C{Vector2Tuple} if C{B{useZ}=False}).

446 @arg point3: Third point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple},

447 C{Vector4Tuple} or C{Vector2Tuple} if C{B{useZ}=False}).

448 @arg alpha1: Angle at B{C{point1}} (C{degrees}).

449 @arg alpha2: Angle at B{C{point2}} (C{degrees}).

450 @arg alpha3: Angle at B{C{point3}} (C{degrees}).

451 @kwarg useZ: If C{True}, interpolate the survey point's Z component,

452 otherwise use C{z=INT0} (C{bool}).

453

454 @return: The survey (or robot) point, an instance of this (sub-)class.

455

456 @raise ResectionError: Near-coincident, -colinear or -concyclic points or

457 invalid B{C{alpha1}}, B{C{alpha2}} or B{C{alpha3}}.

458

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

460

461 @see: Function L{pygeodesy.pierlotx} for references and more details.

462 '''

463 return _MODS.resections.pierlotx(self, point2, point3, alpha1, alpha2, alpha3,

464 useZ=useZ, datum=self.datum)

465

466 @property_RO

467 def sphericalCartesian(self):

468 '''Get the C{Cartesian type} iff spherical, overloaded in L{CartesianSphericalBase}.

469 '''

470 return False

471

472 @deprecated_method

473 def tienstra(self, pointB, pointC, alpha, beta=None, gamma=None, useZ=False):

474 '''DEPRECATED, use method L{tienstra7}.'''

475 return self.tienstra7(pointB, pointC, alpha, beta=beta, gamma=gamma, useZ=useZ)

476

477 def tienstra7(self, pointB, pointC, alpha, beta=None, gamma=None, useZ=False):

478 '''3-Point resection between this and two other points using U{Tienstra

479 <https://WikiPedia.org/wiki/Tienstra_formula>}'s formula.

480

481 @arg pointB: Second point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple}, C{Vector4Tuple} or

482 C{Vector2Tuple} if C{B{useZ}=False}).

483 @arg pointC: Third point (C{Cartesian}, L{Vector3d}, C{Vector3Tuple}, C{Vector4Tuple} or

484 C{Vector2Tuple} if C{B{useZ}=False}).

485 @arg alpha: Angle subtended by triangle side C{a} from B{C{pointB}} to B{C{pointC}} (C{degrees},

486 non-negative).

487 @kwarg beta: Angle subtended by triangle side C{b} from this to B{C{pointC}} (C{degrees},

488 non-negative) or C{None} if C{B{gamma} is not None}.

489 @kwarg gamma: Angle subtended by triangle side C{c} from this to B{C{pointB}} (C{degrees},

490 non-negative) or C{None} if C{B{beta} is not None}.

491 @kwarg useZ: If C{True}, use and interpolate the Z component, otherwise force C{z=INT0}

492 (C{bool}).

493

494 @note: This point, B{C{pointB}} and B{C{pointC}} are ordered clockwise.

495

496 @return: L{Tienstra7Tuple}C{(pointP, A, B, C, a, b, c)} with survey C{pointP},

497 an instance of this (sub-)class and triangle angle C{A} at this point,

498 C{B} at B{C{pointB}} and C{C} at B{C{pointC}} in C{degrees} and

499 triangle sides C{a}, C{b} and C{c}.

500

501 @raise ResectionError: Near-coincident, -colinear or -concyclic points or sum of

502 B{C{alpha}}, B{C{beta}} and B{C{gamma}} not C{360} or

503 negative B{C{alpha}}, B{C{beta}} or B{C{gamma}}.

504

505 @raise TypeError: Invalid B{C{pointB}} or B{C{pointC}}.

506

507 @see: Function L{pygeodesy.tienstra7} for references and more details.

508 '''

509 return _MODS.resections.tienstra7(self, pointB, pointC, alpha, beta, gamma,

510 useZ=useZ, datum=self.datum)

511

512 @deprecated_method

513 def to2ab(self): # PYCHOK no cover

514 '''DEPRECATED, use property C{philam}.

515

516 @return: A L{PhiLam2Tuple}C{(phi, lam)}.

517 '''

518 return self.philam

519

520 @deprecated_method

521 def to2ll(self): # PYCHOK no cover

522 '''DEPRECATED, use property C{latlon}.

523

524 @return: A L{LatLon2Tuple}C{(lat, lon)}.

525 '''

526 return self.latlon

527

528 @deprecated_method

529 def to3llh(self, datum=None): # PYCHOK no cover

530 '''DEPRECATED, use property L{latlonheightdatum} or L{latlonheight}.

531

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

533

534 @note: This method returns a B{C{-4Tuple}} I{and not a} C{-3Tuple}

535 as its name may suggest.

536 '''

537 t = self.toLatLon(datum=datum, LatLon=None)

538 return LatLon4Tuple(t.lat, t.lon, t.height, t.datum, name=self.name)

539

540# def _to3LLh(self, datum, LL, **pairs): # OBSOLETE

541# '''(INTERNAL) Helper for C{subclass.toLatLon} and C{.to3llh}.

542# '''

543# r = self.to3llh(datum) # LatLon3Tuple

544# if LL is not None:

545# r = LL(r.lat, r.lon, height=r.height, datum=datum, name=self.name)

546# for n, v in pairs.items():

547# setattr(r, n, v)

548# return r

549

550 def toDatum(self, datum2, datum=None):

551 '''Convert this cartesian from one datum to an other.

552

553 @arg datum2: Datum to convert I{to} (L{Datum}).

554 @kwarg datum: Datum to convert I{from} (L{Datum}).

555

556 @return: The converted point (C{Cartesian}).

557

558 @raise TypeError: B{C{datum2}} or B{C{datum}}

559 invalid.

560 '''

561 _xinstanceof(Datum, datum2=datum2)

562

563 c = self if datum in (None, self.datum) else \

564 self.toDatum(datum)

565

566 i, d = False, c.datum

567 if d == datum2:

568 return c.copy() if c is self else c

569

570 elif d == _WGS84:

571 d = datum2 # convert from WGS84 to datum2

572

573 elif datum2 == _WGS84:

574 i = True # convert to WGS84 by inverse transformation

575

576 else: # neither datum2 nor c.datum is WGS84, invert to WGS84 first

577 c = c.toTransform(d.transform, inverse=True, datum=_WGS84)

578 d = datum2

579

580 return c.toTransform(d.transform, inverse=i, datum=datum2)

581

582 convertDatum = toDatum # for backward compatibility

583

584 def toEcef(self):

585 '''Convert this cartesian to I{geodetic} (lat-/longitude) coordinates.

586

587 @return: An L{Ecef9Tuple}C{(x, y, z, lat, lon, height,

588 C, M, datum)} with C{C} and C{M} if available.

589

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

591 '''

592 return self._ecef9

593

594 def toLatLon(self, datum=None, height=None, LatLon=None, **LatLon_kwds): # see .ecef.Ecef9Tuple.toDatum

595 '''Convert this cartesian to a geodetic (lat-/longitude) point.

596

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

598 or L{a_f2Tuple}).

599 @kwarg height: Optional height, overriding the converted height

600 (C{meter}), iff B{C{LatLon}} is not C{None}.

601 @kwarg LatLon: Optional class to return the geodetic point

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

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

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

605

606 @return: The geodetic point (B{C{LatLon}}) or if B{C{LatLon}}

607 is C{None}, an L{Ecef9Tuple}C{(x, y, z, lat, lon,

608 height, C, M, datum)} with C{C} and C{M} if available.

609

610 @raise TypeError: Invalid B{C{datum}} or B{C{LatLon_kwds}}.

611 '''

612 d = _spherical_datum(datum or self.datum, name=self.name)

613 if d == self.datum:

614 r = self.toEcef()

615 else:

616 c = self.toDatum(d)

617 r = c.Ecef(d, name=self.name).reverse(c, M=LatLon is None)

618

619 if LatLon: # class or .classof

620 h = _heigHt(r, height)

621 r = LatLon(r.lat, r.lon, datum=r.datum, height=h,

622 **_xkwds(LatLon_kwds, name=r.name))

623 _xdatum(r.datum, d)

624 return r

625

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

627 '''Convert this I{geocentric} cartesian to I{local} C{X}, C{Y} and C{Z}.

628

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

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

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

632 overriding this cartesian's LTP (L{Ltp}).

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

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

635

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

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

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

639

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

641 '''

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

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

644

645 def toLtp(self, Ecef=None):

646 '''Return the I{local tangent plane} (LTP) for this cartesian.

647

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

649 L{EcefYou}), overriding this cartesian's C{Ecef}.

650 '''

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

652 self._ecef9, ecef=Ecef(self.datum), name=self.name)

653

654 def toNvector(self, Nvector=None, datum=None, **Nvector_kwds):

655 '''Convert this cartesian to C{n-vector} components.

656

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

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

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

660 or L{a_f2Tuple}) overriding this cartesian's datum.

661 @kwarg Nvector_kwds: Optional, additional B{C{Nvector}} keyword

662 arguments, ignored if C{B{Nvector} is None}.

663

664 @return: The C{unit, n-vector} components (B{C{Nvector}}) or a

665 L{Vector4Tuple}C{(x, y, z, h)} if B{C{Nvector}} is C{None}.

666

667 @raise TypeError: Invalid B{C{datum}}.

668

669 @raise ValueError: The B{C{Cartesian}} at origin.

670

671 @example:

672

673 >>> c = Cartesian(3980581, 97, 4966825)

674 >>> n = c.toNvector() # (x=0.622818, y=0.00002, z=0.782367, h=0.242887)

675 '''

676 d = _spherical_datum(datum or self.datum, name=self.name)

677 r = self._N_vector.xyzh if self.datum == d else self._n_xyzh4(d)

678

679 if Nvector is not None:

680 kwds = _xkwds(Nvector_kwds, h=r.h, datum=d)

681 r = self._xnamed(Nvector(r.x, r.y, r.z, **kwds))

682 return r

683

684 def toStr(self, prec=3, fmt=Fmt.SQUARE, sep=_COMMASPACE_): # PYCHOK expected

685 '''Return the string representation of this cartesian.

686

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

688 @kwarg fmt: Enclosing backets format (string).

689 @kwarg sep: Separator to join (string).

690

691 @return: Cartesian represented as "[x, y, z]" (string).

692 '''

693 return Vector3d.toStr(self, prec=prec, fmt=fmt, sep=sep)

694

695 def toTransform(self, transform, inverse=False, datum=None):

696 '''Return a new cartesian by applying a Helmert transform

697 to this cartesian.

698

699 @arg transform: Transform to apply (L{Transform}).

700 @kwarg inverse: Apply the inverse of the Helmert

701 transform (C{bool}).

702 @kwarg datum: Datum for the transformed cartesian (L{Datum}),

703 overriding this cartesian's datum.

704

705 @return: The transformed cartesian (C{Cartesian}).

706

707 @raise Valuerror: If C{B{inverse}=True} and B{C{datum}}

708 is not L{Datums}C{.WGS84}.

709 '''

710 d = datum or self.datum

711 if inverse and d != _WGS84:

712 raise _ValueError(inverse=inverse, datum=d,

713 txt=_not_(_WGS84.name))

714

715 xyz = transform.transform(*self.xyz, inverse=inverse)

716 return self.classof(xyz, datum=d)

717

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

719 '''Return this cartesian's components as vector.

720

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

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

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

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

725

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

727 B{C{Vector}} is C{None}.

728

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

730 '''

731 return self.xyz if Vector is None else self._xnamed(

732 Vector(self.x, self.y, self.z, **Vector_kwds))

733

734

735__all__ += _ALL_DOCS(CartesianBase)

736

737# **) MIT License

738#

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

740#

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

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

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

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

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

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

747#

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

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

750#

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

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

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

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

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

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

757# OTHER DEALINGS IN THE SOFTWARE.