Coverage for pygeodesy/ellipsoidalBase.py: 94%

262 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-04 12:01 -0400

1 

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

3 

4u'''(INTERNAL) Private ellipsoidal base classes C{CartesianEllipsoidalBase} 

5and C{LatLonEllipsoidalBase}. 

6 

7A pure Python implementation of geodesy tools for ellipsoidal earth models, 

8transcoded in part from JavaScript originals by I{(C) Chris Veness 2005-2024} 

9and published under the same MIT Licence**, see for example U{latlon-ellipsoidal 

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

11''' 

12# make sure int/int division yields float quotient, see .basics 

13from __future__ import division as _; del _ # PYCHOK semicolon 

14 

15# from pygeodesy.azimuthal import EquidistantExact, EquidistantKarney # _MODS 

16from pygeodesy.basics import _isin, _xinstanceof 

17from pygeodesy.constants import EPS, EPS0, EPS1, _0_0, _0_5 

18from pygeodesy.cartesianBase import CartesianBase # PYCHOK used! 

19# from pygeodesy.css import toCss # _MODS 

20from pygeodesy.datums import Datum, Datums, _earth_ellipsoid, _ellipsoidal_datum, \ 

21 Transform, _WGS84, _EWGS84 # _spherical_datum 

22# from pygeodesy.dms import parse3llh # _MODS 

23# from pygeodesy.elevations import elevation2, geoidHeight2 # _MODS 

24# from pygeodesy.ellipsoidalBaseDI import _intersect3, _intersections2, _nearestOn2 # _MODS 

25# from pygeodesy.ellipsoids import _EWGS84 # from .datums 

26from pygeodesy.errors import _IsnotError, RangeError, _TypeError, _xattr, _xellipsoidal, \ 

27 _xellipsoids, _xError, _xkwds, _xkwds_not 

28# from pygeodesy.etm import etm, toEtm8 # _MODS 

29# from pygeodesy.fmath import favg # _MODS 

30from pygeodesy.interns import NN, _COMMA_, _ellipsoidal_ 

31from pygeodesy.latlonBase import LatLonBase, _trilaterate5, fabs, _Wrap 

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

33# from pygeodesy.lcc import toLcc # _MODS 

34# from pygeodesy.namedTuples import Vector3Tuple # _MODS 

35# from pygeodesy.osgr import toOsgr # _MODS 

36# from pygeodesy.points import isenclosedBy # _MODS 

37from pygeodesy.props import deprecated_method, deprecated_property_RO, \ 

38 Property_RO, property_doc_, property_RO, _update_all 

39# from pygeodesy.trf import RefFrame, _toRefFrame # _MODS 

40from pygeodesy.units import Epoch, _isDegrees, Radius_, _1mm as _TOL_M 

41# from pygeodesy import ups, utm, utmups # MODS 

42# from pygeodesy.utmupsBase import _lowerleft # MODS 

43# from pygeodesy.utily import _Wrap # from .latlonBase 

44# from pygeodesy.vector3d import _intersects2 # _MODS 

45 

46# from math import fabs # from .latlonBase 

47 

48__all__ = _ALL_LAZY.ellipsoidalBase 

49__version__ = '25.04.14' 

50 

51 

52class CartesianEllipsoidalBase(CartesianBase): 

53 '''(INTERNAL) Base class for ellipsoidal C{Cartesian}s. 

54 ''' 

55 _datum = _WGS84 # L{Datum} 

56 _epoch = None # overriding .reframe.epoch (C{float}) 

57 _reframe = None # reference frame (L{RefFrame}) 

58 

59 def __init__(self, x_xyz, y=None, z=None, reframe=None, epoch=None, 

60 **datum_ll_name): 

61 '''New ellispoidal C{Cartesian...}. 

62 

63 @kwarg reframe: Optional reference frame (L{RefFrame}). 

64 @kwarg epoch: Optional epoch to observe for B{C{reframe}} (C{scalar}), 

65 a non-zero, fractional calendar year; silently ignored 

66 if C{B{reframe}=None}. 

67 

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

69 or B{C{x_xyz}} not a C{Cartesian} L{Ecef9Tuple}, 

70 L{Vector3Tuple} or L{Vector4Tuple} or B{C{datum}} is 

71 not a L{Datum}, B{C{reframe}} is not a L{RefFrame} or 

72 B{C{epoch}} is not C{scalar} non-zero. 

73 

74 @see: Class L{CartesianBase<CartesianBase.__init__>} for more details. 

75 ''' 

76 CartesianBase.__init__(self, x_xyz, y=y, z=z, **datum_ll_name) 

77 if reframe: 

78 self.reframe = reframe 

79 self.epoch = epoch 

80 

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

82# '''Return C{NotImplemented} for C{c_ = c @ datum}, C{c_ = c @ reframe} and C{c_ = c @ Transform}. 

83# ''' 

84# RefFrame = _MODS.trf.RefFrame 

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

86# _NotImplemented(self, other) 

87 

88 @deprecated_method 

89 def convertRefFrame(self, reframe2, reframe, epoch=None): 

90 '''DEPRECATED, use method L{toRefFrame}.''' 

91 return self.toRefFrame(reframe2, reframe=reframe, epoch=epoch) # PYCHOK no cover 

92 

93 @property_RO 

94 def ellipsoidalCartesian(self): 

95 '''Get this C{Cartesian}'s ellipsoidal class. 

96 ''' 

97 return type(self) 

98 

99 @property_doc_(''' this cartesian's observed or C{reframe} epoch (C{float}).''') 

100 def epoch(self): 

101 '''Get this cartesian's observed or C{reframe} epoch (C{Epoch}) or C{None}. 

102 ''' 

103 return self._epoch or (self.reframe.epoch if self.reframe else None) 

104 

105 @epoch.setter # PYCHOK setter! 

106 def epoch(self, epoch): 

107 '''Set or clear this cartesian's observed epoch, a fractional 

108 calendar year (L{Epoch}, C{scalar} or C{str}) or C{None}. 

109 

110 @raise TRFError: Invalid B{C{epoch}}. 

111 ''' 

112 self._epoch = None if epoch is None else Epoch(epoch) 

113 

114 def intersections2(self, radius, center2, radius2, sphere=True, 

115 Vector=None, **Vector_kwds): 

