Coverage for pygeodesy/ellipsoidalBase.py: 95%

291 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-12-02 13:46 -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, _xinstanceof # _spherical_datum 

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

21 _ValueError, _xattr, _xellipsoidal, _xError, \ 

22 _xkwds, _xkwds_get, _xkwds_not 

23# from pygeodesy.fmath import favg # _MODS 

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

25 _ellipsoidal_, _no_, _reframe_, _SPACE_ 

26from pygeodesy.latlonBase import LatLonBase, _trilaterate5, \ 

27 fabs, Vector3Tuple, _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 # from .latlonBase 

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.11.08' 

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 @example: 

218 

219 >>> p = LatLon(51.4778, -0.0016) # height=0, datum=Datums.WGS84 

220 ''' 

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

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

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

224 if reframe: 

225 self.reframe = reframe 

226 self.epoch = epoch 

227 

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

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

230# ''' 

231# RefFrame = _MODS.trf.RefFrame 

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

233# _NotImplemented(self, other) 

234 

235 def antipode(self, height=None): 

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

237 to this point. 

238 

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

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

241 

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

243 ''' 

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

245 if lla.datum != self.datum: 

246 lla.datum = self.datum 

247 return lla 

248 

249 @deprecated_property_RO 

250 def convergence(self): 

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

252 return self.gamma 

253 

254 @deprecated_method 

255 def convertDatum(self, datum2): 

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

257 return self.toDatum(datum2) 

258 

259 @deprecated_method 

260 def convertRefFrame(self, reframe2): 

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

262 return self.toRefFrame(reframe2) 

263 

264 @Property_RO 

265 def _css(self): 

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

267 ''' 

268 css = _MODS.css 

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

270 

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

272 def datum(self): 

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

274 ''' 

275 return self._datum 

276 

277 @datum.setter # PYCHOK setter! 

278 def datum(self, datum): 

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

280 

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

282 or not ellipsoidal. 

283 ''' 

284 _xinstanceof(Datum, datum=datum) 

285 if not datum.isEllipsoidal: 

286 raise _IsnotError(_ellipsoidal_, datum=datum) 

287 if self._datum != datum: 

288 _update_all(self) 

289 self._datum = datum 

290 

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

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

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

294 

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

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

297 

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

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

300 point (C{bool}). 

301 

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

303 

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

305 

306 @raise ValueError: Incompatible datum ellipsoids. 

307 

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

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

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

311 formula. 

312 ''' 

313 p = self.others(other) 

314 if wrap: 

315 p = _Wrap.point(p) 

316 E = self.ellipsoids(other) 

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

318 

319 @Property_RO 

320 def _elevation2(self): 

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

322 ''' 

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

324 timeout=self._elevation2to) 

325 

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

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

328 or sphere. 

329 

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

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

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

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

334 radius). 

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

336 

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

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

339 

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

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

342 L{elevations.elevation2} is based. 

343 

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

345 U{Conterminous US (CONUS) 

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

347 

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

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

350 ''' 

351 if self._elevation2to != timeout: 

352 self._elevation2to = timeout 

353 LatLonEllipsoidalBase._elevation2._update(self) 

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

355 

356 def ellipsoid(self, datum=_WGS84): 

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

358 

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

360 

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

362 ''' 

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

364 

365 @property_RO 

366 def ellipsoidalLatLon(self): 

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

368 ''' 

369 return type(self) 

370 

371 def ellipsoids(self, other): 

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

373 

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

375 

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

377 

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

379 

380 @raise ValueError: Incompatible datum ellipsoids. 

381 ''' 

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

383 

384 E = self.ellipsoid() 

385 try: # other may be Sphere, etc. 

386 e = other.ellipsoid() 

387 except AttributeError: 

388 try: # no ellipsoid method, try datum 

389 e = other.datum.ellipsoid 

390 except AttributeError: 

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

392 if e != E: 

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

394 return E 

395 

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

397 def epoch(self): 

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

399 ''' 

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

401 

402 @epoch.setter # PYCHOK setter! 

403 def epoch(self, epoch): 

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

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

406 

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

408 ''' 

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

410 

411 @Property_RO 

412 def Equidistant(self): 

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

414 ''' 

415 try: 

416 _ = self.datum.ellipsoid.geodesic 

417 return _MODS.azimuthal.EquidistantKarney 

418 except ImportError: # no geographiclib 

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

420 

421 @Property_RO 

422 def _etm(self): 

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

424 ''' 

425 etm = _MODS.etm 

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

427 

428 @property_RO 

429 def gamma(self): 

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

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

432 ''' 

433 return self._gamma 

434 

435 @Property_RO 

436 def _geoidHeight2(self): 

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

438 ''' 

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

440 timeout=self._geoidHeight2to) 

