Coverage for pygeodesy/ellipsoidalBase.py: 91%

302 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2024-06-01 11:43 -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-2016} 

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.basics import _xinstanceof # from .datums 

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

17from pygeodesy.cartesianBase import CartesianBase # PYCHOK used! 

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

19 Transform, _WGS84, _EWGS84, _xinstanceof # _spherical_datum 

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

21from pygeodesy.errors import _incompatible, _IsnotError, RangeError, _TypeError, \ 

22 _ValueError, _xattr, _xellipsoidal, _xError, _xkwds, \ 

23 _xkwds_not 

24# from pygeodesy.fmath import favg # _MODS 

25from pygeodesy.interns import NN, _COMMA_, _ellipsoidal_ 

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

27# from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS # from .named 

28# from pygeodesy.lcc import toLcc # _MODS 

29from pygeodesy.named import _name1__, _ALL_DOCS, _ALL_LAZY, _MODS 

30# from pygeodesy.namedTuples import Vector3Tuple # _MODS 

31from pygeodesy.props import deprecated_method, deprecated_property_RO, \ 

32 Property_RO, property_doc_, property_RO, _update_all 

33# from pygeodesy.trf import _eT0Ds4 # _MODS 

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

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

36 

37# from math import fabs # from .latlonBase 

38 

39__all__ = _ALL_LAZY.ellipsoidalBase 

40__version__ = '24.05.31' 

41 

42 

43class CartesianEllipsoidalBase(CartesianBase): 

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

45 ''' 

46 _datum = _WGS84 # L{Datum} 

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

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

49 

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

51 **datum_ll_name): 

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

53 

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

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

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

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

58 

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

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

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

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

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

64 

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

66 ''' 

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

68 if reframe: 

69 self.reframe = reframe 

70 self.epoch = epoch 

71 

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

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

74# ''' 

75# RefFrame = _MODS.trf.RefFrame 

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

77# _NotImplemented(self, other) 

78 

79 @deprecated_method 

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

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

82 return self.toRefFrame(reframe2, reframe=reframe, epoch=epoch) 

83 

84 @property_RO 

85 def ellipsoidalCartesian(self): 

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

87 ''' 

88 return type(self) 

89 

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

91 def epoch(self): 

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

93 ''' 

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

95 

96 @epoch.setter # PYCHOK setter! 

97 def epoch(self, epoch): 

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

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

100 

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

102 ''' 

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

104 

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

106 Vector=None, **Vector_kwds): 

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

108 cartesian center point and a radius. 

109 

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

111 coordinates). 

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

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

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

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

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

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

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

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

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

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

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

123 

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

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

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

127 

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

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

130 the same instance, aka the I{radical center}. 

131 

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

133 

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

135 

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

137 

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

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

140 Intersection and function L{pygeodesy.radical2}. 

141 ''' 

142 try: 

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

144 center2, Radius_(radius2=radius2), 

145 sphere=sphere, clas=self.classof, 

146 Vector=Vector, **Vector_kwds) 

147 except (TypeError, ValueError) as x: 

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

149 

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

151 def reframe(self): 

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

153 ''' 

154 return self._reframe 

155 

156 @reframe.setter # PYCHOK setter! 

157 def reframe(self, reframe): 

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

159 

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

161 ''' 

162 _set_reframe(self, reframe) 

163 

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

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

166 

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

168 for further details. 

169 ''' 

170 kwds = LatLon_and_kwds 

171 if kwds: 

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

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

174 

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

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

177 

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

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

180 overriding this point's reference frame. 

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

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

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

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

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

186 

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

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

189 is non-empty. 

190 

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

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

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

194 

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

196 ''' 

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

198 epoch2=epoch2, **name) 

199 

200 @deprecated_method 

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

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

203 r = self 

204 for t in transforms: 

205 r = r.toTransform(t) 

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

207 

208 

209class LatLonEllipsoidalBase(LatLonBase): 

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

