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

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

21 from pygeodesy.errors import _IsnotError, RangeError, _TypeError, _xattr, _xellipsoidal, \

22 _xellipsoids, _xError, _xkwds, _xkwds_not

23# from pygeodesy.fmath import favg # _MODS

24 from pygeodesy.interns import NN, _COMMA_, _ellipsoidal_

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

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

27# from pygeodesy.lcc import toLcc # _MODS

28# from pygeodesy.namedTuples import Vector3Tuple # _MODS

29 from pygeodesy.props import deprecated_method, deprecated_property_RO, \

30 Property_RO, property_doc_, property_RO, _update_all

31# from pygeodesy.trf import _eT0Ds4 # _MODS

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

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

34

35# from math import fabs # from .latlonBase

36

37__all__ = _ALL_LAZY.ellipsoidalBase

38__version__ = '24.08.14'

39

40

41 class CartesianEllipsoidalBase(CartesianBase):

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

43 '''

44 _datum = _WGS84 # L{Datum}

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

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

47

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

49 **datum_ll_name):

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

51

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

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

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

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

56

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

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

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

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

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

62

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

64 '''

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

66 if reframe:

67 self.reframe = reframe

68 self.epoch = epoch

69

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

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

72# '''

73# RefFrame = _MODS.trf.RefFrame

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

75# _NotImplemented(self, other)

76

77 @deprecated_method

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

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

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

81

82 @property_RO

83 def ellipsoidalCartesian(self):

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

85 '''

86 return type(self)

87

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

89 def epoch(self):

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

91 '''

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

93

94 @epoch.setter # PYCHOK setter!

95 def epoch(self, epoch):

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

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

98

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

100 '''

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

102

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

104 Vector=None, **Vector_kwds):

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

106 cartesian center point and a radius.

107

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

109 coordinates).

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

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

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

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

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

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

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

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

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

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

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

121

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

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

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

125

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

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

128 instance, aka the I{radical center}.

129

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

131

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

133

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

135

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

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

138 Intersection and function L{pygeodesy.radical2}.

139 '''

140 try:

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

142 center2, Radius_(radius2=radius2),

143 sphere=sphere, clas=self.classof,

144 Vector=Vector, **Vector_kwds)

145 except (TypeError, ValueError) as x:

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

147

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

149 def reframe(self):

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

151 '''

152 return self._reframe

153

154 @reframe.setter # PYCHOK setter!

155 def reframe(self, reframe):

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

157

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

159 '''

160 _set_reframe(self, reframe)

161

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

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

164

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

166 for further details.

167 '''

168 kwds = LatLon_and_kwds

169 if kwds:

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

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

172

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

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

175

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

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

178 overriding this point's reference frame.

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

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

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

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

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

184

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

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

187 is non-empty.

188

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

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

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

192

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

194 '''

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

196 epoch2=epoch2, **name)

197

198 @deprecated_method

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

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

201 r = self

202 for t in transforms:

203 r = r.toTransform(t)

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

205

206

207 class LatLonEllipsoidalBase(LatLonBase):

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

209 '''

210 _datum = _WGS84 # L{Datum}

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

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

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

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

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

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

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

218

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

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

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

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

223

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

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

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

227 indicating B{C{latlonh}} is a C{LatLon}.

228 @kwarg height: Optional height above (or below) the earth surface (C{meter},

229 same units as the datum's ellipsoid axes).

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

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

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

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

234 non-zero, fractional calendar year, but silently ignored if

235 C{B{reframe}=None}.

236 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{lat}} and B{C{lon}} (C{bool}).

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

238

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

240 L{rangerrors} set to C{True}.

241

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

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

244 is not C{scalar} non-zero.

245

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

247 '''

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

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

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

251 if reframe:

252 self.reframe = reframe

253 self.epoch = epoch

254

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

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

257# '''

258# RefFrame = _MODS.trf.RefFrame

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

260# _NotImplemented(self, other)

261

262 def antipode(self, height=None):

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

264 to this point.

265

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

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

268

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

270 '''

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

272 if lla.datum != self.datum:

273 lla.datum = self.datum

274 return lla

275

276 @deprecated_property_RO

277 def convergence(self):

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

279 return self.gamma

280

281 @deprecated_method

282 def convertDatum(self, datum2):

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

284 return self.toDatum(datum2)

285

286 @deprecated_method

287 def convertRefFrame(self, reframe2):

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

289 return self.toRefFrame(reframe2)

290

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

292 def datum(self):

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

294 '''