116 '''Compute the intersection of two spheres or circles, each defined by a 

117 cartesian center point and a radius. 

118 

119 @arg radius: Radius of this sphere or circle (same units as this point's 

120 coordinates). 

121 @arg center2: Center of the second sphere or circle (C{Cartesian}, L{Vector3d}, 

122 C{Vector3Tuple} or C{Vector4Tuple}). 

123 @arg radius2: Radius of the second sphere or circle (same units as this and 

124 the B{C{other}} point's coordinates). 

125 @kwarg sphere: If C{True}, compute the center and radius of the intersection 

126 of two I{spheres}. If C{False}, ignore the C{z}-component and 

127 compute the intersection of two I{circles} (C{bool}). 

128 @kwarg Vector: Class to return intersections (C{Cartesian}, L{Vector3d} or 

129 C{Vector3Tuple}) or C{None} for an instance of this (sub-)class. 

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

131 ignored if C{B{Vector} is None}. 

132 

133 @return: If C{B{sphere} is True}, a 2-tuple of the C{center} and C{radius} of 

134 the intersection of the I{spheres}. The C{radius} is C{0.0} for 

135 abutting spheres (and the C{center} is aka the I{radical center}). 

136 

137 If C{B{sphere} is False}, a 2-tuple with the two intersection points 

138 of the I{circles}. For abutting circles, both points are the same 

139 instance, aka the I{radical center}. 

140 

141 @raise IntersectionError: Concentric, invalid or non-intersecting spheres or circles. 

142 

143 @raise TypeError: Invalid B{C{center2}}. 

144 

145 @raise UnitError: Invalid B{C{radius}} or B{C{radius2}}. 

146 

147 @see: U{Sphere-Sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}, 

148 U{Circle-Circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} 

149 Intersection and function L{pygeodesy.radical2}. 

150 ''' 

151 try: 

152 return _MODS.vector3d._intersects2(self, Radius_(radius=radius), 

153 center2, Radius_(radius2=radius2), 

154 sphere=sphere, clas=self.classof, 

155 Vector=Vector, **Vector_kwds) 

156 except (TypeError, ValueError) as x: 

157 raise _xError(x, center=self, radius=radius, center2=center2, radius2=radius2) 

158 

159 @property_doc_(''' this cartesian's reference frame (L{RefFrame}).''') 

160 def reframe(self): 

161 '''Get this cartesian's reference frame (L{RefFrame}) or C{None}. 

162 ''' 

163 return self._reframe 

164 

165 @reframe.setter # PYCHOK setter! 

166 def reframe(self, reframe): 

167 '''Set or clear this cartesian's reference frame (L{RefFrame}) or C{None}. 

168 

169 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}. 

170 ''' 

171 _set_reframe(self, reframe) 

172 

173 def toLatLon(self, datum=None, height=None, **LatLon_and_kwds): # PYCHOK signature 

174 '''Convert this cartesian to a I{geodetic} (lat-/longitude) point. 

175 

176 @see: Method L{toLatLon<cartesianBase.CartesianBase.toLatLon>} 

177 for further details. 

178 ''' 

179 kwds = LatLon_and_kwds 

180 if kwds: 

181 kwds = _xkwds(kwds, reframe=self.reframe, epoch=self.epoch) 

182 return CartesianBase.toLatLon(self, datum=datum, height=height, **kwds) 

183 

184 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, **name): 

185 '''Convert this point to an other reference frame and epoch. 

186 

187 @arg reframe2: Reference frame to convert I{to} (L{RefFrame}). 

188 @kwarg reframe: Optional reference frame to convert I{from} (L{RefFrame}), 

189 overriding this point's reference frame. 

190 @kwarg epoch: Optional epoch (L{Epoch}, C{scalar} or C{str}), overriding 

191 this point's C{epoch or B{reframe}.epoch}. 

192 @kwarg epoch2: Optional epoch to observe for the converted point (L{Epoch}, 

193 C{scalar} or C{str}), otherwise B{C{epoch}}. 

194 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding C{B{reframe2}.name}. 

195 

196 @return: The converted point (ellipsoidal C{Cartesian}) or if conversion 

197 C{isunity}, this point or a copy of this point if the B{C{name}} 

198 is non-empty. 

199 

200 @raise TRFError: This point's C{reframe} is not defined, invalid B{C{epoch}} 

201 or B{C{epoch2}} or conversion from this point's C{reframe} 

202 to B{C{reframe2}} is not available. 

203 

204 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a L{RefFrame}. 

205 ''' 

206 return _MODS.trf._toRefFrame(self, reframe2, reframe=reframe, epoch=epoch, 

207 epoch2=epoch2, **name) 

208 

209 @deprecated_method 

210 def toTransforms_(self, *transforms, **datum): # PYCHOK no cover 

211 '''DEPRECATED on 2024.02.14, use method C{toTransform}.''' 

212 r = self 

213 for t in transforms: 

214 r = r.toTransform(t) 

215 return r.dup(**datum) if datum else r 

216 

217 

218class LatLonEllipsoidalBase(LatLonBase): 

219 '''(INTERNAL) Base class for ellipsoidal C{LatLon}s. 

220 ''' 

221 _datum = _WGS84 # L{Datum} 

222 _elevation2to = None # _elevation2 timeout (C{secs}) 

223 _epoch = None # overriding .reframe.epoch (C{float}) 

224 _gamma = None # UTM/UPS meridian convergence (C{degrees}) 

225 _geoidHeight2to = None # _geoidHeight2 timeout (C{secs}) 

226 _reframe = None # reference frame (L{RefFrame}) 

227 _scale = None # UTM/UPS scale factor (C{float}) 

228 _toLLEB_args = () # Etm/Utm/Ups._toLLEB arguments 

229 

230 def __init__(self, latlonh, lon=None, height=0, datum=_WGS84, reframe=None, 

231 epoch=None, wrap=False, **name): 

232 '''Create an ellipsoidal C{LatLon} point from the given lat-, longitude 

233 and height on the given datum, reference frame and epoch. 

234 

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

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

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

238 indicating B{C{latlonh}} is a C{LatLon}. 

239 @kwarg height: Optional height above (or below) the earth surface (C{meter}, 

240 same units as the datum's ellipsoid axes). 

241 @kwarg datum: Optional, ellipsoidal datum to use (L{Datum}, L{Ellipsoid}, 

242 L{Ellipsoid2} or L{a_f2Tuple}). 

243 @kwarg reframe: Optional reference frame (L{RefFrame}). 

244 @kwarg epoch: Optional epoch to observe for B{C{reframe}} (C{scalar}), a 

245 non-zero, fractional calendar year, but silently ignored if 

246 C{B{reframe}=None}. 

247 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{lat}} and B{C{lon}} (C{bool}). 

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

249 

250 @raise RangeError: Value of C{lat} or B{C{lon}} outside the valid range and 

251 L{rangerrors} set to C{True}. 

252 

253 @raise TypeError: If B{C{latlonh}} is not a C{LatLon}, B{C{datum}} is not a 

254 L{Datum}, B{C{reframe}} is not a L{RefFrame} or B{C{epoch}} 

255 is not C{scalar} non-zero. 

256 

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

258 ''' 

