Coverage for pygeodesy/ellipsoidalBase.py: 95%

291 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-12-12 14:24 -0500

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 _WGS84, _EWGS84, _xinstanceof # _spherical_datum 

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

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

22 _ValueError, _xattr, _xellipsoidal, _xError, \ 

23 _xkwds, _xkwds_get, _xkwds_not 

24# from pygeodesy.fmath import favg # _MODS 

25from pygeodesy.interns import MISSING, NN, _COMMA_, _conversion_, _DOT_, \ 

26 _ellipsoidal_, _no_, _reframe_, _SPACE_ 

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

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

29# from pygeodesy.lcc import toLcc # _MODS 

30# from pygeodesy.named import notOverloaded # _MODS 

31# from pygeodesy.namedTuples import Vector3Tuple # _MODS 

32from pygeodesy.props import deprecated_method, deprecated_property_RO, \ 

33 Property_RO, property_doc_, property_RO, _update_all 

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

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

36 

37# from math import fabs # from .latlonBase 

38 

39__all__ = _ALL_LAZY.ellipsoidalBase 

40__version__ = '23.12.12' 

41 

42 

43class CartesianEllipsoidalBase(CartesianBase): 

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

45 ''' 

46 _datum = _WGS84 # L{Datum} 

47 _reframe = None 

48 

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

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

51# ''' 

52# RefFrame = _MODS.trf.RefFrame 

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

54# _NotImplemented(self, other) 

55 

56 @deprecated_method 

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

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

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

60 

61 @property_RO 

62 def ellipsoidalCartesian(self): 

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

64 ''' 

65 return type(self) 

66 

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

68 Vector=None, **Vector_kwds): 

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

70 cartesian center point and a radius. 

71 

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

73 coordinates). 

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

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

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

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

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

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

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

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

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

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

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

85 

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

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

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

89 

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

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

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

93 

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

95 

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

97 

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

99 

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

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

102 Intersection and function L{pygeodesy.radical2}. 

103 ''' 

104 try: 

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

106 center2, Radius_(radius2=radius2), 

107 sphere=sphere, clas=self.classof, 

108 Vector=Vector, **Vector_kwds) 

109 except (TypeError, ValueError) as x: 

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

111 

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

113 def reframe(self): 

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

115 ''' 

116 return self._reframe 

117 

118 @reframe.setter # PYCHOK setter! 

119 def reframe(self, reframe): 

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

121 

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

123 ''' 

124 _set_reframe(self, reframe) 

125 

126 def toRefFrame(self, reframe2, reframe=None, epoch=None): 

127 '''Convert this cartesian point from one to an other reference frame. 

128 

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

130 @arg reframe: Reference frame to convert I{from} (L{RefFrame}), 

131 overriding this cartesian's C{reframe}. 

132 @kwarg epoch: Optional epoch to observe (C{scalar}, fractional 

133 calendar year), overriding B{C{reframe}}'s epoch. 

134 

135 @return: The converted point (C{Cartesian}) or this point if 

136 conversion is C{nil}. 

137 

138 @raise TRFError: No conversion available from B{C{reframe}} 

139 to B{C{reframe2}} or invalid B{C{epoch}}. 

140 

141 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a 

142 L{RefFrame}. 

143 ''' 

144 r = self.reframe if reframe is None else reframe 

145 if r in (None, reframe2): 

146 xs = None # XXX _set_reframe(self, reframe2)? 

147 else: 

148 trf = _MODS.trf 

149 _xinstanceof(trf.RefFrame, reframe2=reframe2, reframe=r) 

150 _, xs = trf._reframeTransforms2(reframe2, r, epoch) 

151 return self.toTransforms_(*xs) if xs else self 

152 

153 def toTransforms_(self, *transforms, **datum): 

154 '''Apply none, one or several Helmert transforms. 

155 

156 @arg transforms: Transforms to apply, in order (L{Transform}s). 

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

158 overriding this point's datum. 

159 

160 @return: The transformed point (C{Cartesian}) or this point 

161 if the B{C{transforms}} produce the same point. 

162 ''' 

163 r = self 

164 if transforms: 

165 xyz = r.xyz 

166 for t in transforms: 

167 xyz = t.transform(*xyz) 

168 d = _xkwds_get(datum, datum=r.datum) 

169 if d != r.datum or xyz != r.xyz: 

170 r = r.classof(xyz, datum=d) 