211 ''' 

212 _datum = _WGS84 # L{Datum} 

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

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

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

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

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

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

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

220 

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

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

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

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

225 

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

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

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

229 C(None), indicating B{C{latlonh}} is a C{LatLon}. 

230 @kwarg height: Optional height above (or below) the earth surface 

231 (C{meter}, same units as the datum's ellipsoid axes). 

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

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

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

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

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

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

238 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{lat}} and B{C{lon}} 

239 (C{bool}). 

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

241 

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

243 range and L{rangerrors} set to C{True}. 

244 

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

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

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

248 

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

250 ''' 

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

252 if datum not in (None, self._datum, _EWGS84): 

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

254 if reframe: 

255 self.reframe = reframe 

256 self.epoch = epoch 

257 

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

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

260# ''' 

261# RefFrame = _MODS.trf.RefFrame 

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

263# _NotImplemented(self, other) 

264 

265 def antipode(self, height=None): 

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

267 to this point. 

268 

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

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

271 

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

273 ''' 

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

275 if lla.datum != self.datum: 

276 lla.datum = self.datum 

277 return lla 

278 

279 @deprecated_property_RO 

280 def convergence(self): 

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

282 return self.gamma 

283 

284 @deprecated_method 

285 def convertDatum(self, datum2): 

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

287 return self.toDatum(datum2) 

288 

289 @deprecated_method 

290 def convertRefFrame(self, reframe2): 

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

292 return self.toRefFrame(reframe2) 

293 

294 @Property_RO 

295 def _css(self): 

296 '''(INTERNAL) Get this C{LatLon} point as a Cassini-Soldner location (L{Css}). 

297 ''' 

298 css = _MODS.css 

299 return css.toCss(self, height=self.height, Css=css.Css, name=self.name) 

300 

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

302 def datum(self): 

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

304 ''' 

305 return self._datum 

306 

307 @datum.setter # PYCHOK setter! 

308 def datum(self, datum): 

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

310 

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

312 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: 

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 if e != E: 

422 raise _ValueError(e.named2, txt=_incompatible(E.named2)) 

423 return E 

424 

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

426 def epoch(self): 

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

428 ''' 

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

430 

431 @epoch.setter # PYCHOK setter! 

432 def epoch(self, epoch): 

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

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

435 

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

437 ''' 

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

439 

440 @Property_RO 

441 def Equidistant(self): 

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

443 ''' 

444 try: 

445 _ = self.datum.ellipsoid.geodesic 

446 return _MODS.azimuthal.EquidistantKarney 

447 except ImportError: # no geographiclib 

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

449 

450 @Property_RO 

451 def _etm(self): 

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

453 ''' 

454 etm = _MODS.etm 

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

456 

457 @property_RO 

458 def gamma(self): 

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

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

461 ''' 

462 return self._gamma 

463 

464 @Property_RO 

465 def _geoidHeight2(self): 

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

467 ''' 

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

469 timeout=self._geoidHeight2to) 

470 

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

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

473 or sphere. 

474 

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

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

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

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

479 radius). 

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

481 

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

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

484 

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

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

487 the L{elevations.geoidHeight2} is based. 

488 

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

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

491 

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

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