259 LatLonBase.__init__(self, latlonh, lon=lon, height=height, wrap=wrap, **name) 

260 if not _isin(datum, None, self._datum, _EWGS84): 

261 self.datum = _ellipsoidal_datum(datum, name=self.name) 

262 if reframe: 

263 self.reframe = reframe 

264 self.epoch = epoch 

265 

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

267# '''Return C{NotImplemented} for C{ll_ = ll @ datum} and C{ll_ = ll @ reframe}. 

268# ''' 

269# RefFrame = _MODS.trf.RefFrame 

270# return NotImplemented if isinstance(other, (Datum, RefFrame)) else \ 

271# _NotImplemented(self, other) 

272 

273 def antipode(self, height=None): 

274 '''Return the antipode, the point diametrically opposite 

275 to this point. 

276 

277 @kwarg height: Optional height of the antipode, height 

278 of this point otherwise (C{meter}). 

279 

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

281 ''' 

282 lla = LatLonBase.antipode(self, height=height) 

283 if lla.datum != self.datum: 

284 lla.datum = self.datum 

285 return lla 

286 

287 @deprecated_property_RO 

288 def convergence(self): 

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

290 return self.gamma # PYCHOK no cover 

291 

292 @deprecated_method 

293 def convertDatum(self, datum2): 

294 '''DEPRECATED, use method L{toDatum}.''' 

295 return self.toDatum(datum2) 

296 

297 @deprecated_method 

298 def convertRefFrame(self, reframe2): 

299 '''DEPRECATED, use method L{toRefFrame}.''' 

300 return self.toRefFrame(reframe2) 

301 

302 @property_doc_(''' this points's datum (L{Datum}).''') 

303 def datum(self): 

304 '''Get this point's datum (L{Datum}). 

305 ''' 

306 return self._datum 

307 

308 @datum.setter # PYCHOK setter! 

309 def datum(self, datum): 

310 '''Set this point's datum I{without conversion} (L{Datum}). 

311 

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

313 ''' 

314 _xinstanceof(Datum, datum=datum) 

315 if not datum.isEllipsoidal: 

316 raise _IsnotError(_ellipsoidal_, datum=datum) 

317 if self._datum != datum: 

318 _update_all(self) 

319 self._datum = datum 

320 

321 def distanceTo2(self, other, wrap=False): 

322 '''I{Approximate} the distance and (initial) bearing between this 

323 and an other (ellipsoidal) point based on the radii of curvature. 

324 

325 I{Suitable only for short distances up to a few hundred Km 

326 or Miles and only between points not near-polar}. 

327 

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

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

330 point (C{bool}). 

331 

332 @return: An L{Distance2Tuple}C{(distance, initial)}. 

333 

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

335 

336 @raise ValueError: Incompatible datum ellipsoids. 

337 

338 @see: Method L{Ellipsoid.distance2} and U{Local, flat earth 

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

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

341 formula. 

342 ''' 

343 p = self.others(other) 

344 if wrap: # PYCHOK no cover 

345 p = _Wrap.point(p) 

346 E = self.ellipsoids(other) 

347 return E.distance2(*(self.latlon + p.latlon)) 

348 

349 @Property_RO 

350 def _elevation2(self): 

351 '''(INTERNAL) Get elevation and data source. 

352 ''' 

353 return _MODS.elevations.elevation2(self.lat, self.lon, 

354 timeout=self._elevation2to) 

355 

356 def elevation2(self, adjust=True, datum=None, timeout=2): 

357 '''Return elevation of this point for its or the given datum, ellipsoid 

358 or sphere. 

359 

360 @kwarg adjust: Adjust the elevation for a B{C{datum}} other than 

361 C{NAD83} (C{bool}). 

362 @kwarg datum: Optional datum overriding this point's datum (L{Datum}, 

363 L{Ellipsoid}, L{Ellipsoid2}, L{a_f2Tuple} or C{scalar} 

364 radius). 

365 @kwarg timeout: Optional query timeout (C{seconds}). 

366 

367 @return: An L{Elevation2Tuple}C{(elevation, data_source)} or 

368 C{(None, error)} in case of errors. 

369 

370 @note: The adjustment applied is the difference in geocentric earth 

371 radius between the B{C{datum}} and C{NAV83} upon which the 

372 L{elevations.elevation2} is based. 

373 

374 @note: NED elevation is only available for locations within the U{Conterminous 

375 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}. 

376 

377 @see: Function L{elevations.elevation2} and method C{Ellipsoid.Rgeocentric} 

378 for further details and possible C{error}s. 

379 ''' 

380 if self._elevation2to != timeout: 

381 self._elevation2to = timeout 

382 LatLonEllipsoidalBase._elevation2._update(self) 

383 return self._Radjust2(adjust, datum, self._elevation2) 

384 

385 def ellipsoid(self, datum=_WGS84): 

386 '''Return the ellipsoid of this point's datum or the given datum. 

387 

388 @kwarg datum: Default datum (L{Datum}). 

389 

390 @return: The ellipsoid (L{Ellipsoid} or L{Ellipsoid2}). 

391 ''' 

392 return _xattr(self, datum=datum).ellipsoid 

393 

394 @property_RO 

395 def ellipsoidalLatLon(self): 

396 '''Get this C{LatLon}'s ellipsoidal class. 

397 ''' 

398 return type(self) 

399 

400 def ellipsoids(self, other): 

401 '''Check the type and ellipsoid of this and an other point's datum. 

402 

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

404 

405 @return: This point's datum ellipsoid (L{Ellipsoid} or L{Ellipsoid2}). 

406 

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

408 

409 @raise ValueError: Incompatible datum ellipsoids. 

410 ''' 

411 self.others(other, up=2) # ellipsoids' caller 

412 

413 E = self.ellipsoid() 

414 try: # other may be Sphere, etc. 

415 e = other.ellipsoid() 

416 except AttributeError: 

417 try: # no ellipsoid method, try datum 

418 e = other.datum.ellipsoid 

419 except AttributeError: 

420 e = E # no datum, XXX assume equivalent? 

421 return _xellipsoids(E, e) 

422 

423 @property_doc_(''' this point's observed or C{reframe} epoch (C{float}).''') 

424 def epoch(self): 

425 '''Get this point's observed or C{reframe} epoch (L{Epoch}) or C{None}. 

426 ''' 

427 return self._epoch or (self.reframe.epoch if self.reframe else None) 

428 

429 @epoch.setter # PYCHOK setter! 

430 def epoch(self, epoch): 

431 '''Set or clear this point's observed epoch, a fractional 

432 calendar year (L{Epoch}, C{scalar} or C{str}) or C{None}. 

433 

434 @raise TRFError: Invalid B{C{epoch}}. 

435 ''' 

436 self._epoch = None if epoch is None else Epoch(epoch) 