171 return r 

172 

173 

174class LatLonEllipsoidalBase(LatLonBase): 

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

176 ''' 

177 _datum = _WGS84 # L{Datum} 

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

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

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

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

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

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

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

185 

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

187 epoch=None, wrap=False, name=NN): 

188 '''Create an ellipsoidal C{LatLon} point frome the given 

189 lat-, longitude and height on the given datum and with 

190 the given reference frame and epoch. 

191 

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

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

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

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

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

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

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

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

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

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

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

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

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

205 (C{bool}). 

206 @kwarg name: Optional name (string). 

207 

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

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

210 

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

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

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

214 

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

216 ''' 

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

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

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

220 if reframe: 

221 self.reframe = reframe 

222 self.epoch = epoch 

223 

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

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

226# ''' 

227# RefFrame = _MODS.trf.RefFrame 

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

229# _NotImplemented(self, other) 

230 

231 def antipode(self, height=None): 

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

233 to this point. 

234 

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

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

237 

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

239 ''' 

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

241 if lla.datum != self.datum: 

242 lla.datum = self.datum 

243 return lla 

244 

245 @deprecated_property_RO 

246 def convergence(self): 

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

248 return self.gamma 

249 

250 @deprecated_method 

251 def convertDatum(self, datum2): 

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

253 return self.toDatum(datum2) 

254 

255 @deprecated_method 

256 def convertRefFrame(self, reframe2): 

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

258 return self.toRefFrame(reframe2) 

259 

260 @Property_RO 

261 def _css(self): 

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

263 ''' 

264 css = _MODS.css 

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

266 

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

268 def datum(self): 

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

270 ''' 

271 return self._datum 

272 

273 @datum.setter # PYCHOK setter! 

274 def datum(self, datum): 

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

276 

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

278 or not ellipsoidal. 

279 ''' 

280 _xinstanceof(Datum, datum=datum) 

281 if not datum.isEllipsoidal: 

282 raise _IsnotError(_ellipsoidal_, datum=datum) 

283 if self._datum != datum: 

284 _update_all(self) 

285 self._datum = datum 

286 

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

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

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

290 

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

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

293 

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

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

296 point (C{bool}). 

297 

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

299 

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

301 

302 @raise ValueError: Incompatible datum ellipsoids. 

303 

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

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

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

307 formula. 

308 ''' 

309 p = self.others(other) 

310 if wrap: 

311 p = _Wrap.point(p) 

312 E = self.ellipsoids(other) 

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

314 

315 @Property_RO 

316 def _elevation2(self): 

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

318 ''' 

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

320 timeout=self._elevation2to) 

321 

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

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

324 or sphere. 

325 

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

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

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

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

330 radius). 

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

332 

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

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

335 

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

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

338 L{elevations.elevation2} is based. 

339 

340 @note: NED elevation is only available for locations within the 

341 U{Conterminous US (CONUS) 

342 <https://WikiPedia.org/wiki/Contiguous_United_States>}. 

343 

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

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

346 ''' 

347 if self._elevation2to != timeout: 

348 self._elevation2to = timeout 

349 LatLonEllipsoidalBase._elevation2._update(self) 

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

351 

352 def ellipsoid(self, datum=_WGS84): 

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

354 

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

356 

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

358 ''' 

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

360 

361 @property_RO 

362 def ellipsoidalLatLon(self): 

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

364 ''' 

365 return type(self) 

366 

367 def ellipsoids(self, other): 

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

369 

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

371 

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

373 

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

375 

376 @raise ValueError: Incompatible datum ellipsoids. 

377 ''' 

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

379 

380 E = self.ellipsoid() 

381 try: # other may be Sphere, etc. 

382 e = other.ellipsoid() 

383 except AttributeError: 

384 try: # no ellipsoid method, try datum 

385 e = other.datum.ellipsoid 

386 except AttributeError: 

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

388 if e != E: 

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

390 return E 

391 

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

393 def epoch(self): 

394 '''Get this point's observed or C{reframe} epoch (C{float}) or C{None}. 

395 ''' 

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

397 

398 @epoch.setter # PYCHOK setter! 

399 def epoch(self, epoch): 

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

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

402 

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

404 ''' 

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

406 

407 @Property_RO 

408 def Equidistant(self): 

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

410 ''' 

411 try: 

412 _ = self.datum.ellipsoid.geodesic 

413 return _MODS.azimuthal.EquidistantKarney 

414 except ImportError: # no geographiclib 

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

416 

417 @Property_RO 

418 def _etm(self): 

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

420 ''' 

421 etm = _MODS.etm 

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

423 

424 @property_RO 

425 def gamma(self): 

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

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

428 ''' 

429 return self._gamma 

430 

431 @Property_RO 

432 def _geoidHeight2(self): 

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

434 ''' 

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

436 timeout=self._geoidHeight2to) 

437 

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

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

440 or sphere. 

441 

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

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

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

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

446 radius). 

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

448 

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

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

451 

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

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

454 the L{elevations.geoidHeight2} is based. 

455 

456 @note: The geoid height is only available for locations within the 

457 U{Conterminous US (CONUS) 

458 <https://WikiPedia.org/wiki/Contiguous_United_States>}. 

459 

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

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

462 ''' 

463 if self._geoidHeight2to != timeout: 

464 self._geoidHeight2to = timeout 

465 LatLonEllipsoidalBase._geoidHeight2._update(self) 

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

467 

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

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

470 _MODS.named.notOverloaded(self, other, fraction, height=height, wrap=wrap) 

471 

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

473 equidistant=None, tol=_TOL_M): 

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

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

