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, _ellipsoidal_ # PYCHOK used!

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

19 _spherical_datum, _WGS84, _xinstanceof

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

21 _ValueError, _xattr, _xellipsoidal, _xError, \

22 _xkwds, _xkwds_get, _xkwds_not

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

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

25 _reframe_, _SPACE_

26 from pygeodesy.latlonBase import LatLonBase, _trilaterate5, \

27 fabs, Vector3Tuple, _Wrap

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

29# from pygeodesy.lcc import toLcc # _MODS

30# from pygeodesy.named import notOverloaded # _MODS

31# from pygeodesy.namedTuples import Vector3Tuple # from .latlonBase

32 from pygeodesy.props import deprecated_method, deprecated_property_RO, \

33 Property_RO, property_doc_, property_RO, _update_all

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

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

36

37# from math import fabs # from .latlonBase

38

39__all__ = _ALL_LAZY.ellipsoidalBase

40__version__ = '23.09.22'

41

42

43 class CartesianEllipsoidalBase(CartesianBase):

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

45 '''

46 _datum = _WGS84 # L{Datum}

47 _reframe = None

48

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

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

51# '''

52# RefFrame = _MODS.trf.RefFrame

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

54# _NotImplemented(self, other)

55

56 @deprecated_method

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

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

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

60

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

62 Vector=None, **Vector_kwds):

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

64 cartesian center point and a radius.

65

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

67 coordinates).

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

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

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

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

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

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

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

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

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

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

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

79

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

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

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

83

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

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

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

87

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

89

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

91

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

93

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

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

96 Intersection and function L{pygeodesy.radical2}.

97 '''

98 try:

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

100 center2, Radius_(radius2=radius2),

101 sphere=sphere, clas=self.classof,

102 Vector=Vector, **Vector_kwds)

103 except (TypeError, ValueError) as x:

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

105

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

107 def reframe(self):

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

109 '''

110 return self._reframe

111

112 @reframe.setter # PYCHOK setter!

113 def reframe(self, reframe):

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

115

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

117 '''

118 _set_reframe(self, reframe)

119

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

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

122

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

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

125 overriding this cartesian's C{reframe}.

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

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

128

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

130 conversion is C{nil}.

131

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

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

134

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

136 L{RefFrame}.

137 '''

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

139 if r in (None, reframe2):

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

141 else:

142 trf = _MODS.trf

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

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

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

146

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

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

149

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

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

152 overriding this point's datum.

153

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

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

156 '''

157 r = self

158 if transforms:

159 xyz = r.xyz

160 for t in transforms:

161 xyz = t.transform(*xyz)

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

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

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

165 return r

166

167

168 class LatLonEllipsoidalBase(LatLonBase):

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

170 '''

171 _datum = _WGS84 # L{Datum}

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

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

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

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

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

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

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

179

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

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

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

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

184 the given reference frame and epoch.

185

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

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

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

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

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

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

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

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

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

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

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

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

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

199 (C{bool}).

200 @kwarg name: Optional name (string).

201

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

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

204

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

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

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

208

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

210

211 @example:

212

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

214 '''

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

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

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

218 if reframe:

219 self.reframe = reframe

220 self.epoch = epoch

221

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

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

224# '''

225# RefFrame = _MODS.trf.RefFrame

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

227# _NotImplemented(self, other)

228

229 def antipode(self, height=None):

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

231 to this point.

232

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

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

235

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

237 '''

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

239 if lla.datum != self.datum:

240 lla.datum = self.datum

241 return lla

242

243 @deprecated_property_RO

244 def convergence(self):

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

246 return self.gamma

247

248 @deprecated_method

249 def convertDatum(self, datum2):

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

251 return self.toDatum(datum2)

252

253 @deprecated_method

254 def convertRefFrame(self, reframe2):

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

256 return self.toRefFrame(reframe2)

257

258 @Property_RO

259 def _css(self):

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

261 '''

262 css = _MODS.css

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

264

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

266 def datum(self):

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