437 

438 @Property_RO 

439 def Equidistant(self): 

440 '''Get the prefered azimuthal equidistant projection I{class} (L{EquidistantKarney} or L{EquidistantExact}). 

441 ''' 

442 try: 

443 _ = self.datum.ellipsoid.geodesic 

444 return _MODS.azimuthal.EquidistantKarney 

445 except ImportError: # no geographiclib 

446 return _MODS.azimuthal.EquidistantExact # XXX no longer L{azimuthal.Equidistant} 

447 

448 @Property_RO 

449 def _etm(self): 

450 '''(INTERNAL) Get this C{LatLon} point as an ETM coordinate (L{pygeodesy.toEtm8}). 

451 ''' 

452 etm = _MODS.etm 

453 return etm.toEtm8(self, datum=self.datum, Etm=etm.Etm) 

454 

455 @property_RO 

456 def gamma(self): 

457 '''Get this point's UTM or UPS meridian convergence (C{degrees}) or 

458 C{None} if not available or not converted from L{Utm} or L{Ups}. 

459 ''' 

460 return self._gamma 

461 

462 @Property_RO 

463 def _geoidHeight2(self): 

464 '''(INTERNAL) Get geoid height and model. 

465 ''' 

466 return _MODS.elevations.geoidHeight2(self.lat, self.lon, model=0, 

467 timeout=self._geoidHeight2to) 

468 

469 def geoidHeight2(self, adjust=False, datum=None, timeout=2): 

470 '''Return geoid height of this point for its or the given datum, ellipsoid 

471 or sphere. 

472 

473 @kwarg adjust: Adjust the geoid height for a B{C{datum}} other than 

474 C{NAD83/NADV88} (C{bool}). 

475 @kwarg datum: Optional datum overriding this point's datum (L{Datum}, 

476 L{Ellipsoid}, L{Ellipsoid2}, L{a_f2Tuple} or C{scalar} 

477 radius). 

478 @kwarg timeout: Optional query timeout (C{seconds}). 

479 

480 @return: A L{GeoidHeight2Tuple}C{(height, model_name)} or 

481 C{(None, error)} in case of errors. 

482 

483 @note: The adjustment applied is the difference in geocentric earth 

484 radius between the B{C{datum}} and C{NAV83/NADV88} upon which 

485 the L{elevations.geoidHeight2} is based. 

486 

487 @note: The geoid height is only available for locations within the U{Conterminous 

488 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}. 

489 

490 @see: Function L{elevations.geoidHeight2} and method C{Ellipsoid.Rgeocentric} 

491 for further details and possible C{error}s. 

492 ''' 

493 if self._geoidHeight2to != timeout: 

494 self._geoidHeight2to = timeout 

495 LatLonEllipsoidalBase._geoidHeight2._update(self) 

496 return self._Radjust2(adjust, datum, self._geoidHeight2) 

497 

498 def intermediateTo(self, other, fraction, height=None, wrap=False): # PYCHOK no cover 

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

500 self._notOverloaded(other, fraction, height=height, wrap=wrap) 

501 

502 def intersection3(self, end1, start2, end2, height=None, wrap=False, # was=True 

503 equidistant=None, tol=_TOL_M): 

504 '''I{Iteratively} compute the intersection point of two geodesic lines, each 

505 given as two points or as a start point and a bearing from North. 

506 

507 @arg end1: End point of this line (C{LatLon}) or the initial bearing at 

508 this point (compass C{degrees360}). 

509 @arg start2: Start point of the second line (this C{LatLon}). 

510 @arg end2: End point of the second line (this C{LatLon}) or the initial 

511 bearing at B{C{start2}} (compass C{degrees360}). 

512 @kwarg height: Optional height at the intersection (C{meter}, conventionally) 

513 or C{None} for the mean height. 

514 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{start2}} and 

515 both B{C{end*}} points (C{bool}). 

516 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function 

517 L{pygeodesy.equidistant}), or C{None} for this point's 

518 preferred C{.Equidistant}. 

519 @kwarg tol: Tolerance for convergence and skew line distance and length 

520 (C{meter}, conventionally). 

521 

522 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)} with C{point} 

523 a C{LatLon} instance. 

524 

525 @raise ImportError: Package U{geographiclib 

526 <https://PyPI.org/project/geographiclib>} not 

527 installed or not found, but only in case 

528 C{B{equidistant}=}L{EquidistantKarney}. 

529 

530 @raise IntersectionError: Skew, colinear, parallel or otherwise non-intersecting 

531 lines or no convergence for the given B{C{tol}}. 

532 

533 @raise TypeError: Invalid B{C{end1}}, B{C{start2}} or B{C{end2}}. 

534 

535 @note: For each line specified with an initial bearing, a pseudo-end point is 

536 computed as the C{destination} along that bearing at about 1.5 times the 

537 distance from the start point to an initial gu-/estimate of the intersection 

538 point (and between 1/8 and 3/8 of the C{authalic} earth perimeter). 

539 

540 @see: I{Karney's} U{intersect.cpp<https://SourceForge.net/p/geographiclib/ 

541 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https:// 

542 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>} 

543 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section 

544 B{14. MARITIME BOUNDARIES} for more details about the iteration algorithm. 

545 ''' 

546 try: 

547 s2 = self.others(start2=start2) 

548 return _MODS.ellipsoidalBaseDI._intersect3(self, end1, 

549 s2, end2, 

550 height=height, wrap=wrap, 

551 equidistant=equidistant, tol=tol, 

552 LatLon=self.classof, datum=self.datum) 

553 except (TypeError, ValueError) as x: 

554 raise _xError(x, start1=self, end1=end1, start2=start2, end2=end2, 

555 height=height, wrap=wrap, tol=tol) 

556 

557 def intersections2(self, radius1, center2, radius2, height=None, wrap=False, # was=True 

558 equidistant=None, tol=_TOL_M): 

559 '''I{Iteratively} compute the intersection points of two circles, each 

560 defined by a center point and a radius. 

561 

562 @arg radius1: Radius of this circle (C{meter}, conventionally). 

563 @arg center2: Center of the other circle (this C{LatLon}). 

564 @arg radius2: Radius of the other circle (C{meter}, same units as 

565 B{C{radius1}}). 

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

567 conventionally) or C{None} for the I{"radical height"} 

568 at the I{radical line} between both centers. 

569 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{center2}} 

570 (C{bool}). 

571 @kwarg equidistant: An azimuthal equidistant projection (I{class} or 

572 function L{pygeodesy.equidistant}) or C{None} 

573 for this point's preferred C{.Equidistant}. 

574 @kwarg tol: Convergence tolerance (C{meter}, same units as 

575 B{C{radius1}} and B{C{radius2}}). 

576 

577 @return: 2-Tuple of the intersection points, each a C{LatLon} 

578 instance. For abutting circles, both intersection 

579 points are the same instance, aka the I{radical center}. 

580 

581 @raise ImportError: Package U{geographiclib 

582 <https://PyPI.org/project/geographiclib>} 

583 not installed or not found, but only if 

584 C{B{equidistant}=}L{EquidistantKarney}. 

585 

586 @raise IntersectionError: Concentric, antipodal, invalid or 

587 non-intersecting circles or no 

588 convergence for the given B{C{tol}}. 

589 

590 @raise TypeError: Invalid B{C{center2}} or B{C{equidistant}}. 

591 

592 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}. 

593 

594 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/ 

595 calculating-intersection-of-two-circles>}, U{Karney's paper 

596 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES}, 

597 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and 

598 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>} 

599 intersections. 

600 ''' 