441 

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

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

444 or sphere. 

445 

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

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

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

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

450 radius). 

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

452 

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

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

455 

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

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

458 the L{elevations.geoidHeight2} is based. 

459 

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

461 U{Conterminous US (CONUS) 

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

463 

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

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

466 ''' 

467 if self._geoidHeight2to != timeout: 

468 self._geoidHeight2to = timeout 

469 LatLonEllipsoidalBase._geoidHeight2._update(self) 

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

471 

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

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

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

475 

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

477 equidistant=None, tol=_TOL_M): 

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

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

480 

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

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

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

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

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

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

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

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

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

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

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

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

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

494 convergence (C{meter}, conventionally). 

495 

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

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

498 

499 @raise ImportError: Package U{geographiclib 

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

501 not installed or not found, but only if 

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

503 

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

505 non-intersecting lines or no convergence 

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

507 

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

509 is not C{LatLon}. 

510 

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

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

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

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

515 of the authalic earth perimeter). 

516 

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

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

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

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

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

522 ''' 

523 try: 

524 s2 = self.others(other) 

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

526 s2, end2, 

527 height=height, wrap=wrap, 

528 equidistant=equidistant, tol=tol, 

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

530 except (TypeError, ValueError) as x: 

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

532 height=height, wrap=wrap, tol=tol) 

533 

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

535 equidistant=None, tol=_TOL_M): 

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

537 each defined by a center point and a radius. 

538 

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

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

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

542 B{C{radius1}}). 

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

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

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

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

547 center (C{bool}). 

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

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

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

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

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

553 

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

555 instance. For abutting circles, both intersection 

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

557 

558 @raise ImportError: Package U{geographiclib 

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

560 not installed or not found, but only if 

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

562 

563 @raise IntersectionError: Concentric, antipodal, invalid or 

564 non-intersecting circles or no 

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

566 

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

568 

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

570 

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

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

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

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

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

576 intersections. 

577 ''' 

578 try: 

579 c2 = self.others(other) 

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

581 c2, radius2, 

582 height=height, wrap=wrap, 

583 equidistant=equidistant, tol=tol, 

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

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

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

587 height=height, wrap=wrap, tol=tol) 

588 

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

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

591 

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

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

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

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

596 

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

598 C{False} otherwise. 

599 

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

601 

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

603 

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

605 

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

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

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

609 ''' 

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

611 

612 @property_RO 

613 def iteration(self): 

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

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

616 ''' 

617 return self._iteration 

618 

619 @Property_RO 

620 def _lcc(self): 

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

622 ''' 

623 lcc = _MODS.lcc 

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

625 

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

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

628 

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

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

631 mean height (C{meter}). 

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

633 may be negative or greater than 1.0. 

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

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

636 

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

638 

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

640 

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

642 

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

644 ''' 

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

646 

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

648 equidistant=None, tol=_TOL_M): 

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

650 two other (ellipsoidal) points. 

651 

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

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

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

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

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

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

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

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

660 takes the heights of the points into account. 

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

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

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

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

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

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

667 

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

669 

670 @raise ImportError: Package U{geographiclib 

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

672 not installed or not found, but only if 

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

674 

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

676 B{C{equidistant}}. 

677 

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

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

680 

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

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

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

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

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

686 ''' 

687 try: 

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

689 height=height, wrap=wrap, 

690 equidistant=equidistant, 

691 tol=tol, LatLon=self.classof) 

