1

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

3

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

5 and C{LatLonEllipsoidalBase}.

6

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

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

9 and 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

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

14

15# from pygeodesy.basics import _xinstanceof # from .datums

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

17 from pygeodesy.cartesianBase import CartesianBase # PYCHOK used!

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

19 _WGS84, _EWGS84, _xinstanceof # _spherical_datum

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

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

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

23 _xkwds_get, _xkwds_not

24# from pygeodesy.fmath import favg # _MODS

25 from pygeodesy.interns import NN, _COMMA_, _ellipsoidal_

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

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

28# from pygeodesy.lcc import toLcc # _MODS

29# from pygeodesy.named import notOverloaded # _MODS

30# from pygeodesy.namedTuples import Vector3Tuple # _MODS

31 from pygeodesy.props import deprecated_method, deprecated_property_RO, \

32 Property_RO, property_doc_, property_RO, _update_all

33# from pygeodesy.trf import _eT0Ds4 # _MODS

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

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

36

37# from math import fabs # from .latlonBase

38

39__all__ = _ALL_LAZY.ellipsoidalBase

40__version__ = '24.02.04'

41

42

43 class CartesianEllipsoidalBase(CartesianBase):

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

45 '''

46 _datum = _WGS84 # L{Datum}

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

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

49

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

51 epoch=None, ll=None, name=NN):

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

53

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

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

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

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

58

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

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

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

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

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

64

65 @see: Super-class L{CartesianBase<CartesianBase.__init__>} for more details.

66 '''

67 CartesianBase.__init__(self, x_xyz, y=y, z=z, datum=datum, ll=ll, name=name)

68 if reframe:

69 self.reframe = reframe

70 self.epoch = epoch

71

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

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

74# '''

75# RefFrame = _MODS.trf.RefFrame

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

77# _NotImplemented(self, other)

78

79 @deprecated_method

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

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

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

83

84 @property_RO

85 def ellipsoidalCartesian(self):

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

87 '''

88 return type(self)

89

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

91 def epoch(self):

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

93 '''

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

95

96 @epoch.setter # PYCHOK setter!

97 def epoch(self, epoch):

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

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

100

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

102 '''

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

104

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

106 Vector=None, **Vector_kwds):

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

108 cartesian center point and a radius.

109

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

111 coordinates).

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

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

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

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

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

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

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

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

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

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

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

123

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

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

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

127

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

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

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

131

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

133

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

135

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

137

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

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

140 Intersection and function L{pygeodesy.radical2}.

141 '''

142 try:

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

144 center2, Radius_(radius2=radius2),

145 sphere=sphere, clas=self.classof,

146 Vector=Vector, **Vector_kwds)

147 except (TypeError, ValueError) as x:

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

149

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

151 def reframe(self):

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

153 '''

154 return self._reframe

155

156 @reframe.setter # PYCHOK setter!

157 def reframe(self, reframe):

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

159

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

161 '''

162 _set_reframe(self, reframe)

163

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

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

166

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

168 for further details.

169 '''

170 kwds = LatLon_and_kwds

171 if kwds:

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

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

174

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

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

177

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

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

180 point's reference frame.

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

182 this point's epoch.

183 @kwarg epoch2: Optional epoch to observe I{to} (L{Epoch}, C{scalar} or

184 C{str}).

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

186

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

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

189 is non-empty.

190

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

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

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

194

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

196 '''

197 e, t0, d, d2 = _MODS.trf._eT0Ds4(self, reframe, epoch, reframe2, epoch2)

198 if t0:

199 r = self.toDatum(d).toTransforms_(t0).toDatum(d2).toDatum(self.datum)

200 r.reframe, r.epoch = reframe2, e

201 if name:

202 r.rename(name)

203 else:

204 r = self.copy(name=name) if name else self

205 return r

206

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

208 '''Apply none, one or several Helmert transforms to this point.

209

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

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

212 this point's datum.

213

214 @return: The transformed point (C{Cartesian}) or this point if the

215 B{C{transforms}} produce the same point.

216 '''

217 r = self

218 if transforms:

219 xyz = r.xyz

220 for t in transforms:

221 xyz = t.transform(*xyz)

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

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

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

225 return r

226

227

228 class LatLonEllipsoidalBase(LatLonBase):

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

230 '''

231 _datum = _WGS84 # L{Datum}

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

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

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

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

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

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

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

239

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

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

242 '''Create an ellipsoidal C{LatLon} point from the givenlat-, longitude

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