601 try: 

602 c2 = self.others(center2=center2) 

603 return _MODS.ellipsoidalBaseDI._intersections2(self, radius1, 

604 c2, radius2, 

605 height=height, wrap=wrap, 

606 equidistant=equidistant, tol=tol, 

607 LatLon=self.classof, datum=self.datum) 

608 except (AssertionError, TypeError, ValueError) as x: 

609 raise _xError(x, center=self, radius1=radius1, center2=center2, radius2=radius2, 

610 height=height, wrap=wrap, tol=tol) 

611 

612 def isenclosedBy(self, points, wrap=False): 

613 '''Check whether a polygon or composite encloses this point. 

614 

615 @arg points: The polygon points or clips (C{LatLon}[], 

616 L{BooleanFHP} or L{BooleanGH}). 

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

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

619 

620 @return: C{True} if this point is inside the polygon or composite, 

621 C{False} otherwise. 

622 

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

624 

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

626 

627 @raise ValueError: Invalid B{C{point}}, lat- or longitude. 

628 

629 @see: Functions L{pygeodesy.isconvex}, L{pygeodesy.isenclosedBy} 

630 and L{pygeodesy.ispolar} especially if the B{C{points}} may 

631 enclose a pole or wrap around the earth I{longitudinally}. 

632 ''' 

633 return _MODS.points.isenclosedBy(self, points, wrap=wrap) 

634 

635 @property_RO 

636 def iteration(self): 

637 '''Get the most recent C{intersections2} or C{nearestOn} iteration 

638 number (C{int}) or C{None} if not available/applicable. 

639 ''' 

640 return self._iteration 

641 

642 def midpointTo(self, other, height=None, fraction=_0_5, wrap=False): 

643 '''Find the midpoint on a geodesic between this and an other point. 

644 

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

646 @kwarg height: Optional height for midpoint, overriding the 

647 mean height (C{meter}). 

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

649 may be negative or greater than 1.0. 

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

651 B{C{other}} point (C{bool}). 

652 

653 @return: Midpoint (C{LatLon}). 

654 

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

656 

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

658 

659 @see: Methods C{intermediateTo} and C{rhumbMidpointTo}. 

660 ''' 

661 return self.intermediateTo(other, fraction, height=height, wrap=wrap) 

662 

663 def nearestOn(self, point1, point2, within=True, height=None, wrap=False, # was=True 

664 equidistant=None, tol=_TOL_M): 

665 '''I{Iteratively} locate the closest point on the geodesic (line) 

666 between two other (ellipsoidal) points. 

667 

668 @arg point1: Start point of the geodesic (C{LatLon}). 

669 @arg point2: End point of the geodesic (C{LatLon}). 

670 @kwarg within: If C{True}, return the closest point I{between} B{C{point1}} and 

671 B{C{point2}}, otherwise the closest point elsewhere on the geodesic 

672 (C{bool}). 

673 @kwarg height: Optional height for the closest point (C{meter}, conventionally) 

674 or C{None} or C{False} for the interpolated height. If C{False}, 

675 the closest takes the heights of the points into account. 

676 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both B{C{point1}} and 

677 B{C{point2}} (C{bool}). 

678 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function 

679 L{pygeodesy.equidistant}) or C{None} for this point's preferred 

680 C{Equidistant}, like L{Equidistant<LatLonEllipsoidalBase.Equidistant>}. 

681 @kwarg tol: Convergence tolerance (C{meter}, conventionally). 

682 

683 @return: Closest point (C{LatLon}). 

684 

685 @raise ImportError: Package U{geographiclib 

686 <https://PyPI.org/project/geographiclib>} 

687 not installed or not found, but only if 

688 C{B{equidistant}=}L{EquidistantKarney}. 

689 

690 @raise TypeError: Invalid B{C{point1}}, B{C{point2}} or B{C{equidistant}}. 

691 

692 @raise ValueError: Datum or ellipsoid of B{C{point1}} or B{C{point2}} is incompatible 

693 or no convergence for the given B{C{tol}}. 

694 

695 @see: I{Karney}'s U{intercept.cpp<https://SourceForge.net/p/geographiclib/ 

696 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https:// 

697 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>} 

698 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section 

699 B{14. MARITIME BOUNDARIES} for details about the iteration algorithm. 

700 ''' 

701 try: 

702 t = _MODS.ellipsoidalBaseDI._nearestOn2(self, point1, point2, within=within, 

703 height=height, wrap=wrap, 

704 equidistant=equidistant, 

705 tol=tol, LatLon=self.classof) 

706 except (TypeError, ValueError) as x: 

707 raise _xError(x, point=self, point1=point1, point2=point2, within=within, 

708 height=height, wrap=wrap, tol=tol) 

709 return t.closest 

710 

711 def parse(self, strllh, height=0, datum=None, epoch=None, reframe=None, 

712 sep=_COMMA_, wrap=False, **name): 

713 '''Parse a string consisting of C{"lat, lon[, height]"}, 

714 representing a similar, ellipsoidal C{LatLon} point. 

715 

716 @arg strllh: Lat, lon and optional height (C{str}), see function 

717 L{pygeodesy.parse3llh}. 

718 @kwarg height: Optional, default height (C{meter} or C{None}). 

719 @kwarg datum: Optional datum (L{Datum}), overriding this datum 

720 I{without conversion}. 

721 @kwarg epoch: Optional datum (L{Epoch}), overriding this epoch 

722 I{without conversion}. 

723 @kwarg reframe: Optional reference frame (L{RefFrame}), overriding 

724 this reframe I{without conversion}. 

725 @kwarg sep: Optional separator (C{str}). 

726 @kwarg wrap: If C{True}, wrap or I{normalize} the lat- and 

727 longitude (C{bool}). 

728 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding this name. 

729 

730 @return: The similar point (ellipsoidal C{LatLon}). 

731 

732 @raise ParseError: Invalid B{C{strllh}}. 

733 ''' 