295 return self._datum

296

297 @datum.setter # PYCHOK setter!

298 def datum(self, datum):

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

300

301 @raise TypeError: The B{C{datum}} is not a L{Datum} or not ellipsoidal.

302 '''

303 _xinstanceof(Datum, datum=datum)

304 if not datum.isEllipsoidal:

305 raise _IsnotError(_ellipsoidal_, datum=datum)

306 if self._datum != datum:

307 _update_all(self)

308 self._datum = datum

309

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

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

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

313

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

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

316

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

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

319 point (C{bool}).

320

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

322

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

324

325 @raise ValueError: Incompatible datum ellipsoids.

326

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

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

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

330 formula.

331 '''

332 p = self.others(other)

333 if wrap:

334 p = _Wrap.point(p)

335 E = self.ellipsoids(other)

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

337

338 @Property_RO

339 def _elevation2(self):

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

341 '''

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

343 timeout=self._elevation2to)

344

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

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

347 or sphere.

348

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

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

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

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

353 radius).

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

355

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

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

358

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

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

361 L{elevations.elevation2} is based.

362

363 @note: NED elevation is only available for locations within the U{Conterminous

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

365

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

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

368 '''

369 if self._elevation2to != timeout:

370 self._elevation2to = timeout

371 LatLonEllipsoidalBase._elevation2._update(self)

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

373

374 def ellipsoid(self, datum=_WGS84):

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

376

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

378

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

380 '''

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

382

383 @property_RO

384 def ellipsoidalLatLon(self):

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

386 '''

387 return type(self)

388

389 def ellipsoids(self, other):

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

391

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

393

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

395

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

397

398 @raise ValueError: Incompatible datum ellipsoids.

399 '''

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

401

402 E = self.ellipsoid()

403 try: # other may be Sphere, etc.

404 e = other.ellipsoid()

405 except AttributeError:

406 try: # no ellipsoid method, try datum

407 e = other.datum.ellipsoid

408 except AttributeError:

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

410 return _xellipsoids(E, e)

411

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

413 def epoch(self):

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

415 '''

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

417

418 @epoch.setter # PYCHOK setter!

419 def epoch(self, epoch):

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

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

422

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

424 '''

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

426

427 @Property_RO

428 def Equidistant(self):

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

430 '''

431 try:

432 _ = self.datum.ellipsoid.geodesic

433 return _MODS.azimuthal.EquidistantKarney

434 except ImportError: # no geographiclib

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

436

437 @Property_RO

438 def _etm(self):

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

440 '''

441 etm = _MODS.etm

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

443

444 @property_RO

445 def gamma(self):

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

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

448 '''

449 return self._gamma

450

451 @Property_RO

452 def _geoidHeight2(self):

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

454 '''

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

456 timeout=self._geoidHeight2to)

457

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

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

460 or sphere.

461

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

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

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

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

466 radius).

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

468

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

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

471

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

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

474 the L{elevations.geoidHeight2} is based.

475

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

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

478

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

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

481 '''

482 if self._geoidHeight2to != timeout:

483 self._geoidHeight2to = timeout

484 LatLonEllipsoidalBase._geoidHeight2._update(self)

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

486

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

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

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

490

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

492 equidistant=None, tol=_TOL_M):

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

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

495

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

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

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

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

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

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

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

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

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

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

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

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

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

509 length (C{meter}, conventionally).

510

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

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

513

514 @raise ImportError: Package U{geographiclib

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

516 not installed or not found, but only if

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

518

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

520 non-intersecting lines or no convergence

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

522

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

524 is not C{LatLon}.

525

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

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

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

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

530 of the C{authalic} earth perimeter).

531

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

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

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

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

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

537 '''

538 try:

539 s2 = self.others(other)

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

541 s2, end2,

542 height=height, wrap=wrap,

543 equidistant=equidistant, tol=tol,

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

545 except (TypeError, ValueError) as x:

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

547 height=height, wrap=wrap, tol=tol)

548

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

550 equidistant=None, tol=_TOL_M):

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

552 each defined by a center point and a radius.

553

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

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

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

557 B{C{radius1}}).

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

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

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

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

562 center (C{bool}).

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

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

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

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

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

568

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

570 instance. For abutting circles, both intersection

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

572

573 @raise ImportError: Package U{geographiclib

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

575 not installed or not found, but only if

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

577

578 @raise IntersectionError: Concentric, antipodal, invalid or

579 non-intersecting circles or no

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

581

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

583

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

585

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

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

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

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

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

591 intersections.

592 '''