494 ''' 

495 if self._geoidHeight2to != timeout: 

496 self._geoidHeight2to = timeout 

497 LatLonEllipsoidalBase._geoidHeight2._update(self) 

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

499 

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

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

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

503 

504 def intersection3(self, end1, other, end2, height=None, wrap=False, # was=True 

505 equidistant=None, tol=_TOL_M): 

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

507 defined by two points or a start point and bearing from North. 

508 

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

510 bearing at this point (compass C{degrees360}). 

511 @arg other: Start point of the other line (C{LatLon}). 

512 @arg end2: End point of the other line (C{LatLon}) or the initial 

513 bearing at the other point (compass C{degrees360}). 

514 @kwarg height: Optional height at the intersection (C{meter}, 

515 conventionally) or C{None} for the mean height. 

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

517 B{C{other}} and B{C{end*}} points (C{bool}). 

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

519 function L{pygeodesy.equidistant}), or C{None} 

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

521 @kwarg tol: Tolerance for convergence and skew line distance and 

522 length (C{meter}, conventionally). 

523 

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

525 with C{point} a C{LatLon} instance. 

526 

527 @raise ImportError: Package U{geographiclib 

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

529 not installed or not found, but only if 

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

531 

532 @raise IntersectionError: Skew, colinear, parallel or otherwise 

533 non-intersecting lines or no convergence 

534 for the given B{C{tol}}. 

535 

536 @raise TypeError: If B{C{end1}}, B{C{other}} or B{C{end2}} point 

537 is not C{LatLon}. 

538 

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

540 point is computed as the C{destination} along that bearing at 

541 about 1.5 times the distance from the start point to an initial 

542 gu-/estimate of the intersection point (and between 1/8 and 3/8 

543 of the authalic earth perimeter). 

544 

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

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

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

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

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

550 ''' 

551 try: 

552 s2 = self.others(other) 

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

554 s2, end2, 

555 height=height, wrap=wrap, 

556 equidistant=equidistant, tol=tol, 

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

558 except (TypeError, ValueError) as x: 

559 raise _xError(x, start1=self, end1=end1, other=other, end2=end2, 

560 height=height, wrap=wrap, tol=tol) 

561 

562 def intersections2(self, radius1, other, radius2, height=None, wrap=False, # was=True 

563 equidistant=None, tol=_TOL_M): 

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

565 each defined by a center point and a radius. 

566 

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

568 @arg other: Center of the other circle (C{LatLon}). 

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

570 B{C{radius1}}). 

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

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

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

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

575 center (C{bool}). 

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

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

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

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

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

581 

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

583 instance. For abutting circles, both intersection 

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

585 

586 @raise ImportError: Package U{geographiclib 

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

588 not installed or not found, but only if 

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

590 

591 @raise IntersectionError: Concentric, antipodal, invalid or 

592 non-intersecting circles or no 

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

594 

595 @raise TypeError: Invalid B{C{other}} or B{C{equidistant}}. 

596 

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

598 

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

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

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

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

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

604 intersections. 

605 ''' 

606 try: 

607 c2 = self.others(other) 

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

609 c2, radius2, 

610 height=height, wrap=wrap, 

611 equidistant=equidistant, tol=tol, 

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

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

614 raise _xError(x, center=self, radius1=radius1, other=other, radius2=radius2, 

615 height=height, wrap=wrap, tol=tol) 

616 

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

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

619 

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

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

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

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

624 

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

626 C{False} otherwise. 

627 

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

629 

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

631 

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

633 

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

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

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

637 ''' 

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

639 

640 @property_RO 

641 def iteration(self): 

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

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

644 ''' 

645 return self._iteration 

646 

647 @Property_RO 

648 def _lcc(self): 

649 '''(INTERNAL) Get this C{LatLon} point as a Lambert location (L{Lcc}). 

650 ''' 

651 lcc = _MODS.lcc 

652 return lcc.toLcc(self, height=self.height, Lcc=lcc.Lcc, name=self.name) 

653 

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

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

656 

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

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

659 mean height (C{meter}). 

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

661 may be negative or greater than 1.0. 

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

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

664 

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

666 

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

668 

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

670 

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

672 ''' 

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

674 

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

676 equidistant=None, tol=_TOL_M): 

