Coverage for pygeodesy/ellipsoidalBase.py: 89%

309 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-10-11 16:04 -0400

1 

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

3 

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

5and C{LatLonEllipsoidalBase}. 

6 

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

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

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

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

11''' 

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

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

14 

15from pygeodesy.basics import isinstanceof, _xinstanceof 

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

17from pygeodesy.cartesianBase import CartesianBase, _ellipsoidal_ # PYCHOK used! 

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

19 _spherical_datum, _WGS84 

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

21 _ValueError, _xattr, _xellipsoidal, _xError, \ 

22 _xkwds, _xkwds_get, _xkwds_not 

23# from pygeodesy.interns import _ellipsoidal_ # from .cartesianBase 

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

25 _no_, _reframe_, _SPACE_ 

26from pygeodesy.latlonBase import _intersecend2, LatLonBase, _trilaterate5, \ 

27 fabs, _unrollon, 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 Bearing, Epoch, _1mm as _TOL_M, Radius_ 

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

36 

37# from math import fabs # from .latlonBase 

38 

39__all__ = _ALL_LAZY.ellipsoidalBase 

40__version__ = '23.10.10' 

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 def intersections2(self, radius, center2, radius2, sphere=True, 

62 Vector=None, **Vector_kwds): 

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

64 cartesian center point and a radius. 

65 

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

67 coordinates). 

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

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

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

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

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

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

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

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

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

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

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

79 

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

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

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

83 

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

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

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

87 

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

89 

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

91 

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

93 

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

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

96 Intersection and function L{pygeodesy.radical2}. 

97 ''' 

98 try: 

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

100 center2, Radius_(radius2=radius2), 

101 sphere=sphere, clas=self.classof, 

102 Vector=Vector, **Vector_kwds) 

103 except (TypeError, ValueError) as x: 

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

105 

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

107 def reframe(self): 

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

109 ''' 

110 return self._reframe 

111 

112 @reframe.setter # PYCHOK setter! 

113 def reframe(self, reframe): 

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

115 

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

117 ''' 

118 _set_reframe(self, reframe) 

119 

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

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

122 

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

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

125 overriding this cartesian's C{reframe}. 

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

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

128 

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

130 conversion is C{nil}. 

131 

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

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

134 

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

136 L{RefFrame}. 

137 ''' 

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

139 if r in (None, reframe2): 

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

141 else: 

142 trf = _MODS.trf 

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

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

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

146 

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

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

149 

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

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

152 overriding this point's datum. 

153 

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

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

156 ''' 

157 r = self 

158 if transforms: 

159 xyz = r.xyz 

160 for t in transforms: 

161 xyz = t.transform(*xyz) 

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

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

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

165 return r 

166 

167 

168class LatLonEllipsoidalBase(LatLonBase): 

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

170 ''' 

171 _datum = _WGS84 # L{Datum} 

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

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

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

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

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

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

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

179 

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

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

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

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

184 the given reference frame and epoch. 

185 

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

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

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

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

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

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

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

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

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

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

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

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

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

199 (C{bool}). 

200 @kwarg name: Optional name (string). 

201 

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

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

204 

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

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

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

208 

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

210 

211 @example: 

212 

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

214 ''' 

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

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

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

218 if reframe: 

219 self.reframe = reframe 

220 self.epoch = epoch 

221 

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

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

224# ''' 

225# RefFrame = _MODS.trf.RefFrame 

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

227# _NotImplemented(self, other) 

228 

229 def antipode(self, height=None): 

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

231 to this point. 

232 

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

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

235 

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

237 ''' 

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

239 if lla.datum != self.datum: 

240 lla.datum = self.datum 

241 return lla 

242 

243 @deprecated_property_RO 

244 def convergence(self): 

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

246 return self.gamma 

247 

248 @deprecated_method 

249 def convertDatum(self, datum2): 

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

251 return self.toDatum(datum2) 

252 

253 @deprecated_method 

254 def convertRefFrame(self, reframe2): 

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

256 return self.toRefFrame(reframe2) 

257 

258 @Property_RO 

259 def _css(self): 

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

261 ''' 