268 '''

269 return self._datum

270

271 @datum.setter # PYCHOK setter!

272 def datum(self, datum):

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

274

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

276 or not ellipsoidal.

277 '''

278 _xinstanceof(Datum, datum=datum)

279 if not datum.isEllipsoidal:

280 raise _IsnotError(_ellipsoidal_, datum=datum)

281 if self._datum != datum:

282 _update_all(self)

283 self._datum = datum

284

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

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

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

288

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

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

291

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

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

294 point (C{bool}).

295

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

297

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

299

300 @raise ValueError: Incompatible datum ellipsoids.

301

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

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

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

305 formula.

306 '''

307 p = self.others(other)

308 if wrap:

309 p = _Wrap.point(p)

310 E = self.ellipsoids(other)

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

312

313 @Property_RO

314 def _elevation2(self):

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

316 '''

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

318 timeout=self._elevation2to)

319

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

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

322 or sphere.

323

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

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

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

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

328 radius).

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

330

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

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

333

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

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

336 L{elevations.elevation2} is based.

337

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

339 U{Conterminous US (CONUS)

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

341

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

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

344 '''

345 if self._elevation2to != timeout:

346 self._elevation2to = timeout

347 LatLonEllipsoidalBase._elevation2._update(self)

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

349

350 def ellipsoid(self, datum=_WGS84):

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

352

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

354

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

356 '''

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

358

359 def ellipsoids(self, other):

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

361

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

363

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

365

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

367

368 @raise ValueError: Incompatible datum ellipsoids.

369 '''

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

371

372 E = self.ellipsoid()

373 try: # other may be Sphere, etc.

374 e = other.ellipsoid()

375 except AttributeError:

376 try: # no ellipsoid method, try datum

377 e = other.datum.ellipsoid

378 except AttributeError:

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

380 if e != E:

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

382 return E

383

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

385 def epoch(self):

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

387 '''

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

389

390 @epoch.setter # PYCHOK setter!

391 def epoch(self, epoch):

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

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

394

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

396 '''

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

398

399 @Property_RO

400 def Equidistant(self):

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

402 '''

403 try:

404 _ = self.datum.ellipsoid.geodesic

405 return _MODS.azimuthal.EquidistantKarney

406 except ImportError: # no geographiclib

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

408

409 @Property_RO

410 def _etm(self):

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

412 '''

413 etm = _MODS.etm

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

415

416 @property_RO

417 def gamma(self):

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

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

420 '''

421 return self._gamma

422

423 @Property_RO

424 def _geoidHeight2(self):

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

426 '''

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

428 timeout=self._geoidHeight2to)

429

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

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

432 or sphere.

433

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

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

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

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

438 radius).

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

440

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

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

443

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

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

446 the L{elevations.geoidHeight2} is based.

447

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

449 U{Conterminous US (CONUS)

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

451

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

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

454 '''

455 if self._geoidHeight2to != timeout:

456 self._geoidHeight2to = timeout

457 LatLonEllipsoidalBase._geoidHeight2._update(self)

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

459

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

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

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

463

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

465 equidistant=None, tol=_TOL_M):

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

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

468

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

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

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

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

473 initial bearing at the other point (compass

474 C{degrees360}).

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

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

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

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

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

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

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

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

483 convergence (C{meter}, conventionally).

484

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

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

487

488 @raise ImportError: Package U{geographiclib

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

490 not installed or not found, but only if

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

492

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

494 non-intersecting lines or no convergence

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

496

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

498 is not C{LatLon}.

499

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

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

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

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

504 of the authalic earth perimeter).

505

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

507 calculating-intersection-of-two-circles>} and U{Karney's paper

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

509 BOUNDARIES} for more details about the iteration algorithm.