244

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

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

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

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

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

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

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

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

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

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

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

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

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

258 (C{bool}).

259 @kwarg name: Optional name (C{str}).

260

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

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

263

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

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

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

267

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

269 '''

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

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

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

273 if reframe:

274 self.reframe = reframe

275 self.epoch = epoch

276

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

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

279# '''

280# RefFrame = _MODS.trf.RefFrame

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

282# _NotImplemented(self, other)

283

284 def antipode(self, height=None):

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

286 to this point.

287

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

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

290

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

292 '''

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

294 if lla.datum != self.datum:

295 lla.datum = self.datum

296 return lla

297

298 @deprecated_property_RO

299 def convergence(self):

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

301 return self.gamma

302

303 @deprecated_method

304 def convertDatum(self, datum2):

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

306 return self.toDatum(datum2)

307

308 @deprecated_method

309 def convertRefFrame(self, reframe2):

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

311 return self.toRefFrame(reframe2)

312

313 @Property_RO

314 def _css(self):

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

316 '''

317 css = _MODS.css

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

319

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

321 def datum(self):

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

323 '''

324 return self._datum

325

326 @datum.setter # PYCHOK setter!

327 def datum(self, datum):

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

329

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

331 or not ellipsoidal.

332 '''

333 _xinstanceof(Datum, datum=datum)

334 if not datum.isEllipsoidal:

335 raise _IsnotError(_ellipsoidal_, datum=datum)

336 if self._datum != datum:

337 _update_all(self)

338 self._datum = datum

339

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

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

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

343

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

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

346

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

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

349 point (C{bool}).

350

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

352

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

354

355 @raise ValueError: Incompatible datum ellipsoids.

356

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

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

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

360 formula.

361 '''

362 p = self.others(other)

363 if wrap:

364 p = _Wrap.point(p)

365 E = self.ellipsoids(other)

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

367

368 @Property_RO

369 def _elevation2(self):

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

371 '''

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

373 timeout=self._elevation2to)

374

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

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

377 or sphere.

378

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

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

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

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

383 radius).

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

385

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

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

388

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

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

391 L{elevations.elevation2} is based.

392

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

394 U{Conterminous US (CONUS)

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

396

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

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

399 '''

400 if self._elevation2to != timeout:

401 self._elevation2to = timeout

402 LatLonEllipsoidalBase._elevation2._update(self)

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

404

405 def ellipsoid(self, datum=_WGS84):

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

407

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

409

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

411 '''

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

413

414 @property_RO

415 def ellipsoidalLatLon(self):

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

417 '''

418 return type(self)

419

420 def ellipsoids(self, other):

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

422

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

424

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

426

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

428

429 @raise ValueError: Incompatible datum ellipsoids.

430 '''

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

432

433 E = self.ellipsoid()

434 try: # other may be Sphere, etc.

435 e = other.ellipsoid()

436 except AttributeError:

437 try: # no ellipsoid method, try datum

438 e = other.datum.ellipsoid

439 except AttributeError:

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

441 if e != E:

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

443 return E

444

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

446 def epoch(self):

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

448 '''

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

450

451 @epoch.setter # PYCHOK setter!

452 def epoch(self, epoch):

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

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

455

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

457 '''

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

459

460 @Property_RO

461 def Equidistant(self):

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

463 '''

464 try:

465 _ = self.datum.ellipsoid.geodesic

466 return _MODS.azimuthal.EquidistantKarney

467 except ImportError: # no geographiclib

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

469

470 @Property_RO

471 def _etm(self):

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

473 '''

474 etm = _MODS.etm

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

476

477 @property_RO

478 def gamma(self):

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

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

481 '''

482 return self._gamma

483

484 @Property_RO

485 def _geoidHeight2(self):

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

487 '''

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

489 timeout=self._geoidHeight2to)

490

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

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

493 or sphere.

494

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

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

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

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

499 radius).

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

501

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

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

504

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

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

507 the L{elevations.geoidHeight2} is based.

508

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