734 a, b, h = _MODS.dms.parse3llh(strllh, height=height, sep=sep, wrap=wrap) 

735 return self.classof(a, b, height=h, datum=datum or self.datum, 

736 epoch=epoch or self.epoch, 

737 reframe=reframe or self.reframe, **name) 

738 

739 def _Radjust2(self, adjust, datum, meter_text2): 

740 '''(INTERNAL) Adjust an C{elevation} or C{geoidHeight} with 

741 difference in Gaussian radii of curvature of the given 

742 datum and NAD83 ellipsoids at this point's latitude. 

743 

744 @note: This is an arbitrary, possibly incorrect adjustment. 

745 ''' 

746 if adjust: # Elevation2Tuple or GeoidHeight2Tuple 

747 m, t = meter_text2 

748 if isinstance(m, float) and fabs(m) > EPS: # PYCHOK no cover 

749 n = Datums.NAD83.ellipsoid.rocGauss(self.lat) 

750 if n > EPS0: 

751 # use ratio, datum and NAD83 units may differ 

752 E = self.ellipsoid() if _isin(datum, None, self.datum) else \ 

753 _earth_ellipsoid(datum) 

754 r = E.rocGauss(self.lat) 

755 if r > EPS0 and fabs(r - n) > EPS: # EPS1 

756 m *= r / n 

757 meter_text2 = meter_text2.classof(m, t) 

758 return self._xnamed(meter_text2) 

759 

760 @property_doc_(''' this point's reference frame (L{RefFrame}).''') 

761 def reframe(self): 

762 '''Get this point's reference frame (L{RefFrame}) or C{None}. 

763 ''' 

764 return self._reframe 

765 

766 @reframe.setter # PYCHOK setter! 

767 def reframe(self, reframe): 

768 '''Set or clear this point's reference frame (L{RefFrame}) or C{None}. 

769 

770 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}. 

771 ''' 

772 _set_reframe(self, reframe) 

773 

774 @Property_RO 

775 def scale(self): 

776 '''Get this point's UTM grid or UPS point scale factor (C{float}) 

777 or C{None} if not converted from L{Utm} or L{Ups}. 

778 ''' 

779 return self._scale 

780 

781 def toCartesian(self, height=None, **Cartesian_and_kwds): # PYCHOK signature 

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

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

784 

785 @see: Method L{toCartesian<latlonBase.LatLonBase.toCartesian>} 

786 for further details. 

787 ''' 

788 kwds = Cartesian_and_kwds 

789 if kwds: 

790 kwds = _xkwds(kwds, reframe=self.reframe, epoch=self.epoch) 

791 return LatLonBase.toCartesian(self, height=height, **kwds) 

792 

793 def toCss(self, **toCss_kwds): 

794 '''Convert this C{LatLon} point to a Cassini-Soldner location. 

795 

796 @kwarg toCss_kwds: Optional L{pygeodesy.toCss} keyword arguments. 

797 

798 @return: The Cassini-Soldner location (L{Css}). 

799 

800 @see: Function L{pygeodesy.toCss}. 

801 ''' 

802 return _MODS.css.toCss(self, **self._name1__(toCss_kwds)) 

803 

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

805 '''Convert this point to an other datum. 

806 

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

808 @kwarg height: Optional height, overriding the 

809 converted height (C{meter}). 

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

811 

812 @return: The converted point (this C{LatLon}) or a copy 

813 of this point if B{C{datum2}} matches this 

814 point's C{datum}. 

815 

816 @raise TypeError: Invalid B{C{datum2}}. 

817 ''' 

818 n = self._name__(name) 

819 d2 = _ellipsoidal_datum(datum2, name=n) 

820 if self.datum == d2: 

821 r = self.copy(name=n) 

822 else: 

823 kwds = _xkwds_not(None, LatLon=self.classof, name=n, 

824 epoch=self.epoch, reframe=self.reframe) 

825 c = self.toCartesian().toDatum(d2) 

826 r = c.toLatLon(datum=d2, height=height, **kwds) 

827 return r 

828 

829 def toEtm(self, **toEtm8_kwds): 

830 '''Convert this C{LatLon} point to an ETM coordinate. 

831 

832 @kwarg toEtm8_kwds: Optional L{pygeodesy.toEtm8} keyword arguments. 

833 

834 @return: The ETM coordinate (L{Etm}). 

835 

836 @see: Function L{pygeodesy.toEtm8}. 

837 ''' 

838 return _MODS.etm.toEtm8(self, **self._name1__(toEtm8_kwds)) if toEtm8_kwds else self._etm 

839 

840 def toLcc(self, **toLcc_kwds): 

841 '''Convert this C{LatLon} point to a Lambert location. 

842 

843 @kwarg toLcc_kwds: Optional L{pygeodesy.toLcc} keyword arguments. 

844 

845 @return: The Lambert location (L{Lcc}). 

846 

847 @see: Function L{pygeodesy.toLcc}. 

848 ''' 

849 return _MODS.lcc.toLcc(self, **self._name1__(toLcc_kwds)) 

850 

851 def toMgrs(self, center=False, pole=NN): 

852 '''Convert this C{LatLon} point to an MGRS coordinate. 

853 

854 @kwarg center: If C{True}, try to I{un}-center MGRS 

855 to its C{lowerleft} (C{bool}) or by 

856 C{B{center} meter} (C{scalar}). 

857 @kwarg pole: Optional top/center for the MGRS UPS 

858 projection (C{str}, 'N[orth]' or 'S[outh]'). 

859 

860 @return: The MGRS coordinate (L{Mgrs}). 

861 

862 @see: Method L{toUtmUps} and L{Mgrs.toLatLon}. 

863 ''' 

864 return self.toUtmUps(center=center, pole=pole).toMgrs(center=False) 

865 

866 def toOsgr(self, kTM=False, **toOsgr_kwds): 

867 '''Convert this C{LatLon} point to an OSGR coordinate. 

868 

869 @kwarg kTM: If C{True}, use I{Karney}'s Krüger method from module 

870 L{ktm}, otherwise I{Ordinance Survery}'s recommended 

871 formulation (C{bool}). 

872 @kwarg toOsgr_kwds: Optional L{pygeodesy.toOsgr} keyword arguments. 

873 

874 @return: The OSGR coordinate (L{Osgr}). 

875 

876 @see: Function L{pygeodesy.toOsgr}. 

877 ''' 

878 return _MODS.osgr.toOsgr(self, kTM=kTM, **self._name1__(toOsgr_kwds)) 

879 

880 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, height=None, **name): 

881 '''Convert this point to an other reference frame and epoch. 

882 

883 @arg reframe2: Reference frame to convert I{to} (L{RefFrame}). 

884 @kwarg reframe: Optional reference frame to convert I{from} (L{RefFrame}), 