677 '''I{Iteratively} locate the closest point on the geodesic between 

678 two other (ellipsoidal) points. 

679 

680 @arg point1: Start point (C{LatLon}). 

681 @arg point2: End point (C{LatLon}). 

682 @kwarg within: If C{True} return the closest point I{between} 

683 B{C{point1}} and B{C{point2}}, otherwise the 

684 closest point elsewhere on the geodesic (C{bool}). 

685 @kwarg height: Optional height for the closest point (C{meter}, 

686 conventionally) or C{None} or C{False} for the 

687 interpolated height. If C{False}, the closest 

688 takes the heights of the points into account. 

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

690 B{C{point1}} and B{C{point2}} (C{bool}). 

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

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

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

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

695 

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

697 

698 @raise ImportError: Package U{geographiclib 

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

700 not installed or not found, but only if 

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

702 

703 @raise TypeError: Invalid B{C{point1}}, B{C{point2}} or 

704 B{C{equidistant}}. 

705 

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

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

708 

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

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

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

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

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

714 ''' 

715 try: 

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

717 height=height, wrap=wrap, 

718 equidistant=equidistant, 

719 tol=tol, LatLon=self.classof) 

720 except (TypeError, ValueError) as x: 

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

722 height=height, wrap=wrap, tol=tol) 

723 return t.closest 

724 

725 @Property_RO 

726 def _osgr(self): 

727 '''(INTERNAL) Get this C{LatLon} point as an OSGR coordinate (L{Osgr}), 

728 based on the OS recommendation. 

729 ''' 

730 return _MODS.osgr.toOsgr(self, kTM=False, name=self.name) # datum=self.datum 

731 

732 @Property_RO 

733 def _osgrTM(self): 

734 '''(INTERNAL) Get this C{LatLon} point as an OSGR coordinate (L{Osgr}) 

735 based on I{Karney}'s Krüger implementation. 

736 ''' 

737 return _MODS.osgr.toOsgr(self, kTM=True, name=self.name) # datum=self.datum 

738 

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

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

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

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

743 

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

745 L{pygeodesy.parse3llh}. 

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

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

748 I{without conversion}. 

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

750 I{without conversion}. 

751 @kwarg reframe: Optional datum (L{RefFrame}), overriding this 

752 reframe I{without conversion}. 

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

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

755 longitude (C{bool}). 

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

757 

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

759 

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

761 ''' 

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

763 r = self.classof(a, b, height=h, datum=self.datum) 

764 if datum not in (None, self.datum): 

765 r.datum = datum 

766 if epoch not in (None, self.epoch): 

767 r.epoch = epoch 

768 if reframe not in (None, self.reframe): 

769 r.reframe = reframe 

770 return self._xnamed(r, force=True, **name) if name else r 

771 

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

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

774 difference in Gaussian radii of curvature of the given 

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

776 

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

778 ''' 

779 if adjust: # Elevation2Tuple or GeoidHeight2Tuple 

780 m, t = meter_text2 

781 if isinstance(m, float) and fabs(m) > EPS: 

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

783 if n > EPS0: 

784 # use ratio, datum and NAD83 units may differ 

785 E = self.ellipsoid() if datum in (None, self.datum) else \ 

786 _earth_ellipsoid(datum) 

787 r = E.rocGauss(self.lat) 

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

789 m *= r / n 

790 meter_text2 = meter_text2.classof(m, t) 

791 return self._xnamed(meter_text2) 

792 

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

794 def reframe(self): 

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

796 ''' 

797 return self._reframe 

798 

799 @reframe.setter # PYCHOK setter! 

800 def reframe(self, reframe): 

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

802 

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

804 ''' 

805 _set_reframe(self, reframe) 

806 

807 @Property_RO 

808 def scale(self): 

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

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

811 ''' 

812 return self._scale 

813 

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

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

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

817 

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

819 for further details. 

820 ''' 

821 kwds = Cartesian_and_kwds 

822 if kwds: 

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

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

825 

826 def toCss(self, **toCss_kwds): 

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

828 

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

830 

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

832 

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

834 ''' 

835 return self._css if not toCss_kwds else _MODS.css.toCss( 

836 self, **_name1__(toCss_kwds, _or_nameof=self)) 

837 

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

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

840 

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

842 @kwarg height: Optional height, overriding the 

843 converted height (C{meter}). 

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

845 

846 @return: The converted point (ellipsoidal C{LatLon}) 

847 or a copy of this point if B{C{datum2}} 

848 matches this point's C{datum}. 

849 

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

851 ''' 

