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

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 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 datum (L{RefFrame}), overriding this

718 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)

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

731 r.datum = datum

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

733 r.epoch = epoch

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

735 r.reframe = reframe

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

737

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

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

740 difference in Gaussian radii of curvature of the given

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

742

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

744 '''

745 if adjust: # Elevation2Tuple or GeoidHeight2Tuple

746 m, t = meter_text2

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

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

749 if n > EPS0:

750 # use ratio, datum and NAD83 units may differ

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

752 _earth_ellipsoid(datum)

753 r = E.rocGauss(self.lat)

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

755 m *= r / n

756 meter_text2 = meter_text2.classof(m, t)

757 return self._xnamed(meter_text2)

758

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

760 def reframe(self):

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

762 '''

763 return self._reframe

764

765 @reframe.setter # PYCHOK setter!

766 def reframe(self, reframe):

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

768

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

770 '''

771 _set_reframe(self, reframe)

772

773 @Property_RO

774 def scale(self):

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

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

777 '''

778 return self._scale

779

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

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

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

783

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

785 for further details.

786 '''

787 kwds = Cartesian_and_kwds

788 if kwds:

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

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

791

792 def toCss(self, **toCss_kwds):

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

794

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

796

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

798

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

800 '''

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

802

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

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

805

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

807 @kwarg height: Optional height, overriding the

808 converted height (C{meter}).

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

810

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

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

813 matches this point's C{datum}.

814

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

816 '''

817 n = self._name__(name)

818 d2 = _ellipsoidal_datum(datum2, name=n)

819 if self.datum == d2:

820 r = self.copy(name=n)

821 else:

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

823 epoch=self.epoch, reframe=self.reframe)

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

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

826 return r

827

828 def toEtm(self, **toEtm8_kwds):

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

830

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

832

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

834

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

836 '''

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

838

839 def toLcc(self, **toLcc_kwds):

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

841

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

843

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

845

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

847 '''

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

849

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

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

852

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

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

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

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

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

858

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

860

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

862 '''

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

864

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

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

867

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

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

870 formulation (C{bool}).

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

872

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

874

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

876 '''

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

878

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

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

881

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

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

884 overriding this point's reference frame.

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

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

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

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

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

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

891

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

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

894 is non-empty.

895

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

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

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

899

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

901 '''

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

903 epoch2=epoch2, height=height, **name)

904

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

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

907

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

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

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

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

912 @kwarg LatLon_kwds: Optional keyword arguments for the transformed

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

914

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

916 C{B{transform}.isunity}.

917

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

919 '''

920 _xinstanceof(Transform, transform=transform)

921 d = datum or self.datum

922 if transform.isunity:

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

924 else:

925 c = self.toCartesian()

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

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

928 return r

929

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

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

932

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

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

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

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

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

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

939

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

941

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

943 '''

944 if self._upsOK(pole, falsed):

945 u = self._ups

946 else:

947 ups = _MODS.ups

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

949 pole=pole, falsed=falsed)

950 return _lowerleft(u, center)

951

952 def toUtm(self, center=False):

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

954

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

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

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

958

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

960

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

962 '''

963 return _lowerleft(self._utm, center)

964

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

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

967

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

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

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

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

972 meter} (C{scalar}).

973

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

975

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

977 '''

978 if self._utmOK():

979 u = self._utm

980 elif self._upsOK(pole):

981 u = self._ups

982 else: # no cover

983 utmups = _MODS.utmups

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

985 Utm=utmups.Utm, Ups=utmups.Ups)

986 if isinstance(u, utmups.Utm):

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

988 elif isinstance(u, utmups.Ups):

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

990 else:

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

992 return _lowerleft(u, center)

993

994 @deprecated_method

995 def to3xyz(self): # PYCHOK no cover

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

997

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

999

1000 @note: Overloads C{LatLonBase.to3xyz}

1001 '''

1002 r = self.toEcef()

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

1004

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

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

1007 bearing at this and at the other point.

1008

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

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

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

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

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

1014

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

1016

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

1018 '''

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

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

1021 return r.point

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

1023

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

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

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

1027 intersection} of three intersecting circles.

1028

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

1030 as B{C{eps}}).

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

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

1033 B{C{eps}}).

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

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

1036 B{C{eps}}).

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

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

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

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

1041 (C{meter}, conventionally).

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

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

1044

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

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

1047 the corresponding trilaterated points C{minPoint} and

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

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

1050

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

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

1053

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

1055 respectively largest I{radial} overlap found.

1056

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

1058 nearest respectively farthest intersection margin.

1059

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

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

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

1063 largest B{C{distance#}}.

1064

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

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

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

1068 all circles are (near-)concentric.

1069

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

1071

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

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

1074

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

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

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

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

1079 '''

1080 return _trilaterate5(self, distance1,

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

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

1083 area=area, eps=eps, wrap=wrap)

1084

1085 @Property_RO

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

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

1088 see L{pygeodesy.toUps8}.

1089 '''

1090 ups = _MODS.ups

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

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

1093

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

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

1096 '''

1097 try:

1098 u = self._ups

1099 except RangeError:

1100 return False

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

1102

1103 @Property_RO

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

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

1106 see L{pygeodesy.toUtm8}.

1107 '''

1108 utm = _MODS.utm

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

1110

1111 def _utmOK(self):

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

1113 '''

1114 try:

1115 _ = self._utm

1116 except RangeError:

1117 return False

1118 return True

1119

1120

1121 def _lowerleft(utmups, center):

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

1123 '''

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

1125 u = utmups

1126 elif center in (True,):

1127 u = utmups._lowerleft

1128 else:

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

1130 return u

1131

1132

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

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

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

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

1137 '''

1138 try:

1139 p = _xellipsoidal(point=point)

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

1141 height=height, wrap=wrap,

1142 equidistant=equidistant,

1143 tol=tol, **LatLon_and_kwds)

1144 except (TypeError, ValueError) as x:

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

1146 return t.closest

1147

1148

1149 def _set_reframe(inst, reframe):

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

1151 '''

1152 if reframe is not None:

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

1154 inst._reframe = reframe

1155 elif inst.reframe is not None:

1156 inst._reframe = None

1157

1158

1159__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)

1160

1161# **) MIT License

1162#

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

1164#

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

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

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

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

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

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

1171#

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

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

1174#

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

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

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

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

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

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

1181# OTHER DEALINGS IN THE SOFTWARE.