510 '''

511 try:

512 s2 = self.others(other)

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

514 s2, end2,

515 height=height, wrap=wrap,

516 equidistant=equidistant, tol=tol,

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

518 except (TypeError, ValueError) as x:

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

520 height=height, wrap=wrap, tol=tol)

521

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

523 equidistant=None, tol=_TOL_M):

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

525 each defined by a center point and a radius.

526

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

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

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

530 B{C{radius1}}).

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

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

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

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

535 center (C{bool}).

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

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

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

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

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

541

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

543 instance. For abutting circles, both intersection

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

545

546 @raise ImportError: Package U{geographiclib

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

548 not installed or not found, but only if

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

550

551 @raise IntersectionError: Concentric, antipodal, invalid or

552 non-intersecting circles or no

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

554

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

556

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

558

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

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

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

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

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

564 intersections.

565 '''

566 try:

567 c2 = self.others(other)

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

569 c2, radius2,

570 height=height, wrap=wrap,

571 equidistant=equidistant, tol=tol,

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

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

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

575 height=height, wrap=wrap, tol=tol)

576

577 @Property_RO

578 def isEllipsoidalLatLon(self):

579 '''Get C{LatLon} base.

580 '''

581 return True

582

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

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

585

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

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

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

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

590

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

592 C{False} otherwise.

593

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

595

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

597

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

599

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

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

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

603 '''

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

605

606 @property_RO

607 def iteration(self):

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

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

610 '''

611 return self._iteration

612

613 @Property_RO

614 def _lcc(self):

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

616 '''

617 lcc = _MODS.lcc

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

619

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

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

622

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

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

625 mean height (C{meter}).

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

627 may be negative or greater than 1.0.

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

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

630

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

632

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

634

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

636

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

638 '''

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

640

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

642 equidistant=None, tol=_TOL_M):

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

644 two other (ellipsoidal) points.

645

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

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

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

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

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

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

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

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

654 takes the heights of the points into account.

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

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

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

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

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

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

661

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

663

664 @raise ImportError: Package U{geographiclib

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

666 not installed or not found, but only if

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

668

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

670 B{C{equidistant}}.

671

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

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

674

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

676 calculating-intersection-of-two-circles>} and U{Karney's paper

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

678 BOUNDARIES} for details about the iteration algorithm.

679 '''

680 try:

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

682 height=height, wrap=wrap,

683 equidistant=equidistant,

684 tol=tol, LatLon=self.classof)

685 except (TypeError, ValueError) as x:

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

687 height=height, wrap=wrap, tol=tol)

688 return t.closest

689

690 @Property_RO

691 def _osgr(self):

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

693 based on the OS recommendation.

694 '''

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

696

697 @Property_RO

698 def _osgrTM(self):

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

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

701 '''

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

703

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

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

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

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

708

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

710 see function L{pygeodesy.parse3llh}.

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

712 C{None}).

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

714 datum I{without conversion}.

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

716 epoch I{without conversion}.

717 @kwarg reframe: Optional datum (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-

721 and longitude (C{bool}).

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

723 this name.

724

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

726

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

728 '''

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

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

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, name=name, force=True) 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 _spherical_datum(datum).ellipsoid

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 toCss(self, **toCss_kwds):

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

783

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

785

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

787

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

789 '''

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

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

792

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

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

795

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

797 @kwarg height: Optional height, overriding the

798 converted height (C{meter}).

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

800

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

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

803 matches this point's C{datum}.

804

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

806

807 @example:

808

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

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

811 '''

812 n = name or self.name

813 d2 = _ellipsoidal_datum(datum2, name=n)

814 if self.datum == d2:

815 r = self.copy(name=name)

816 else:

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

818 epoch=self.epoch, reframe=self.reframe)

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

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

821 return r

822

823 def toEtm(self, **toEtm8_kwds):

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

825

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

827

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

829

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

831 '''

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

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

834

835 def toLcc(self, **toLcc_kwds):

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

837

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

839

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

841

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

843 '''

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

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

846

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

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

849

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

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

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

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

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

855

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

857

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

859 '''

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

861

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

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

864

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

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

867 formulation (C{bool}).

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

869

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

871

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

873 '''

874 if toOsgr_kwds:

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

876 else:

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

878 return r