852 n = self._name__(name) 

853 d2 = _ellipsoidal_datum(datum2, name=n) 

854 if self.datum == d2: 

855 r = self.copy(name=n) 

856 else: 

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

858 epoch=self.epoch, reframe=self.reframe) 

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

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

861 return r 

862 

863 def toEtm(self, **toEtm8_kwds): 

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

865 

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

867 

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

869 

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

871 ''' 

872 return self._etm if not toEtm8_kwds else _MODS.etm.toEtm8( 

873 self, **_name1__(toEtm8_kwds, _or_nameof=self)) 

874 

875 def toLcc(self, **toLcc_kwds): 

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

877 

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

879 

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

881 

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

883 ''' 

884 return self._lcc if not toLcc_kwds else _MODS.lcc.toLcc( 

885 self, **_name1__(toLcc_kwds, _or_nameof=self)) 

886 

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

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

889 

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

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

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

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

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

895 

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

897 

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

899 ''' 

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

901 

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

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

904 

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

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

907 formulation (C{bool}). 

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

909 

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

911 

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

913 ''' 

914 if toOsgr_kwds: 

915 kwds = _name1__(toOsgr_kwds, _or_nameof=self) 

916 r = _MODS.osgr.toOsgr(self, kTM=kTM, **kwds) 

917 else: 

918 r = self._osgrTM if kTM else self._osgr 

919 return r 

920 

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

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

923 

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

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

926 overriding this point's reference frame. 

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

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

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

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

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

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

933 

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

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

936 is non-empty. 

937 

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

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

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

941 

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

943 ''' 

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

945 epoch2=epoch2, height=height, **name) 

946 

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

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

949 

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

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

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

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

954 @kwarg LatLon_kwds: Optional keyword arguments for the transformed 

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

956 

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

958 C{B{transform}.isunity}. 

959 

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

961 ''' 

962 _xinstanceof(Transform, transform=transform) 

963 d = datum or self.datum 

964 if transform.isunity: 

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

966 else: 

967 c = self.toCartesian() 

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

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

970 return r 

971 

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

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

974 

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

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

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

978 @kwarg center: If C{True}, I{un}-center the UPS 

979 to its C{lowerleft} (C{bool}) or 

980 by C{B{center} meter} (C{scalar}). 

981 

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

983 

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

985 ''' 

986 if self._upsOK(pole, falsed): 

987 u = self._ups 

988 else: 

989 ups = _MODS.ups 

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

991 pole=pole, falsed=falsed) 

992 return _lowerleft(u, center) 

993 

994 def toUtm(self, center=False): 

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

996 

997 @kwarg center: If C{True}, I{un}-center the UTM 

998 to its C{lowerleft} (C{bool}) or 

999 by C{B{center} meter} (C{scalar}). 

1000 

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

1002 

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

1004 ''' 

1005 return _lowerleft(self._utm, center) 

1006 

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

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

1009 

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

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

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

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

1014 meter} (C{scalar}). 

1015 

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

1017 

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

1019 ''' 

1020 if self._utmOK(): 

1021 u = self._utm 

1022 elif self._upsOK(pole): 

1023 u = self._ups 

1024 else: # no cover 

1025 utmups = _MODS.utmups 

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

1027 Utm=utmups.Utm, Ups=utmups.Ups) 

1028 if isinstance(u, utmups.Utm): 

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

1030 elif isinstance(u, utmups.Ups): 

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

1032 else: 

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

1034 return _lowerleft(u, center) 

1035 

1036 @deprecated_method 

1037 def to3xyz(self): # PYCHOK no cover 

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

1039 

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

1041 

1042 @note: Overloads C{LatLonBase.to3xyz} 

1043 ''' 

1044 r = self.toEcef() 

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