262 css = _MODS.css 

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

264 

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

266 def datum(self): 

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

268 ''' 

269 return self._datum 

270 

271 @datum.setter # PYCHOK setter! 

272 def datum(self, datum): 

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

274 

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

276 or not ellipsoidal. 

277 ''' 

278 _xinstanceof(Datum, datum=datum) 

279 if not datum.isEllipsoidal: 

280 raise _IsnotError(_ellipsoidal_, datum=datum) 

281 if self._datum != datum: 

282 _update_all(self) 

283 self._datum = datum 

284 

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

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

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

288 

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

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

291 

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

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

294 point (C{bool}). 

295 

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

297 

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

299 

300 @raise ValueError: Incompatible datum ellipsoids. 

301 

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

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

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

305 formula. 

306 ''' 

307 p = self.others(other) 

308 if wrap: 

309 p = _Wrap.point(p) 

310 E = self.ellipsoids(other) 

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

312 

313 @Property_RO 

314 def _elevation2(self): 

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

316 ''' 

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

318 timeout=self._elevation2to) 

319 

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

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

322 or sphere. 

323 

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

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

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

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

328 radius). 

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

330 

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

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

333 

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

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

336 L{elevations.elevation2} is based. 

337 

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

339 U{Conterminous US (CONUS) 

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

341 

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

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

344 ''' 

345 if self._elevation2to != timeout: 

346 self._elevation2to = timeout 

347 LatLonEllipsoidalBase._elevation2._update(self) 

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

349 

350 def ellipsoid(self, datum=_WGS84): 

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

352 

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

354 

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

356 ''' 

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

358 

359 def ellipsoids(self, other): 

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

361 

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

363 

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

365 

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

367 

368 @raise ValueError: Incompatible datum ellipsoids. 

369 ''' 

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

371 

372 E = self.ellipsoid() 

373 try: # other may be Sphere, etc. 

374 e = other.ellipsoid() 

375 except AttributeError: 

376 try: # no ellipsoid method, try datum 

377 e = other.datum.ellipsoid 

378 except AttributeError: 

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

380 if e != E: 

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

382 return E 

383 

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

385 def epoch(self): 

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

387 ''' 

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

389 

390 @epoch.setter # PYCHOK setter! 

391 def epoch(self, epoch): 

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

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

394 

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

396 ''' 

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

398 

399 @Property_RO 

400 def Equidistant(self): 

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

402 ''' 

403 try: 

404 _ = self.datum.ellipsoid.geodesic 

405 return _MODS.azimuthal.EquidistantKarney 

406 except ImportError: # no geographiclib 

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

408 

409 @Property_RO 

410 def _etm(self): 

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

412 ''' 

413 etm = _MODS.etm 

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

415 

416 @property_RO 

417 def gamma(self): 

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

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

420 ''' 

421 return self._gamma 

422 

423 @Property_RO 

424 def _geoidHeight2(self): 

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

426 ''' 

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

428 timeout=self._geoidHeight2to) 

429 

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

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

432 or sphere. 

433 

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

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

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

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

438 radius). 

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

440 

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

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

443 

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

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

446 the L{elevations.geoidHeight2} is based. 

447 

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

449 U{Conterminous US (CONUS) 

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

451 

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

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

454 ''' 

455 if self._geoidHeight2to != timeout: 

456 self._geoidHeight2to = timeout 

457 LatLonEllipsoidalBase._geoidHeight2._update(self) 

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

459 

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

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

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

463 

464 def intersecant2(self, circle, point, bearing, radius=None, exact=False, 

465 height=None, wrap=False): 

466 '''Compute the intersections of a circle and a line given as a point 

467 and bearing or as two points. 

468 

469 @arg circle: Radius of the circle centered at this location (C{meter}, 

470 same units as B{C{radius}}) or a point on the circle 

471 (this C{LatLon}). 

472 @arg point: An other point in- or outside the circle on the line (this 

473 C{LatLon}). 

474 @arg bearing: Bearing at the B{C{point}} (compass C{degrees360}) or an 

475 other point on the line (this C{LatLon}). 

476 @kwarg radius: Optional earth radius (C{meter}) or earth model (L{Datum}, 

477 L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}), overriding 

478 this and the B{C{point}}'s datum. 

479 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}), see 

480 method L{Ellipsoid.rhumb_}. 

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

482 conventionally) or C{None}. 

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

484 B{C{point}}, B{C{circle}} and/or B{C{bearing}} (C{bool}). 

485 

486 @return: 2-Tuple of the intersection points (representing a chord), 

487 each an instance of this class. For a tangent line, both 

488 points are the same instance, the B{C{point}} or wrapped 

489 or I{normalized}. 

490 

491 @raise IntersectionError: The circle and line do not intersect. 

492 

493 @raise TypeError: If B{C{point}} is not this C{LatLon} or B{C{circle}} 

494 or B{C{bearing}} invalid. 

495 

496 @raise ValueError: Invalid B{C{circle}}, B{C{bearing}}, B{C{radius}}, 

497 B{C{exact}} or B{C{height}}. 

498 

499 @see: Methods L{RhumbLineAux.Intersecant2} and L{RhumbLine.Intersecant2}. 

500 ''' 

501 c, p = self, self.others(point=point) 

502 try: 

503 if wrap: 

504 p = _unrollon(c, p, wrap=wrap) 

505 

506 r = circle 

507 if isinstanceof(r, c.__class__, p.__class__): 

508 r = c.rhumbDistanceTo(r, radius=radius, exact=exact, wrap=wrap) 

509 else: 

510 r = Radius_(circle=r) 

511 

512 b = bearing 

513 if isinstanceof(b, c.__class__, p.__class__): 

514 b = p.rhumbAzimuthTo(b, radius=radius, exact=exact, wrap=wrap) 

515 else: 

516 b = Bearing(b) 

517 

518 R, _, Cs = p._rhumb3(exact, radius) 

519 d = R._Inverse(p, c, False, outmask=Cs.AZIMUTH_DISTANCE) 

520 return _intersecend2(p, d.s12, d.azi12, b, r, radius, height, exact) 

521 

522 except (TypeError, ValueError) as x: 

523 raise _xError(x, center=self, circle=circle, point=point, bearing=bearing, 

524 exact=exact, wrap=wrap) 

525 

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

527 equidistant=None, tol=_TOL_M): 

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

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