879

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

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

882

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

884 @kwarg height: Optional height, overriding the converted

885 height (C{meter}).

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

887

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

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

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

891

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

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

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

895

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

897

898 @example:

899

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

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

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

903 '''

904 if not self.reframe:

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

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

907

908 trf = _MODS.trf

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

910

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

912 if xs:

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

914 n = name or self.name

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

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

917 else:

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

919 return ll

920

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

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

923

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

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

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

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

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

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

930

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

932

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

934 '''

935 if self._upsOK(pole, falsed):

936 u = self._ups

937 else:

938 ups = _MODS.ups

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

940 pole=pole, falsed=falsed)

941 return _lowerleft(u, center)

942

943 def toUtm(self, center=False):

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

945

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

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

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

949

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

951

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

953 '''

954 return _lowerleft(self._utm, center)

955

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

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

958

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

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

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

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

963 meter} (C{scalar}).

964

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

966

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

968 '''

969 if self._utmOK():

970 u = self._utm

971 elif self._upsOK(pole):

972 u = self._ups

973 else: # no cover

974 utmups = _MODS.utmups

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

976 Utm=utmups.Utm, Ups=utmups.Ups)

977 if isinstance(u, utmups.Utm):

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

979 elif isinstance(u, utmups.Ups):

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

981 else:

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

983 return _lowerleft(u, center)

984

985 @deprecated_method

986 def to3xyz(self): # PYCHOK no cover

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

988

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

990

991 @note: Overloads C{LatLonBase.to3xyz}

992 '''

993 r = self.toEcef()

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

995

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

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

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

999 intersection} of three intersecting circles.

1000

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

1002 as B{C{eps}}).

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

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

1005 B{C{eps}}).

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

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

1008 B{C{eps}}).

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

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

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

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

1013 (C{meter}, conventionally).

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

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

1016

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

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

1019 the corresponding trilaterated points C{minPoint} and

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

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

1022

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

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

1025

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

1027 respectively largest I{radial} overlap found.

1028

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

1030 nearest respectively farthest intersection margin.

1031

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

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

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

1035 largest B{C{distance#}}.

1036

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

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

1039 no intersection or all (near-)concentric for

1040 C{B{area}=False}.

1041

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

1043

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

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

1046

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

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

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

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

1051 '''

1052 return _trilaterate5(self, distance1,

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

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

1055 area=area, eps=eps, wrap=wrap)

1056

1057 @Property_RO

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

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

1060 see L{pygeodesy.toUps8}.

1061 '''

1062 ups = _MODS.ups

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

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

1065

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

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

1068 '''

1069 try:

1070 u = self._ups

1071 except RangeError:

1072 return False

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

1074

1075 @Property_RO

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

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

1078 see L{pygeodesy.toUtm8}.

1079 '''

1080 utm = _MODS.utm

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

1082

1083 def _utmOK(self):

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

1085 '''

1086 try:

1087 _ = self._utm

1088 except RangeError:

1089 return False

1090 return True

1091

1092

1093 def _lowerleft(utmups, center):

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

1095 '''

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

1097 u = utmups

1098 elif center in (True,):

1099 u = utmups._lowerleft

1100 else:

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

1102 return u

1103

1104

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

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

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

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

1109 '''

1110 try:

1111 p = _xellipsoidal(point=point)

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

1113 height=height, wrap=wrap,

1114 equidistant=equidistant,

1115 tol=tol, **LatLon_and_kwds)

1116 except (TypeError, ValueError) as x:

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

1118 return t.closest

1119

1120

1121 def _set_reframe(inst, reframe):

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

1123 '''

1124 if reframe is not None:

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

1126 inst._reframe = reframe

1127 elif inst.reframe is not None:

1128 inst._reframe = None

1129

1130

1131__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)

1132

1133# **) MIT License

1134#

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

1136#

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

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

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

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

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

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

1143#

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

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

1146#

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

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

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

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

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

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

1153# OTHER DEALINGS IN THE SOFTWARE.