1046 

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

1048 '''I{Iteratively} locate a point given this, an other point and the (initial) 

1049 bearing at this and at the other point. 

1050 

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

1052 @arg other: Start point of the other line (C{LatLon}). 

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

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

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

1056 

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

1058 

1059 @see: Method L{intersection3} for further details. 

1060 ''' 

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

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

1063 return r.point 

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

1065 

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

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

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

1069 intersection} of three intersecting circles. 

1070 

1071 @arg distance1: Distance to this point (C{meter}), same units 

1072 as B{C{eps}}). 

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

1074 @arg distance2: Distance to point2 (C{meter}, same units as 

1075 B{C{eps}}). 

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

1077 @arg distance3: Distance to point3 (C{meter}, same units as 

1078 B{C{eps}}). 

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

1080 perimeter intersection of the circles (C{bool}). 

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

1082 or the I{intersection margin} for C{B{area}=False} 

1083 (C{meter}, conventionally). 

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

1085 B{C{point2}} and B{C{point3}} (C{bool}). 

1086 

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

1088 with C{min} and C{max} in C{meter}, same units as B{C{eps}}, 

1089 the corresponding trilaterated points C{minPoint} and 

1090 C{maxPoint} as I{ellipsoidal} C{LatLon} and C{n}, the number 

1091 of trilatered points found for the given B{C{eps}}. 

1092 

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

1094 max}, C{minPoint I{is} maxPoint} and C{n = 1}. 

1095 

1096 For C{B{area}=True}, C{min} and C{max} are the smallest 

1097 respectively largest I{radial} overlap found. 

1098 

1099 For C{B{area}=False}, C{min} and C{max} represent the 

1100 nearest respectively farthest intersection margin. 

1101 

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

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

1104 the smallest B{C{distance#}} C{min} respectively C{max} the 

1105 largest B{C{distance#}}. 

1106 

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

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

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

1110 all circles are (near-)concentric. 

1111 

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

1113 

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

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

1116 

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

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

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

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

1121 ''' 

1122 return _trilaterate5(self, distance1, 

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

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

1125 area=area, eps=eps, wrap=wrap) 

1126 

1127 @Property_RO 

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

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

1130 see L{pygeodesy.toUps8}. 

1131 ''' 

1132 ups = _MODS.ups 

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

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

1135 

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

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

1138 ''' 

1139 try: 

1140 u = self._ups 

1141 except RangeError: 

1142 return False 

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

1144 

1145 @Property_RO 

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

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

1148 see L{pygeodesy.toUtm8}. 

1149 ''' 

1150 utm = _MODS.utm 

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

1152 

1153 def _utmOK(self): 

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

1155 ''' 

1156 try: 

1157 _ = self._utm 

1158 except RangeError: 

1159 return False 

1160 return True 

1161 

1162 

1163def _lowerleft(utmups, center): 

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

1165 ''' 

1166 if center in (False, 0, _0_0): 

1167 u = utmups 

1168 elif center in (True,): 

1169 u = utmups._lowerleft 

1170 else: 

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

1172 return u 

1173 

1174 

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

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

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

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

1179 ''' 

1180 try: 

1181 p = _xellipsoidal(point=point) 

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

1183 height=height, wrap=wrap, 

1184 equidistant=equidistant, 

1185 tol=tol, **LatLon_and_kwds) 

1186 except (TypeError, ValueError) as x: 

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

1188 return t.closest 

1189 

1190 

1191def _set_reframe(inst, reframe): 

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

1193 ''' 

1194 if reframe is not None: 

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

1196 inst._reframe = reframe 

1197 elif inst.reframe is not None: 

1198 inst._reframe = None 

1199 

1200 

1201__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase) 

1202 

1203# **) MIT License 

1204# 

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

1206# 

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

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

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

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

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

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

1213# 

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

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

1216# 

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

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

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

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

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

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

1223# OTHER DEALINGS IN THE SOFTWARE.