530 

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

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

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

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

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

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

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

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

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

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

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

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

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

544 convergence (C{meter}, conventionally). 

545 

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

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

548 

549 @raise ImportError: Package U{geographiclib 

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

551 not installed or not found, but only if 

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

553 

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

555 non-intersecting lines or no convergence 

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

557 

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

559 is not C{LatLon}. 

560 

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

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

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

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

565 of the authalic earth perimeter). 

566 

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

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

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

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

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

572 ''' 

573 try: 

574 s2 = self.others(other) 

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

576 s2, end2, 

577 height=height, wrap=wrap, 

578 equidistant=equidistant, tol=tol, 

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

580 except (TypeError, ValueError) as x: 

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

582 height=height, wrap=wrap, tol=tol) 

583 

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

585 equidistant=None, tol=_TOL_M): 

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

587 each defined by a center point and a radius. 

588 

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

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

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

592 B{C{radius1}}). 

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

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

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

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

597 center (C{bool}). 

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

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

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

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

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

603 

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

605 instance. For abutting circles, both intersection 

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

607 

608 @raise ImportError: Package U{geographiclib 

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

610 not installed or not found, but only if 

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

612 

613 @raise IntersectionError: Concentric, antipodal, invalid or 

614 non-intersecting circles or no 

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

616 

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

618 

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

620 

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

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

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

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

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

626 intersections. 

627 ''' 