476 

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

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

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

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

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

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

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

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

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

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

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

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

489 @kwarg tol: Tolerance for skew line distance and length and for 

490 convergence (C{meter}, conventionally). 

491 

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

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

494 

495 @raise ImportError: Package U{geographiclib 

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

497 not installed or not found, but only if 

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

499 

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

501 non-intersecting lines or no convergence 

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

503 

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

505 is not C{LatLon}. 

506 

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

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

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

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

511 of the authalic earth perimeter). 

512 

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

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

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

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

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

518 ''' 

519 try: 

520 s2 = self.others(other) 

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

522 s2, end2, 

523 height=height, wrap=wrap, 

524 equidistant=equidistant, tol=tol, 

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

526 except (TypeError, ValueError) as x: 

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

528 height=height, wrap=wrap, tol=tol) 

529 

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

531 equidistant=None, tol=_TOL_M): 

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

533 each defined by a center point and a radius. 

534 

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

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

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

538 B{C{radius1}}). 

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

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

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

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

543 center (C{bool}). 

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

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

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

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

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

549 

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

551 instance. For abutting circles, both intersection 

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

553 

554 @raise ImportError: Package U{geographiclib 

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

556 not installed or not found, but only if 

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

558 

559 @raise IntersectionError: Concentric, antipodal, invalid or 

560 non-intersecting circles or no 

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

562 

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

564 

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

566 

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

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

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

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

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

572 intersections. 

573 ''' 

574 try: 

575 c2 = self.others(other) 

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

577 c2, radius2, 

578 height=height, wrap=wrap, 

579 equidistant=equidistant, tol=tol, 

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

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

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

583 height=height, wrap=wrap, tol=tol) 

584 

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

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

587 

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

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

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

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

592 

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

594 C{False} otherwise. 

595 

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

597 

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

599 

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

601 

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

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

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

605 ''' 

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

607 

608 @property_RO 

609 def iteration(self): 

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

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

612 ''' 

613 return self._iteration 

614 

615 @Property_RO 

616 def _lcc(self): 

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

618 ''' 

619 lcc = _MODS.lcc 

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

621 

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

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

624 

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

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

627 mean height (C{meter}). 

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

629 may be negative or greater than 1.0. 

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

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

632 

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

634 

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

636 

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

638 

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

640 ''' 

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

642 

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

644 equidistant=None, tol=_TOL_M): 

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

646 two other (ellipsoidal) points. 

647 

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

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

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

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

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

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

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

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

656 takes the heights of the points into account. 

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

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

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

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

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

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

663 

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

665 