593 try:

594 c2 = self.others(other)

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

596 c2, radius2,

597 height=height, wrap=wrap,

598 equidistant=equidistant, tol=tol,

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

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

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

602 height=height, wrap=wrap, tol=tol)

603

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

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

606

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

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

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

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

611

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

613 C{False} otherwise.

614

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

616

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

618

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

620

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

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

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

624 '''

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

626

627 @property_RO

628 def iteration(self):

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

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

631 '''

632 return self._iteration

633

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

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

636

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

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

639 mean height (C{meter}).

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

641 may be negative or greater than 1.0.

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

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

644

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

646

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

648

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

650

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

652 '''

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

654

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

656 equidistant=None, tol=_TOL_M):

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

658 two other (ellipsoidal) points.

659

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

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

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

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

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

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

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

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

668 takes the heights of the points into account.

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

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

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

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

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

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

675

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

677

678 @raise ImportError: Package U{geographiclib

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

680 not installed or not found, but only if

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

682

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

684 B{C{equidistant}}.

685

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

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

688

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

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

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

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

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

694 '''

695 try:

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

697 height=height, wrap=wrap,

698 equidistant=equidistant,

699 tol=tol, LatLon=self.classof)

700 except (TypeError, ValueError) as x:

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

702 height=height, wrap=wrap, tol=tol)

703 return t.closest

704

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

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

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

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

709

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

711 L{pygeodesy.parse3llh}.

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

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

714 I{without conversion}.

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

716 I{without conversion}.

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

718 this reframe I{without conversion}.

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

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

721 longitude (C{bool}).

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

723

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

725

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

727 '''

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

729 r = self.classof(a, b, height=h, datum=self.datum, epoch=self.epoch,

730 reframe=self.reframe)

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

732 r.datum = datum

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

734 r.epoch = epoch

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

736 r.reframe = reframe

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

738

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

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

741 difference in Gaussian radii of curvature of the given

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

743

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

745 '''

746 if adjust: # Elevation2Tuple or GeoidHeight2Tuple

747 m, t = meter_text2

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

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

750 if n > EPS0:

751 # use ratio, datum and NAD83 units may differ

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

753 _earth_ellipsoid(datum)

754 r = E.rocGauss(self.lat)

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

756 m *= r / n

757 meter_text2 = meter_text2.classof(m, t)

758 return self._xnamed(meter_text2)

759

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

761 def reframe(self):

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

763 '''

764 return self._reframe

765

766 @reframe.setter # PYCHOK setter!

767 def reframe(self, reframe):

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

769

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

771 '''

772 _set_reframe(self, reframe)

773

774 @Property_RO

775 def scale(self):

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

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

778 '''

779 return self._scale

780

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

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

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

784

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

786 for further details.

787 '''

788 kwds = Cartesian_and_kwds

789 if kwds:

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

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

792

793 def toCss(self, **toCss_kwds):

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

795

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

797

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

799

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

801 '''

802 return _MODS.css.toCss(self, **self._name1__(toCss_kwds))

803

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

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

806

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

808 @kwarg height: Optional height, overriding the

809 converted height (C{meter}).

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

811

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

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

814 matches this point's C{datum}.

815

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

817 '''

818 n = self._name__(name)

819 d2 = _ellipsoidal_datum(datum2, name=n)

820 if self.datum == d2:

821 r = self.copy(name=n)

822 else:

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

824 epoch=self.epoch, reframe=self.reframe)

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

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

827 return r

828

829 def toEtm(self, **toEtm8_kwds):

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

831

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

833

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

835

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

837 '''

838 return _MODS.etm.toEtm8(self, **self._name1__(toEtm8_kwds)) if toEtm8_kwds else self._etm

839

840 def toLcc(self, **toLcc_kwds):

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

842

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

844

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

846

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

848 '''

849 return _MODS.lcc.toLcc(self, **self._name1__(toLcc_kwds))

850

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

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

853

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

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

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

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

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

859

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

861

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

863 '''

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

865

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

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

868

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

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

871 formulation (C{bool}).

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

873

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

875

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

877 '''

878 return _MODS.osgr.toOsgr(self, kTM=kTM, **self._name1__(toOsgr_kwds))

879

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

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

882

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

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

885 overriding this point's reference frame.

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

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

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

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

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

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

892

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

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

895 is non-empty.

896

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

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

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

900

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