628 try: 

629 c2 = self.others(other) 

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

631 c2, radius2, 

632 height=height, wrap=wrap, 

633 equidistant=equidistant, tol=tol, 

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

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

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

637 height=height, wrap=wrap, tol=tol) 

638 

639 @Property_RO 

640 def isEllipsoidalLatLon(self): 

641 '''Get C{LatLon} base. 

642 ''' 

643 return True 

644 

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

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

647 

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

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

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

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

652 

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

654 C{False} otherwise. 

655 

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

657 

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

659 

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

661 

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

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

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

665 ''' 

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

667 

668 @property_RO 

669 def iteration(self): 

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

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

672 ''' 

673 return self._iteration 

674 

675 @Property_RO 

676 def _lcc(self): 

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

678 ''' 

679 lcc = _MODS.lcc 

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

681 

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

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

684 

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

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

687 mean height (C{meter}). 

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

689 may be negative or greater than 1.0. 

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

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

692 

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

694 

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

696 

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

698 

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

700 ''' 

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

702 

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

704 equidistant=None, tol=_TOL_M): 

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

706 two other (ellipsoidal) points. 

707 

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

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

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

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

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

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

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

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

716 takes the heights of the points into account. 

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

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

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

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

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

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

723 

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

725 

726 @raise ImportError: Package U{geographiclib 

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

728 not installed or not found, but only if 

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

730 

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

732 B{C{equidistant}}. 

733 

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

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

736 

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

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

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

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

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

742 ''' 

743 try: 

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

745 height=height, wrap=wrap, 

746 equidistant=equidistant, 

747 tol=tol, LatLon=self.classof) 

748 except (TypeError, ValueError) as x: 

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

750 height=height, wrap=wrap, tol=tol) 

751 return t.closest 

752 

753 @Property_RO 

754 def _osgr(self): 

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

756 based on the OS recommendation. 

757 ''' 

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

759 

760 @Property_RO 

761 def _osgrTM(self): 

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

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

764 ''' 

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

766 

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

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

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

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

771 

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

773 see function L{pygeodesy.parse3llh}. 

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

775 C{None}). 

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

777 datum I{without conversion}. 

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

779 epoch I{without conversion}. 

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

781 this reframe I{without conversion}. 

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

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

784 and longitude (C{bool}). 

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

786 this name. 

787 

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

789 

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

791 ''' 

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

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

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

795 r.datum = datum 

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

797 r.epoch = epoch 

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

799 r.reframe = reframe 

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

801 

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

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

804 difference in Gaussian radii of curvature of the given 

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

806 

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

808 ''' 

809 if adjust: # Elevation2Tuple or GeoidHeight2Tuple 

810 m, t = meter_text2 

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

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

813 if n > EPS0: 

814 # use ratio, datum and NAD83 units may differ 

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

816 _spherical_datum(datum).ellipsoid 

817 r = E.rocGauss(self.lat) 

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

819 m *= r / n 

820 meter_text2 = meter_text2.classof(m, t) 

821 return self._xnamed(meter_text2) 

822 

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

824 def reframe(self): 

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

826 ''' 

827 return self._reframe 

828 

829 @reframe.setter # PYCHOK setter! 

830 def reframe(self, reframe): 

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

832 

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

834 ''' 

835 _set_reframe(self, reframe) 

836 

837 @Property_RO 

838 def scale(self): 

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

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

841 ''' 

842 return self._scale 

843 

844 def toCss(self, **toCss_kwds): 

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

846 

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

848 

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

850 

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

852 ''' 

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

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

855 

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

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

858 

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

860 @kwarg height: Optional height, overriding the 

861 converted height (C{meter}). 

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

863 

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

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

866 matches this point's C{datum}. 

867 

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

869 

870 @example: 

871 

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

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

874 ''' 

875 n = name or self.name 

876 d2 = _ellipsoidal_datum(datum2, name=n) 

877 if self.datum == d2: 

878 r = self.copy(name=name) 

879 else: 

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

881 epoch=self.epoch, reframe=self.reframe) 

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

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