692 except (TypeError, ValueError) as x: 

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

694 height=height, wrap=wrap, tol=tol) 

695 return t.closest 

696 

697 @Property_RO 

698 def _osgr(self): 

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

700 based on the OS recommendation. 

701 ''' 

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

703 

704 @Property_RO 

705 def _osgrTM(self): 

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

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

708 ''' 

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

710 

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

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

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

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

715 

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

717 see function L{pygeodesy.parse3llh}. 

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

719 C{None}). 

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

721 datum I{without conversion}. 

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

723 epoch I{without conversion}. 

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

725 this reframe I{without conversion}. 

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

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

728 and longitude (C{bool}). 

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

730 this name. 

731 

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

733 

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

735 ''' 

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

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

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

739 r.datum = datum 

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

741 r.epoch = epoch 

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

743 r.reframe = reframe 

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

745 

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

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

748 difference in Gaussian radii of curvature of the given 

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

750 

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

752 ''' 

753 if adjust: # Elevation2Tuple or GeoidHeight2Tuple 

754 m, t = meter_text2 

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

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

757 if n > EPS0: 

758 # use ratio, datum and NAD83 units may differ 

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

760 _earth_ellipsoid(datum) 

761 r = E.rocGauss(self.lat) 

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

763 m *= r / n 

764 meter_text2 = meter_text2.classof(m, t) 

765 return self._xnamed(meter_text2) 

766 

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

768 def reframe(self): 

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

770 ''' 

771 return self._reframe 

772 

773 @reframe.setter # PYCHOK setter! 

774 def reframe(self, reframe): 

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

776 

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

778 ''' 

779 _set_reframe(self, reframe) 

780 

781 @Property_RO 

782 def scale(self): 

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

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

785 ''' 

786 return self._scale 

787 

788 def toCss(self, **toCss_kwds): 

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

790 

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

792 

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

794 

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

796 ''' 

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

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

799 

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

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

802 

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

804 @kwarg height: Optional height, overriding the 

805 converted height (C{meter}). 

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

807 

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

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

810 matches this point's C{datum}. 

811 

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

813 

814 @example: 

815 

816 >>> p = LatLon(51.4778, -0.0016) # default Datums.WGS84 

817 >>> p.toDatum(Datums.OSGB36) # 51.477284°N, 000.00002°E 

818 ''' 

819 n = name or self.name 

820 d2 = _ellipsoidal_datum(datum2, name=n) 

821 if self.datum == d2: 

822 r = self.copy(name=name) 

823 else: 

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

825 epoch=self.epoch, reframe=self.reframe) 

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

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

828 return r 

829 

830 def toEtm(self, **toEtm8_kwds): 

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

832 

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

834 

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

836 

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

838 ''' 

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

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

841 

842 def toLcc(self, **toLcc_kwds): 

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

844 

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

846 

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

848 

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

850 ''' 

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

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

853 

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

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

856 

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

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

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

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

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

862 

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

864 

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

866 ''' 

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

868 

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

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

871 

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

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

874 formulation (C{bool}). 

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

876 

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

878 

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

880 ''' 

881 if toOsgr_kwds: 

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

883 else: 

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

885 return r 

886 

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

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

889 

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

891 @kwarg height: Optional height, overriding the converted 

892 height (C{meter}). 

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

894 

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

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

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

898 

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

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

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

902 

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

904 

905 @example: 

906 

907 >>> p = LatLon(51.4778, -0.0016, reframe=RefFrames.ETRF2000) # default Datums.WGS84 

908 >>> p.toRefFrame(RefFrames.ITRF2014) # 51.477803°N, 000.001597°W, +0.01m 

909 >>> p.toRefFrame(RefFrames.ITRF2014, height=0) # 51.477803°N, 000.001597°W 

910 ''' 

911 if not self.reframe: 

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

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

914 

915 trf = _MODS.trf 

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

917 

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

919 if xs: 

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

921 n = name or self.name 

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

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