666 @raise ImportError: Package U{geographiclib 

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

668 not installed or not found, but only if 

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

670 

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

672 B{C{equidistant}}. 

673 

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

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

676 

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

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

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

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

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

682 ''' 

683 try: 

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

685 height=height, wrap=wrap, 

686 equidistant=equidistant, 

687 tol=tol, LatLon=self.classof) 

688 except (TypeError, ValueError) as x: 

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

690 height=height, wrap=wrap, tol=tol) 

691 return t.closest 

692 

693 @Property_RO 

694 def _osgr(self): 

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

696 based on the OS recommendation. 

697 ''' 

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

699 

700 @Property_RO 

701 def _osgrTM(self): 

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

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

704 ''' 

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

706 

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

708 sep=_COMMA_, wrap=False, name=NN): 

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

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

711 

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

713 see function L{pygeodesy.parse3llh}. 

714 @kwarg height: Optional, default height (C{meter} or 

715 C{None}). 

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

717 datum I{without conversion}. 

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

719 epoch I{without conversion}. 

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

721 this reframe I{without conversion}. 

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

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

724 and longitude (C{bool}). 

725 @kwarg name: Optional instance name (C{str}), overriding 

726 this name. 

727 

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

729 

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

731 ''' 

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

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

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

735 r.datum = datum 

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

737 r.epoch = epoch 

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

739 r.reframe = reframe 

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

741 

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

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

744 difference in Gaussian radii of curvature of the given 

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

746 

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

748 ''' 

749 if adjust: # Elevation2Tuple or GeoidHeight2Tuple 

750 m, t = meter_text2 

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

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

753 if n > EPS0: 

754 # use ratio, datum and NAD83 units may differ 

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

756 _earth_ellipsoid(datum) 

757 r = E.rocGauss(self.lat) 

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

759 m *= r / n 

760 meter_text2 = meter_text2.classof(m, t) 

761 return self._xnamed(meter_text2) 

762 

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

764 def reframe(self): 

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

766 ''' 

767 return self._reframe 

768 

769 @reframe.setter # PYCHOK setter! 

770 def reframe(self, reframe): 

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

772 

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

774 ''' 

775 _set_reframe(self, reframe) 

776 

777 @Property_RO 

778 def scale(self): 

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

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

781 ''' 

782 return self._scale 

783 

784 def toCss(self, **toCss_kwds): 

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

786 

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

788 

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

790 

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

792 ''' 

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

794 self, **_xkwds(toCss_kwds, name=self.name)) 

795 

796 def toDatum(self, datum2, height=None, name=NN): 

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

798 

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

800 @kwarg height: Optional height, overriding the 

801 converted height (C{meter}). 

802 @kwarg name: Optional name (C{str}), iff converted. 

803 

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

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

806 matches this point's C{datum}. 

807 

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

809 ''' 

810 n = name or self.name 

811 d2 = _ellipsoidal_datum(datum2, name=n) 

812 if self.datum == d2: 

813 r = self.copy(name=name) 

814 else: 

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

816 epoch=self.epoch, reframe=self.reframe) 

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

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

819 return r 

820 

821 def toEtm(self, **toEtm8_kwds): 

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

823 

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

825 

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

827 

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

829 ''' 

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

831 self, **_xkwds(toEtm8_kwds, name=self.name)) 

832 

833 def toLcc(self, **toLcc_kwds): 

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

835 

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

837 

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

839 

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

841 ''' 

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

843 self, **_xkwds(toLcc_kwds, name=self.name)) 

844 

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

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

847 

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

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

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

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

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

853 

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

855 

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

857 ''' 

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

859 

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

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

862 

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

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

865 formulation (C{bool}). 

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

867 

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

869 

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

871 ''' 

872 if toOsgr_kwds: 

873 r = _MODS.osgr.toOsgr(self, kTM=kTM, **_xkwds(toOsgr_kwds, name=self.name)) 

874 else: 

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

876 return r 

877 

878 def toRefFrame(self, reframe2, height=None, name=NN): 

879 '''Convert this point to an other reference frame. 

880 

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

882 @kwarg height: Optional height, overriding the converted 

883 height (C{meter}). 

884 @kwarg name: Optional name (C{str}), iff converted. 

885 

886 @return: The converted point (ellipsoidal C{LatLon}) or this 

887 point if conversion is C{nil}, or a copy of this 

888 point if the B{C{name}} is non-empty. 

889 

890 @raise TRFError: This point's C{reframe} is not defined or 

891 conversion from this point's C{reframe} to 

892 B{C{reframe2}} is not available. 

893 

894 @raise TypeError: Invalid B{C{reframe2}}, not a L{RefFrame}. 

895 ''' 

896 if not self.reframe: 

897 t = _SPACE_(_DOT_(repr(self), _reframe_), MISSING) 

898 raise TRFError(_no_(_conversion_), txt=t) 

899 

900 trf = _MODS.trf 

901 trf._xinstanceof(trf.RefFrame, reframe2=reframe2) 