885 overriding this point's reference frame. 

886 @kwarg epoch: Optional epoch (L{Epoch}, C{scalar} or C{str}), overriding 

887 this point's C{epoch or B{reframe}.epoch}. 

888 @kwarg epoch2: Optional epoch to observe for the converted point (L{Epoch}, 

889 C{scalar} or C{str}), otherwise B{C{epoch}}. 

890 @kwarg height: Optional height, overriding the converted height (C{meter}). 

891 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding C{B{reframe2}.name}. 

892 

893 @return: The converted point (ellipsoidal C{LatLon}) or if conversion 

894 C{isunity}, this point or a copy of this point if the B{C{name}} 

895 is non-empty. 

896 

897 @raise TRFError: This point's C{reframe} is not defined, invalid B{C{epoch}} 

898 or B{C{epoch2}} or conversion from this point's C{reframe} 

899 to B{C{reframe2}} is not available. 

900 

901 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a L{RefFrame}. 

902 ''' 

903 return _MODS.trf._toRefFrame(self, reframe2, reframe=reframe, epoch=epoch, 

904 epoch2=epoch2, height=height, **name) 

905 

906 def toTransform(self, transform, inverse=False, datum=None, **LatLon_kwds): 

907 '''Apply a Helmert transform to this geodetic point. 

908 

909 @arg transform: Transform to apply (L{Transform} or L{TransformXform}). 

910 @kwarg inverse: Apply the inverse of the Helmert transform (C{bool}). 

911 @kwarg datum: Datum for the transformed point (L{Datum}), overriding 

912 this point's datum but I{not} taken it into account. 

913 @kwarg LatLon_kwds: Optional keyword arguments for the transformed 

914 point, like C{B{height}=...}. 

915 

916 @return: A transformed point (C{LatLon}) or a copy of this point if 

917 C{B{transform}.isunity}. 

918 

919 @raise TypeError: Invalid B{C{transform}}. 

920 ''' 

921 _xinstanceof(Transform, transform=transform) 

922 d = datum or self.datum 

923 if transform.isunity: 

924 r = self.dup(datum=d, **LatLon_kwds) 

925 else: 

926 c = self.toCartesian() 

927 c = c.toTransform(transform, inverse=inverse, datum=d) 

928 r = c.toLatLon(LatLon=self.classof, **_xkwds(LatLon_kwds, height=self.height)) 

929 return r 

930 

931 def toUps(self, pole=NN, falsed=True, center=False): 

932 '''Convert this C{LatLon} point to a UPS coordinate. 

933 

934 @kwarg pole: Optional top/center of (stereographic) 

935 projection (C{str}, 'N[orth]' or 'S[outh]'). 

936 @kwarg falsed: False easting and northing (C{bool}). 

937 @kwarg center: If C{True}, I{un}-center the UPS to its 

938 C{lowerleft} (C{bool}) or by C{B{center} 

939 meter} (C{scalar}). 

940 

941 @return: The UPS coordinate (L{Ups}). 

942 

943 @see: Function L{pygeodesy.toUps8}. 

944 ''' 

945 if self._upsOK(pole, falsed): 

946 u = self._ups 

947 else: 

948 ups = _MODS.ups 

949 u = ups.toUps8(self, datum=self.datum, Ups=ups.Ups, 

950 pole=pole, falsed=falsed) 

951 return _lowerleft(u, center) 

952 

953 def toUtm(self, center=False): 

954 '''Convert this C{LatLon} point to a UTM coordinate. 

955 

956 @kwarg center: If C{True}, I{un}-center the UTM to its 

957 C{lowerleft} (C{bool}) or by C{B{center} 

958 meter} (C{scalar}). 

959 

960 @return: The UTM coordinate (L{Utm}). 

961 

962 @see: Method L{Mgrs.toUtm} and function L{pygeodesy.toUtm8}. 

963 ''' 

964 return _lowerleft(self._utm, center) 

965 

966 def toUtmUps(self, pole=NN, center=False): 

967 '''Convert this C{LatLon} point to a UTM or UPS coordinate. 

968 

969 @kwarg pole: Optional top/center of UPS (stereographic) 

970 projection (C{str}, 'N[orth]' or 'S[outh]'). 

971 @kwarg center: If C{True}, I{un}-center the UTM or UPS to 

972 its C{lowerleft} (C{bool}) or by C{B{center} 

973 meter} (C{scalar}). 

974 

975 @return: The UTM or UPS coordinate (L{Utm} or L{Ups}). 

976 

977 @see: Function L{pygeodesy.toUtmUps8}. 

978 ''' 

979 if self._utmOK(): 

980 u = self._utm 

981 elif self._upsOK(pole): 

982 u = self._ups 

983 else: # no cover 

984 utmups = _MODS.utmups 

985 u = utmups.toUtmUps8(self, datum=self.datum, pole=pole, name=self.name, 

986 Utm=utmups.Utm, Ups=utmups.Ups) 

987 if isinstance(u, utmups.Utm): 

988 self._update(False, _utm=u) # PYCHOK kwds 

989 elif isinstance(u, utmups.Ups): 

990 self._update(False, _ups=u) # PYCHOK kwds 

991 else: 

992 _xinstanceof(utmups.Utm, utmups.Ups, toUtmUps8=u) 

993 return _lowerleft(u, center) 

994 

995 @deprecated_method 

996 def to3xyz(self): # PYCHOK no cover 

997 '''DEPRECATED, use method C{toEcef}. 

998 

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

1000 

1001 @note: Overloads C{LatLonBase.to3xyz} 

1002 ''' 

1003 r = self.toEcef() 

1004 return _MODS.namedTuples.Vector3Tuple(r.x, r.y, r.z, name=self.name) 

1005 

1006 def triangulate(self, bearing1, other, bearing2, **height_wrap_tol): 

1007 '''I{Iteratively} locate a point given this, an other point and a bearing 

1008 from North at each point. 

1009 

1010 @arg bearing1: Bearing at this point (compass C{degrees360}). 

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

1012 @arg bearing2: Bearing at the B{C{other}} point (compass C{degrees360}). 

1013 @kwarg height_wrap_tol: Optional keyword arguments C{B{height}=None}, 

1014 C{B{wrap}=False} and C{B{tol}}, see method L{intersection3 

1015 <pygeodesy.ellipsoidalBase.LatLonEllipsoidalBase>}. 

1016 

1017 @return: Triangulated point (C{LatLon}). 

1018 

1019 @see: Method L{intersection3<pygeodesy.ellipsoidalBase.LatLonEllipsoidalBase>} 

1020 for further details. 