510 U{Conterminous US (CONUS)

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

512

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

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

515 '''

516 if self._geoidHeight2to != timeout:

517 self._geoidHeight2to = timeout

518 LatLonEllipsoidalBase._geoidHeight2._update(self)

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

520

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

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

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

524

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

526 equidistant=None, tol=_TOL_M):

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

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

529

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

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

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

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

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

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

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

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

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

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

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

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

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

543 length (C{meter}, conventionally).

544

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

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

547

548 @raise ImportError: Package U{geographiclib

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

550 not installed or not found, but only if

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

552

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

554 non-intersecting lines or no convergence

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

556

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

558 is not C{LatLon}.

559

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

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

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

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

564 of the authalic earth perimeter).

565

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

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

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

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

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

571 '''

572 try:

573 s2 = self.others(other)

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

575 s2, end2,

576 height=height, wrap=wrap,

577 equidistant=equidistant, tol=tol,

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

579 except (TypeError, ValueError) as x:

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

581 height=height, wrap=wrap, tol=tol)

582

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

584 equidistant=None, tol=_TOL_M):

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

586 each defined by a center point and a radius.

587

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

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

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

591 B{C{radius1}}).

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

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

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

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

596 center (C{bool}).

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

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

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

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

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

602

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

604 instance. For abutting circles, both intersection

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

606

607 @raise ImportError: Package U{geographiclib

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

609 not installed or not found, but only if

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

611

612 @raise IntersectionError: Concentric, antipodal, invalid or

613 non-intersecting circles or no

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

615

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

617

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

619

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

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

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

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

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

625 intersections.

626 '''

627 try:

628 c2 = self.others(other)

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

630 c2, radius2,

631 height=height, wrap=wrap,

632 equidistant=equidistant, tol=tol,

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

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

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

636 height=height, wrap=wrap, tol=tol)

637

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

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

640

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

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

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

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

645

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

647 C{False} otherwise.

648

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

650

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

652

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

654

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

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

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

658 '''

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

660

661 @property_RO

662 def iteration(self):

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

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

665 '''

666 return self._iteration

667

668 @Property_RO

669 def _lcc(self):

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

671 '''

672 lcc = _MODS.lcc

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

674

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

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

677

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

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

680 mean height (C{meter}).

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

682 may be negative or greater than 1.0.

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

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

685

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

687

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

689

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

691

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

693 '''

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

695

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

697 equidistant=None, tol=_TOL_M):

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

699 two other (ellipsoidal) points.

700

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

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

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

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

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

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

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

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

709 takes the heights of the points into account.

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

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

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

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

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

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

716

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

718

719 @raise ImportError: Package U{geographiclib

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

721 not installed or not found, but only if

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

723

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

725 B{C{equidistant}}.

726

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

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

729

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

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

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

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

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

735 '''

736 try:

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

738 height=height, wrap=wrap,

739 equidistant=equidistant,

740 tol=tol, LatLon=self.classof)

741 except (TypeError, ValueError) as x:

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

743 height=height, wrap=wrap, tol=tol)

744 return t.closest

745

746 @Property_RO

747 def _osgr(self):

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

749 based on the OS recommendation.

750 '''

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

752

753 @Property_RO

754 def _osgrTM(self):

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

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

757 '''

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

759

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

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

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

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

764

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

766 see function L{pygeodesy.parse3llh}.

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

768 C{None}).

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

770 datum I{without conversion}.

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

772 epoch I{without conversion}.

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

774 this reframe I{without conversion}.

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

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

777 and longitude (C{bool}).

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

779 this name.

780

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

782

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

784 '''

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

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

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

788 r.datum = datum

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

790 r.epoch = epoch

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

792 r.reframe = reframe

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

794

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

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

797 difference in Gaussian radii of curvature of the given

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

799

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

801 '''

802 if adjust: # Elevation2Tuple or GeoidHeight2Tuple

803 m, t = meter_text2

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

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

806 if n > EPS0:

807 # use ratio, datum and NAD83 units may differ

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

809 _earth_ellipsoid(datum)

810 r = E.rocGauss(self.lat)

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

812 m *= r / n

813 meter_text2 = meter_text2.classof(m, t)

814 return self._xnamed(meter_text2)

815

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

817 def reframe(self):

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

819 '''

820 return self._reframe

821

822 @reframe.setter # PYCHOK setter!

823 def reframe(self, reframe):

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

825

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

827 '''

828 _set_reframe(self, reframe)

829

830 @Property_RO

831 def scale(self):

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

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

834 '''

835 return self._scale

836

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

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

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

840

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

842 for further details.

843 '''

844 kwds = Cartesian_and_kwds

845 if kwds:

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

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

848

849 def toCss(self, **toCss_kwds):

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

851

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

853

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

855

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