902 '''

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

904 epoch2=epoch2, height=height, **name)

905

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

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

908

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

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

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

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

913 @kwarg LatLon_kwds: Optional keyword arguments for the transformed

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

915

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

917 C{B{transform}.isunity}.

918

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

920 '''

921 _xinstanceof(Transform, transform=transform)

922 d = datum or self.datum

923 if transform.isunity:

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

925 else:

926 c = self.toCartesian()

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

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

929 return r

930

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

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

933

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

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

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

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

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

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

940

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

942

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

944 '''

945 if self._upsOK(pole, falsed):

946 u = self._ups

947 else:

948 ups = _MODS.ups

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

950 pole=pole, falsed=falsed)

951 return _lowerleft(u, center)

952

953 def toUtm(self, center=False):

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

955

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

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

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

959

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

961

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

963 '''

964 return _lowerleft(self._utm, center)

965

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

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

968

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

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

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

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

973 meter} (C{scalar}).

974

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

976

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

978 '''

979 if self._utmOK():

980 u = self._utm

981 elif self._upsOK(pole):

982 u = self._ups

983 else: # no cover

984 utmups = _MODS.utmups

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

986 Utm=utmups.Utm, Ups=utmups.Ups)

987 if isinstance(u, utmups.Utm):

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

989 elif isinstance(u, utmups.Ups):

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

991 else:

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

993 return _lowerleft(u, center)

994

995 @deprecated_method

996 def to3xyz(self): # PYCHOK no cover

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

998

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

1000

1001 @note: Overloads C{LatLonBase.to3xyz}

1002 '''

1003 r = self.toEcef()

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

1005

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

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

1008 bearing at this and at the other point.

1009

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

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

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

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

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

1015 <pygeodesy.ellipsoidalBase.LatLonEllipsoidalBase>}.

1016

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

1018

1019 @see: Method L{intersection3<pygeodesy.ellipsoidalBase.LatLonEllipsoidalBase>}

1020 for further details.

1021 '''

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

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

1024 return r.point

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

1026

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

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

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

1030 intersection} of three intersecting circles.

1031

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

1033 as B{C{eps}}).

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

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

1036 B{C{eps}}).

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

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

1039 B{C{eps}}).

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

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

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

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

1044 (C{meter}, conventionally).

1045 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{point2}}

1046 and B{C{point3}} (C{bool}).

1047

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

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

1050 the corresponding trilaterated points C{minPoint} and

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

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

1053

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

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

1056

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

1058 respectively largest I{radial} overlap found.

1059

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

1061 nearest respectively farthest intersection margin.

1062

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

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

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

1066 largest B{C{distance#}}.

1067

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

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

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

1071 all circles are (near-)concentric.

1072

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

1074

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

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

1077

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

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

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

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

1082 '''

1083 return _trilaterate5(self, distance1,

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

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

1086 area=area, eps=eps, wrap=wrap)

1087

1088 @Property_RO

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

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

1091 see L{pygeodesy.toUps8}.

1092 '''

1093 ups = _MODS.ups

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

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

1096

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

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

1099 '''

1100 try:

1101 u = self._ups

1102 except RangeError:

1103 return False

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

1105

1106 @Property_RO

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

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

1109 see L{pygeodesy.toUtm8}.

1110 '''

1111 utm = _MODS.utm

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

1113

1114 def _utmOK(self):

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

1116 '''

1117 try:

1118 _ = self._utm

1119 except RangeError:

1120 return False

1121 return True

1122

1123

1124 def _lowerleft(utmups, center):

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

1126 '''

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

1128 u = utmups

1129 elif center in (True,):

1130 u = utmups._lowerleft

1131 else:

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

1133 return u

1134

1135

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

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

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

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

1140 '''

1141 try:

1142 p = _xellipsoidal(point=point)

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

1144 height=height, wrap=wrap,

1145 equidistant=equidistant,

1146 tol=tol, **LatLon_and_kwds)

1147 except (TypeError, ValueError) as x:

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

1149 return t.closest

1150

1151

1152 def _set_reframe(inst, reframe):

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

1154 '''

1155 if reframe is not None:

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

1157 inst._reframe = reframe

1158 elif inst.reframe is not None:

1159 inst._reframe = None

1160

1161

1162__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)

1163

1164# **) MIT License

1165#

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

1167#

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

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

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

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

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

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

1174#

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

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

1177#

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

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

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

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

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

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

1184# OTHER DEALINGS IN THE SOFTWARE.