924 else: 

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

926 return ll 

927 

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

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

930 

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

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

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

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

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

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

937 

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

939 

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

941 ''' 

942 if self._upsOK(pole, falsed): 

943 u = self._ups 

944 else: 

945 ups = _MODS.ups 

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

947 pole=pole, falsed=falsed) 

948 return _lowerleft(u, center) 

949 

950 def toUtm(self, center=False): 

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

952 

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

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

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

956 

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

958 

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

960 ''' 

961 return _lowerleft(self._utm, center) 

962 

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

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

965 

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

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

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

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

970 meter} (C{scalar}). 

971 

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

973 

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

975 ''' 

976 if self._utmOK(): 

977 u = self._utm 

978 elif self._upsOK(pole): 

979 u = self._ups 

980 else: # no cover 

981 utmups = _MODS.utmups 

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

983 Utm=utmups.Utm, Ups=utmups.Ups) 

984 if isinstance(u, utmups.Utm): 

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

986 elif isinstance(u, utmups.Ups): 

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

988 else: 

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

990 return _lowerleft(u, center) 

991 

992 @deprecated_method 

993 def to3xyz(self): # PYCHOK no cover 

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

995 

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

997 

998 @note: Overloads C{LatLonBase.to3xyz} 

999 ''' 

1000 r = self.toEcef() 

1001 return Vector3Tuple(r.x, r.y, r.z, name=self.name) 

1002 

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

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

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

1006 intersection} of three intersecting circles. 

1007 

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

1009 as B{C{eps}}). 

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

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

1012 B{C{eps}}). 

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

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

1015 B{C{eps}}). 

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

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

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

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

1020 (C{meter}, conventionally). 

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

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

1023 

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

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

1026 the corresponding trilaterated points C{minPoint} and 

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

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

1029 

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

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

1032 

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

1034 respectively largest I{radial} overlap found. 

1035 

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

1037 nearest respectively farthest intersection margin. 

1038 

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

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

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

1042 largest B{C{distance#}}. 

1043 

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

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

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

1047 all circles are (near-)concentric. 

1048 

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

1050 

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

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

1053 

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

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

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

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

1058 ''' 

1059 return _trilaterate5(self, distance1, 

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

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

1062 area=area, eps=eps, wrap=wrap) 

1063 

1064 @Property_RO 

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

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

1067 see L{pygeodesy.toUps8}. 

1068 ''' 

1069 ups = _MODS.ups 

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

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

1072 

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

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

1075 ''' 

1076 try: 

1077 u = self._ups 

1078 except RangeError: 

1079 return False 

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

1081 

1082 @Property_RO 

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

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

1085 see L{pygeodesy.toUtm8}. 

1086 ''' 

1087 utm = _MODS.utm 

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

1089 

1090 def _utmOK(self): 

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

1092 ''' 

1093 try: 

1094 _ = self._utm 

1095 except RangeError: 

1096 return False 

1097 return True 

1098 

1099 

1100def _lowerleft(utmups, center): 

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

1102 ''' 

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

1104 u = utmups 

1105 elif center in (True,): 

1106 u = utmups._lowerleft 

1107 else: 

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

1109 return u 

1110 

1111 

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

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

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

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

1116 ''' 

1117 try: 

1118 p = _xellipsoidal(point=point) 

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

1120 height=height, wrap=wrap, 

1121 equidistant=equidistant, 

1122 tol=tol, **LatLon_and_kwds) 

1123 except (TypeError, ValueError) as x: 

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

1125 return t.closest 

1126 

1127 

1128def _set_reframe(inst, reframe): 

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

1130 ''' 

1131 if reframe is not None: 

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

1133 inst._reframe = reframe 

1134 elif inst.reframe is not None: 

1135 inst._reframe = None 

1136 

1137 

1138__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase) 

1139 

1140# **) MIT License 

1141# 

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

1143# 

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

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

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

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

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

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

1150# 

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

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

1153# 

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

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

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

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

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

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

1160# OTHER DEALINGS IN THE SOFTWARE.