857 '''

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

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

860

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

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

863

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

865 @kwarg height: Optional height, overriding the

866 converted height (C{meter}).

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

868

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

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

871 matches this point's C{datum}.

872

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

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, reframe=None, epoch=None, epoch2=None, height=None, name=NN):

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

945

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

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

948 point's reference frame.

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

950 this point's epoch.

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

952 C{scalar} or C{str}).

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

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

955

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

957 C{nil}, this point or a copy of this point if the B{C{name}} is

958 non-empty.

959

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

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

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

963

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

965 '''

966 e, t0, d, d2 = _MODS.trf._eT0Ds4(self, reframe, epoch, reframe2, epoch2)

967 if t0:

968 c = self.toCartesian().toDatum(d).toTransforms_(t0).toDatum(d2)

969 n = name or self.name

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

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

972 else:

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

974 return ll

975

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

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

978

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

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

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

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

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

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

985

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

987

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

989 '''

990 if self._upsOK(pole, falsed):

991 u = self._ups

992 else:

993 ups = _MODS.ups

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

995 pole=pole, falsed=falsed)

996 return _lowerleft(u, center)

997

998 def toUtm(self, center=False):

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

1000

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

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

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

1004

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

1006

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

1008 '''

1009 return _lowerleft(self._utm, center)

1010

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

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

1013

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

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

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

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

1018 meter} (C{scalar}).

1019

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

1021

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

1023 '''

1024 if self._utmOK():

1025 u = self._utm

1026 elif self._upsOK(pole):

1027 u = self._ups

1028 else: # no cover

1029 utmups = _MODS.utmups

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

1031 Utm=utmups.Utm, Ups=utmups.Ups)

1032 if isinstance(u, utmups.Utm):

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

1034 elif isinstance(u, utmups.Ups):

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

1036 else:

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

1038 return _lowerleft(u, center)

1039

1040 @deprecated_method

1041 def to3xyz(self): # PYCHOK no cover

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

1043

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

1045

1046 @note: Overloads C{LatLonBase.to3xyz}

1047 '''

1048 r = self.toEcef()

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

1050

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

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

1053 bearing at this and at the other point.

1054

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

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

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

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

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

1060

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

1062

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

1064 '''

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

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

1067 return r.point

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

1069

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

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

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

1073 intersection} of three intersecting circles.

1074

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

1076 as B{C{eps}}).

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

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

1079 B{C{eps}}).

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

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

1082 B{C{eps}}).

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

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

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

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

1087 (C{meter}, conventionally).

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

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

1090

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

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

1093 the corresponding trilaterated points C{minPoint} and

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

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

1096

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

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

1099

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

1101 respectively largest I{radial} overlap found.

1102

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

1104 nearest respectively farthest intersection margin.

1105

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

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

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

1109 largest B{C{distance#}}.

1110

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

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

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

1114 all circles are (near-)concentric.

1115

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

1117

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

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

1120

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

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

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

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

1125 '''

1126 return _trilaterate5(self, distance1,

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

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

1129 area=area, eps=eps, wrap=wrap)

1130

1131 @Property_RO

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

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

1134 see L{pygeodesy.toUps8}.

1135 '''

1136 ups = _MODS.ups

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

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

1139

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

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

1142 '''

1143 try:

1144 u = self._ups

1145 except RangeError:

1146 return False

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

1148

1149 @Property_RO

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

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

1152 see L{pygeodesy.toUtm8}.

1153 '''

1154 utm = _MODS.utm

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

1156

1157 def _utmOK(self):

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

1159 '''

1160 try:

1161 _ = self._utm

1162 except RangeError:

1163 return False

1164 return True

1165

1166

1167 def _lowerleft(utmups, center):

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

1169 '''

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

1171 u = utmups

1172 elif center in (True,):

1173 u = utmups._lowerleft

1174 else:

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

1176 return u

1177

1178

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

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

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

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

1183 '''

1184 try:

1185 p = _xellipsoidal(point=point)

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

1187 height=height, wrap=wrap,

1188 equidistant=equidistant,

1189 tol=tol, **LatLon_and_kwds)

1190 except (TypeError, ValueError) as x:

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

1192 return t.closest

1193

1194

1195 def _set_reframe(inst, reframe):

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

1197 '''

1198 if reframe is not None:

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

1200 inst._reframe = reframe

1201 elif inst.reframe is not None:

1202 inst._reframe = None

1203

1204

1205__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)

1206

1207# **) MIT License

1208#

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

1210#

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

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

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

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

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

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

1217#

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

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

1220#

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

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

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

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

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

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

1227# OTHER DEALINGS IN THE SOFTWARE.