884 return r 

885 

886 def toEtm(self, **toEtm8_kwds): 

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

888 

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

890 

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

892 

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

894 ''' 

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

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

897 

898 def toLcc(self, **toLcc_kwds): 

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

900 

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

902 

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

904 

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

906 ''' 

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

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

909 

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

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

912 

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

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

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

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

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

918 

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

920 

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

922 ''' 

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

924 

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

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

927 

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

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

930 formulation (C{bool}). 

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

932 

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

934 

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

936 ''' 

937 if toOsgr_kwds: 

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

939 else: 

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

941 return r 

942 

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

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

945 

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

947 @kwarg height: Optional height, overriding the converted 

948 height (C{meter}). 

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

950 

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

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

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

954 

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

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

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

958 

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

960 

961 @example: 

962 

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

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

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

966 ''' 

967 if not self.reframe: 

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

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

970 

971 trf = _MODS.trf 

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

973 

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

975 if xs: 

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

977 n = name or self.name 

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

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

980 else: 

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

982 return ll 

983 

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

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

986 

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

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

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

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

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

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

993 

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

995 

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

997 ''' 

998 if self._upsOK(pole, falsed): 

999 u = self._ups 

1000 else: 

1001 ups = _MODS.ups 

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

1003 pole=pole, falsed=falsed) 

1004 return _lowerleft(u, center) 

1005 

1006 def toUtm(self, center=False): 

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

1008 

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

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

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

1012 

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

1014 

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

1016 ''' 

1017 return _lowerleft(self._utm, center) 

1018 

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

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

1021 

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

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

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

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

1026 meter} (C{scalar}). 

1027 

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

1029 

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

1031 ''' 

1032 if self._utmOK(): 

1033 u = self._utm 

1034 elif self._upsOK(pole): 

1035 u = self._ups 

1036 else: # no cover 

1037 utmups = _MODS.utmups 

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

1039 Utm=utmups.Utm, Ups=utmups.Ups) 

1040 if isinstance(u, utmups.Utm): 

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

1042 elif isinstance(u, utmups.Ups): 

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

1044 else: 

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

1046 return _lowerleft(u, center) 

1047 

1048 @deprecated_method 

1049 def to3xyz(self): # PYCHOK no cover 

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

1051 

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

1053 

1054 @note: Overloads C{LatLonBase.to3xyz} 

1055 ''' 

1056 r = self.toEcef() 

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

1058 

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

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

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

1062 intersection} of three intersecting circles. 

1063 

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

1065 as B{C{eps}}). 

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

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

1068 B{C{eps}}). 

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

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

1071 B{C{eps}}). 

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

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

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

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

1076 (C{meter}, conventionally). 

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

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

1079 

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

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

1082 the corresponding trilaterated points C{minPoint} and 

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

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

1085 

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

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

1088 

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

1090 respectively largest I{radial} overlap found. 

1091 

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

1093 nearest respectively farthest intersection margin. 

1094 

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

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

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

1098 largest B{C{distance#}}. 

1099 

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

1101 insufficient overlap for C{B{area}=True} or 

1102 no intersection or all (near-)concentric for 

1103 C{B{area}=False}. 

1104 

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

1106 

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

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

1109 

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

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

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

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

1114 ''' 

1115 return _trilaterate5(self, distance1, 

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

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

1118 area=area, eps=eps, wrap=wrap) 

1119 

1120 @Property_RO 

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

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

1123 see L{pygeodesy.toUps8}. 

1124 ''' 

1125 ups = _MODS.ups 

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

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

1128 

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

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

1131 ''' 

1132 try: 

1133 u = self._ups 