1021 ''' 

1022 if _isDegrees(bearing1) and _isDegrees(bearing2): 

1023 r = self.intersection3(bearing1, other, bearing2, **height_wrap_tol) 

1024 return r.point 

1025 raise _TypeError(bearing1=bearing1, bearing2=bearing2 **height_wrap_tol) 

1026 

1027 def trilaterate5(self, distance1, point2, distance2, point3, distance3, 

1028 area=True, eps=EPS1, wrap=False): 

1029 '''Trilaterate three points by I{area overlap} or I{perimeter intersection} 

1030 of three intersecting circles. 

1031 

1032 @arg distance1: Distance to this point (C{meter}), same units as B{C{eps}}). 

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

1034 @arg distance2: Distance to point2 (C{meter}, same units as B{C{eps}}). 

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

1036 @arg distance3: Distance to point3 (C{meter}, same units as B{C{eps}}). 

1037 @kwarg area: If C{True}, compute the area overlap, otherwise the perimeter 

1038 intersection of the circles (C{bool}). 

1039 @kwarg eps: The required I{minimal overlap} for C{B{area}=True} or the 

1040 I{intersection margin} for C{B{area}=False} (C{meter}, 

1041 conventionally). 

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

1043 and B{C{point3}} (C{bool}). 

1044 

1045 @return: A L{Trilaterate5Tuple}C{(min, minPoint, max, maxPoint, n)} with 

1046 C{min} and C{max} in C{meter}, same units as B{C{eps}}, the 

1047 corresponding trilaterated points C{minPoint} and C{maxPoint} 

1048 as I{ellipsoidal} C{LatLon} and C{n}, the number of trilatered 

1049 points found for the given B{C{eps}}. 

1050 

1051 If only a single trilaterated point is found, C{min I{is} max}, 

1052 C{minPoint I{is} maxPoint} and C{n=1}. 

1053 

1054 If C{B{area}=False}, C{min} and C{max} represent the nearest 

1055 respectively farthest intersection margin. 

1056 

1057 If C{B{area}=True}, C{min} and C{max} are the smallest respectively 

1058 largest I{radial} overlap found. 

1059 

1060 If C{B{area}=True} and all 3 circles are concentric, C{n=0} and 

1061 C{minPoint} and C{maxPoint} are the B{C{point#}} with the smallest 

1062 B{C{distance#}} C{min} respectively largest B{C{distance#}} C{max}. 

1063 

1064 @raise IntersectionError: Trilateration failed for the given B{C{eps}}, 

1065 insufficient overlap for C{B{area}=True}, no 

1066 circle intersections for C{B{area}=False} or 

1067 all circles are (near-)concentric. 

1068 

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

1070 

1071 @raise ValueError: Coincident B{C{points}} or invalid B{C{distance1}}, 

1072 B{C{distance2}} or B{C{distance3}}. 

1073 

1074 @note: Ellipsoidal trilateration invokes methods C{LatLon.intersections2} 

1075 and C{LatLon.nearestOn} based on I{Karney}'s Python U{geographiclib 

1076 <https://PyPI.org/project/geographiclib>} if installed, otherwise 

1077 the accurate (but slower) C{ellipsoidalExact.LatLon} methods. 

1078 ''' 

1079 return _trilaterate5(self, distance1, 

1080 self.others(point2=point2), distance2, 

1081 self.others(point3=point3), distance3, 

1082 area=area, eps=eps, wrap=wrap) 

1083 

1084 @Property_RO 

1085 def _ups(self): # __dict__ value overwritten by method C{toUtmUps} 

1086 '''(INTERNAL) Get this C{LatLon} point as UPS coordinate (L{Ups}), 

1087 see L{pygeodesy.toUps8}. 

1088 ''' 

1089 ups = _MODS.ups 

1090 return ups.toUps8(self, datum=self.datum, Ups=ups.Ups, 

1091 pole=NN, falsed=True, name=self.name) 

1092 

1093 def _upsOK(self, pole=NN, falsed=True): 

1094 '''(INTERNAL) Check matching C{Ups}. 

1095 ''' 

1096 try: 

1097 u = self._ups 

1098 except RangeError: 

1099 return False 

1100 return falsed and (u.pole == pole[:1].upper() or not pole) 

1101 

1102 @Property_RO 

1103 def _utm(self): # __dict__ value overwritten by method C{toUtmUps} 

1104 '''(INTERNAL) Get this C{LatLon} point as UTM coordinate (L{Utm}), 

1105 see L{pygeodesy.toUtm8}. 

1106 ''' 

1107 utm = _MODS.utm 

1108 return utm.toUtm8(self, datum=self.datum, Utm=utm.Utm, name=self.name) 

1109 

1110 def _utmOK(self): 

1111 '''(INTERNAL) Check C{Utm}. 

1112 ''' 

1113 try: 

1114 _ = self._utm 

1115 except RangeError: 

1116 return False 

1117 return True 

1118 

1119 

1120def _lowerleft(utmups, center): 

1121 '''(INTERNAL) Optionally I{un}-center C{utmups}. 

1122 ''' 

1123 if _isin(center, False, 0, _0_0): 

1124 u = utmups 

1125 elif _isin(center, True): 

1126 u = utmups._lowerleft 

1127 else: 

1128 u = _MODS.utmupsBase._lowerleft(utmups, center) 

1129 return u 

1130 

1131 

1132def _nearestOn(point, point1, point2, within=True, height=None, wrap=False, # was=True 

1133 equidistant=None, tol=_TOL_M, **LatLon_and_kwds): 

1134 '''(INTERNAL) Get closest point, imported by .ellipsoidalExact, 

1135 -GeodSolve, -Karney and -Vincenty to embellish exceptions. 

1136 ''' 

1137 try: 

1138 p = _xellipsoidal(point=point) 

1139 t = _MODS.ellipsoidalBaseDI._nearestOn2(p, point1, point2, within=within, 

1140 height=height, wrap=wrap, 

1141 equidistant=equidistant, 

1142 tol=tol, **LatLon_and_kwds) 

1143 except (TypeError, ValueError) as x: 

1144 raise _xError(x, point=point, point1=point1, point2=point2) 

1145 return t.closest 

1146 

1147 

1148def _set_reframe(inst, reframe): 

1149 '''(INTERNAL) Set or clear an instance's reference frame. 

1150 ''' 

1151 if reframe is not None: 

1152 _xinstanceof(_MODS.trf.RefFrame, reframe=reframe) 

1153 inst._reframe = reframe 

1154 elif inst.reframe is not None: 

1155 inst._reframe = None 

1156 

1157 

1158__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase) 

1159 

1160# **) MIT License 

1161# 

1162# Copyright (C) 2016-2025 -- mrJean1 at Gmail -- All Rights Reserved. 

1163# 

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

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

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

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

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

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

1170# 

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

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

1173# 

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

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

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

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

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

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

1180# OTHER DEALINGS IN THE SOFTWARE.