902 

903 e, xs = trf._reframeTransforms2(reframe2, self.reframe, self.epoch) 

904 if xs: 

905 c = self.toCartesian().toTransforms_(*xs) 

906 n = name or self.name 

907 ll = c.toLatLon(datum=self.datum, epoch=e, height=height, 

908 LatLon=self.classof, name=n, reframe=reframe2) 

909 else: 

910 ll = self.copy(name=name) if name else self 

911 return ll 

912 

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

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

915 

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

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

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

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

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

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

922 

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

924 

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

926 ''' 

927 if self._upsOK(pole, falsed): 

928 u = self._ups 

929 else: 

930 ups = _MODS.ups 

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

932 pole=pole, falsed=falsed) 

933 return _lowerleft(u, center) 

934 

935 def toUtm(self, center=False): 

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

937 

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

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

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

941 

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

943 

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

945 ''' 

946 return _lowerleft(self._utm, center) 

947 

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

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

950 

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

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

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

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

955 meter} (C{scalar}). 

956 

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

958 

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

960 ''' 

961 if self._utmOK(): 

962 u = self._utm 

963 elif self._upsOK(pole): 

964 u = self._ups 

965 else: # no cover 

966 utmups = _MODS.utmups 

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

968 Utm=utmups.Utm, Ups=utmups.Ups) 

969 if isinstance(u, utmups.Utm): 

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

971 elif isinstance(u, utmups.Ups): 

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

973 else: 

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

975 return _lowerleft(u, center) 

976 

977 @deprecated_method 

978 def to3xyz(self): # PYCHOK no cover 

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

980 

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

982 

983 @note: Overloads C{LatLonBase.to3xyz} 

984 ''' 

985 r = self.toEcef() 

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

987 

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

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

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

991 intersection} of three intersecting circles. 

992 

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

994 as B{C{eps}}). 

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

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

997 B{C{eps}}). 

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

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

1000 B{C{eps}}). 

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

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

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

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

1005 (C{meter}, conventionally). 

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

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

1008 

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

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

1011 the corresponding trilaterated points C{minPoint} and 

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

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

1014 

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

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

1017 

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

1019 respectively largest I{radial} overlap found. 

1020 

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

1022 nearest respectively farthest intersection margin. 

1023 

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

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

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

1027 largest B{C{distance#}}. 

1028 

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

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

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

1032 all circles are (near-)concentric. 

1033 

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

1035 

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

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

1038 

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

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

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

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

1043 ''' 

1044 return _trilaterate5(self, distance1, 

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

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

1047 area=area, eps=eps, wrap=wrap) 

1048 

1049 @Property_RO 

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

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

1052 see L{pygeodesy.toUps8}. 

1053 ''' 

1054 ups = _MODS.ups 

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

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

1057 

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

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

1060 ''' 

1061 try: 

1062 u = self._ups 

1063 except RangeError: 

1064 return False 

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

1066 

1067 @Property_RO 

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

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

1070 see L{pygeodesy.toUtm8}. 

1071 ''' 

1072 utm = _MODS.utm 

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

1074 

1075 def _utmOK(self): 

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

1077 ''' 

1078 try: 

1079 _ = self._utm 

1080 except RangeError: 

1081 return False 

1082 return True 

1083 

1084 

1085def _lowerleft(utmups, center): 

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

1087 ''' 

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

1089 u = utmups 

1090 elif center in (True,): 

1091 u = utmups._lowerleft 

1092 else: 

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

1094 return u 

1095 

1096 

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

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

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

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

1101 ''' 

1102 try: 

1103 p = _xellipsoidal(point=point) 

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

1105 height=height, wrap=wrap, 

1106 equidistant=equidistant, 

1107 tol=tol, **LatLon_and_kwds) 

1108 except (TypeError, ValueError) as x: 

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

1110 return t.closest 

1111 

1112 

1113def _set_reframe(inst, reframe): 

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

1115 ''' 

1116 if reframe is not None: 

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

1118 inst._reframe = reframe 

1119 elif inst.reframe is not None: 

1120 inst._reframe = None 

1121 

1122 

1123__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase) 

1124 

1125# **) MIT License 

1126# 

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

1128# 

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

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

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

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

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

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

1135# 

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

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

1138# 

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

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

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

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

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

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

1145# OTHER DEALINGS IN THE SOFTWARE.