1134 except RangeError: 

1135 return False 

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

1137 

1138 @Property_RO 

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

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

1141 see L{pygeodesy.toUtm8}. 

1142 ''' 

1143 utm = _MODS.utm 

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

1145 

1146 def _utmOK(self): 

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

1148 ''' 

1149 try: 

1150 _ = self._utm 

1151 except RangeError: 

1152 return False 

1153 return True 

1154 

1155 

1156def intersecant2(center, circle, point, bearing, radius=None, exact=False, 

1157 height=None, wrap=False): # was=True 

1158 '''Compute the intersections of a circle and a line given as a point and 

1159 bearing or as two points. 

1160 

1161 @arg center: Center of the circle (C{LatLon}). 

1162 @arg circle: Radius of the circle (C{meter}, same units as B{C{radius}}) 

1163 or a point on the circle (C{LatLon}). 

1164 @arg point: A point in- or outside the circle on the line (C{LatLon}). 

1165 @arg bearing: Bearing at the B{C{point}} (compass C{degrees360}) or 

1166 an other point on the line (C{LatLon}). 

1167 @kwarg radius: Optional earth radius (C{meter}) or earth model (L{Datum}, 

1168 L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}), overriding 

1169 the B{C{center}}'s and B{C{point}}'s datum. 

1170 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}), see 

1171 method L{Ellipsoid.rhumb_}. 

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

1173 conventionally) or C{None}. 

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

1175 and the B{C{circle}} and B{C{bearing}} points (C{bool}). 

1176 

1177 @return: 2-Tuple of the intersection points (representing a chord), 

1178 each an instance of this class. For a tangent line, both 

1179 points are the same instance, the B{C{point}} or wrapped 

1180 or I{normalized}. 

1181 

1182 @raise IntersectionError: The circle and line do not intersect. 

1183 

1184 @raise TypeError: If B{C{center}} or B{C{point}} not ellipsoidal C{LatLon} 

1185 or B{C{circle}} or B{C{bearing}} invalid. 

1186 

1187 @raise ValueError: Invalid B{C{circle}}, B{C{bearing}}, B{C{radius}}, 

1188 B{C{exact}} or B{C{height}}. 

1189 

1190 @see: Methods L{RhumbLineAux.Intersecant2} and L{RhumbLine.Intersecant2}. 

1191 ''' 

1192 try: 

1193 if not isinstance(center, LatLonEllipsoidalBase): 

1194 raise _IsnotError(_ellipsoidal_, center=center) 

1195 return center.intersecant2(circle, point, bearing, radius=radius, exact=exact, 

1196 height=height, wrap=wrap) 

1197 except (TypeError, ValueError) as x: 

1198 raise _xError(x, center=center, circle=circle, 

1199 point=point, bearing=bearing, exact=exact) 

1200 

1201 

1202def _lowerleft(utmups, center): 

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

1204 ''' 

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

1206 u = utmups 

1207 elif center in (True,): 

1208 u = utmups._lowerleft 

1209 else: 

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

1211 return u 

1212 

1213 

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

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

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

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

1218 ''' 

1219 try: 

1220 p = _xellipsoidal(point=point) 

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

1222 height=height, wrap=wrap, 

1223 equidistant=equidistant, 

1224 tol=tol, **LatLon_and_kwds) 

1225 except (TypeError, ValueError) as x: 

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

1227 return t.closest 

1228 

1229 

1230def _set_reframe(inst, reframe): 

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

1232 ''' 

1233 if reframe is not None: 

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

1235 inst._reframe = reframe 

1236 elif inst.reframe is not None: 

1237 inst._reframe = None 

1238 

1239 

1240__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase, intersecant2) 

1241 

1242# **) MIT License 

1243# 

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

1245# 

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

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

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

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

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

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

1252# 

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

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

1255# 

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

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

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

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

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

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

1262# OTHER DEALINGS IN THE SOFTWARE.