1

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

3

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

5 and C{LatLonEllipsoidalBase}.

6

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

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

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

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

11'''

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

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

14

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

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

17 from pygeodesy.cartesianBase import CartesianBase # PYCHOK used!

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

19 _WGS84, _EWGS84, _xinstanceof # _spherical_datum

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

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

22 _TypeError, _ValueError, _xattr, _xellipsoidal, \

23 _xError, _xkwds, _xkwds_get, _xkwds_not

24# from pygeodesy.fmath import favg # _MODS

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

26 _ellipsoidal_, _no_, _reframe_, _SPACE_

27 from pygeodesy.latlonBase import LatLonBase, _trilaterate5, fabs, _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 # _MODS

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, _isDegrees, Radius_, _1mm as _TOL_M

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

36

37# from math import fabs # from .latlonBase

38

39__all__ = _ALL_LAZY.ellipsoidalBase

40__version__ = '23.12.18'

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 @property_RO

62 def ellipsoidalCartesian(self):

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

64 '''

65 return type(self)

66

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

68 Vector=None, **Vector_kwds):

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

70 cartesian center point and a radius.

71

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

73 coordinates).

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

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

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

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

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

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

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

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

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

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

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

85

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

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

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

89

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

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

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

93

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

95

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

97

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

99

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

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

102 Intersection and function L{pygeodesy.radical2}.

103 '''

104 try:

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

106 center2, Radius_(radius2=radius2),

107 sphere=sphere, clas=self.classof,

108 Vector=Vector, **Vector_kwds)

109 except (TypeError, ValueError) as x:

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

111

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

113 def reframe(self):

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

115 '''

116 return self._reframe

117

118 @reframe.setter # PYCHOK setter!

119 def reframe(self, reframe):

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

121

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

123 '''

124 _set_reframe(self, reframe)

125

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

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

128

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

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

131 overriding this cartesian's C{reframe}.

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

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

134

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

136 conversion is C{nil}.

137

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

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

140

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

142 L{RefFrame}.

143 '''

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

145 if r in (None, reframe2):

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

147 else:

148 trf = _MODS.trf

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

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

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

152

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

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

155

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

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

158 overriding this point's datum.

159

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

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

162 '''

163 r = self

164 if transforms:

165 xyz = r.xyz

166 for t in transforms:

167 xyz = t.transform(*xyz)

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

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

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

171 return r

172

173

174 class LatLonEllipsoidalBase(LatLonBase):

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

176 '''

177 _datum = _WGS84 # L{Datum}

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

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

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

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

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

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

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

185

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

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

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

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

190

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

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

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

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

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

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

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

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

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

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

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

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

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

204 (C{bool}).

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

206

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

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

209

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

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

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

213

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

215 '''

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

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

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

219 if reframe:

220 self.reframe = reframe

221 self.epoch = epoch

222

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

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

225# '''

226# RefFrame = _MODS.trf.RefFrame

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

228# _NotImplemented(self, other)

229

230 def antipode(self, height=None):

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

232 to this point.

233

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

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

236

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

238 '''

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

240 if lla.datum != self.datum:

241 lla.datum = self.datum

242 return lla

243

244 @deprecated_property_RO

245 def convergence(self):

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

247 return self.gamma

248

249 @deprecated_method

250 def convertDatum(self, datum2):

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

252 return self.toDatum(datum2)

253

254 @deprecated_method

255 def convertRefFrame(self, reframe2):

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

257 return self.toRefFrame(reframe2)

258

259 @Property_RO

260 def _css(self):

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

262 '''

263 css = _MODS.css

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

265

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

267 def datum(self):

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

269 '''

270 return self._datum

271

272 @datum.setter # PYCHOK setter!

273 def datum(self, datum):

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

275

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

277 or not ellipsoidal.

278 '''

279 _xinstanceof(Datum, datum=datum)

280 if not datum.isEllipsoidal:

281 raise _IsnotError(_ellipsoidal_, datum=datum)

282 if self._datum != datum:

283 _update_all(self)

284 self._datum = datum

285

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

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

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

289

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

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

292

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

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

295 point (C{bool}).

296

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

298

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

300

301 @raise ValueError: Incompatible datum ellipsoids.

302

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

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

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

306 formula.

307 '''

308 p = self.others(other)

309 if wrap:

310 p = _Wrap.point(p)

311 E = self.ellipsoids(other)

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

313

314 @Property_RO

315 def _elevation2(self):

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

317 '''

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

319 timeout=self._elevation2to)

320

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

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

323 or sphere.

324

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

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

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

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

329 radius).

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

331

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

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

334

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

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

337 L{elevations.elevation2} is based.

338

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

340 U{Conterminous US (CONUS)

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

342

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

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

345 '''

346 if self._elevation2to != timeout:

347 self._elevation2to = timeout

348 LatLonEllipsoidalBase._elevation2._update(self)

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

350

351 def ellipsoid(self, datum=_WGS84):

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

353

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

355

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

357 '''

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

359

360 @property_RO

361 def ellipsoidalLatLon(self):

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

363 '''

364 return type(self)

365

366 def ellipsoids(self, other):

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

368

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

370

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

372

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

374

375 @raise ValueError: Incompatible datum ellipsoids.

376 '''

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

378

379 E = self.ellipsoid()

380 try: # other may be Sphere, etc.

381 e = other.ellipsoid()

382 except AttributeError:

383 try: # no ellipsoid method, try datum

384 e = other.datum.ellipsoid

385 except AttributeError:

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

387 if e != E:

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

389 return E

390

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

392 def epoch(self):

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

394 '''

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

396

397 @epoch.setter # PYCHOK setter!

398 def epoch(self, epoch):

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

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

401

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

403 '''

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

405

406 @Property_RO

407 def Equidistant(self):

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

409 '''

410 try:

411 _ = self.datum.ellipsoid.geodesic

412 return _MODS.azimuthal.EquidistantKarney

413 except ImportError: # no geographiclib

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

415

416 @Property_RO

417 def _etm(self):

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

419 '''

420 etm = _MODS.etm

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

422

423 @property_RO

424 def gamma(self):

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

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

427 '''

428 return self._gamma

429

430 @Property_RO

431 def _geoidHeight2(self):

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

433 '''

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

435 timeout=self._geoidHeight2to)

436

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

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

439 or sphere.

440

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

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

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

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

445 radius).

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

447

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

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

450

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

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

453 the L{elevations.geoidHeight2} is based.

454

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

456 U{Conterminous US (CONUS)

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

458

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

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

461 '''

462 if self._geoidHeight2to != timeout:

463 self._geoidHeight2to = timeout

464 LatLonEllipsoidalBase._geoidHeight2._update(self)

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

466

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

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

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

470

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

472 equidistant=None, tol=_TOL_M):

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

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

475

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

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

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

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

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

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

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

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

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

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

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

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

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

489 length (C{meter}, conventionally).

490

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

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

493

494 @raise ImportError: Package U{geographiclib

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

496 not installed or not found, but only if

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

498

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

500 non-intersecting lines or no convergence

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

502

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

504 is not C{LatLon}.

505

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

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

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

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

510 of the authalic earth perimeter).

511

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

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

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

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

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

517 '''

518 try:

519 s2 = self.others(other)

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

521 s2, end2,

522 height=height, wrap=wrap,

523 equidistant=equidistant, tol=tol,

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

525 except (TypeError, ValueError) as x:

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

527 height=height, wrap=wrap, tol=tol)

528

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

530 equidistant=None, tol=_TOL_M):

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

532 each defined by a center point and a radius.

533

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

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

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

537 B{C{radius1}}).

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

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

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

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

542 center (C{bool}).

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

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

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

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

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

548

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

550 instance. For abutting circles, both intersection

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

552

553 @raise ImportError: Package U{geographiclib

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

555 not installed or not found, but only if

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

557

558 @raise IntersectionError: Concentric, antipodal, invalid or

559 non-intersecting circles or no

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

561

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

563

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

565

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

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

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

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

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

571 intersections.

572 '''

573 try:

574 c2 = self.others(other)

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

576 c2, radius2,

577 height=height, wrap=wrap,

578 equidistant=equidistant, tol=tol,

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

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

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

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

583

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

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

586

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

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

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

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

591

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

593 C{False} otherwise.

594

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

596

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

598

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

600

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

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

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

604 '''

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

606

607 @property_RO

608 def iteration(self):

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

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

611 '''

612 return self._iteration

613

614 @Property_RO

615 def _lcc(self):

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

617 '''

618 lcc = _MODS.lcc

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

620

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

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

623

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

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

626 mean height (C{meter}).

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

628 may be negative or greater than 1.0.

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

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

631

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

633

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

635

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

637

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

639 '''

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

641

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

643 equidistant=None, tol=_TOL_M):

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

645 two other (ellipsoidal) points.

646

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

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

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

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

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

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

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

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

655 takes the heights of the points into account.

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

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

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

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

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

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

662

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

664

665 @raise ImportError: Package U{geographiclib

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

667 not installed or not found, but only if

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

669

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

671 B{C{equidistant}}.

672

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

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

675

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

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

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

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

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

681 '''

682 try:

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

684 height=height, wrap=wrap,

685 equidistant=equidistant,

686 tol=tol, LatLon=self.classof)

687 except (TypeError, ValueError) as x:

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

689 height=height, wrap=wrap, tol=tol)

690 return t.closest

691

692 @Property_RO

693 def _osgr(self):

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

695 based on the OS recommendation.

696 '''

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

698

699 @Property_RO

700 def _osgrTM(self):

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

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

703 '''

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

705

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

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

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

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

710

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

712 see function L{pygeodesy.parse3llh}.

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

714 C{None}).

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

716 datum I{without conversion}.

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

718 epoch I{without conversion}.

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

720 this reframe I{without conversion}.

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

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

723 and longitude (C{bool}).

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

725 this name.

726

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

728

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

730 '''

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

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

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

734 r.datum = datum

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

736 r.epoch = epoch

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

738 r.reframe = reframe

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

740

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

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

743 difference in Gaussian radii of curvature of the given

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

745

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

747 '''

748 if adjust: # Elevation2Tuple or GeoidHeight2Tuple

749 m, t = meter_text2

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

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

752 if n > EPS0:

753 # use ratio, datum and NAD83 units may differ

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

755 _earth_ellipsoid(datum)

756 r = E.rocGauss(self.lat)

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

758 m *= r / n

759 meter_text2 = meter_text2.classof(m, t)

760 return self._xnamed(meter_text2)

761

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

763 def reframe(self):

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

765 '''

766 return self._reframe

767

768 @reframe.setter # PYCHOK setter!

769 def reframe(self, reframe):

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

771

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

773 '''

774 _set_reframe(self, reframe)

775

776 @Property_RO

777 def scale(self):

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

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

780 '''

781 return self._scale

782

783 def toCss(self, **toCss_kwds):

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

785

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

787

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

789

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

791 '''

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

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

794

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

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

797

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

799 @kwarg height: Optional height, overriding the

800 converted height (C{meter}).

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

802

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

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

805 matches this point's C{datum}.

806

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

808 '''

809 n = name or self.name

810 d2 = _ellipsoidal_datum(datum2, name=n)

811 if self.datum == d2:

812 r = self.copy(name=name)

813 else:

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

815 epoch=self.epoch, reframe=self.reframe)

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

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

818 return r

819

820 def toEtm(self, **toEtm8_kwds):

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

822

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

824

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

826

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

828 '''

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

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

831

832 def toLcc(self, **toLcc_kwds):

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

834

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

836

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

838

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

840 '''

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

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

843

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

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

846

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

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

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

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

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

852

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

854

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

856 '''

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

858

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

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

861

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

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

864 formulation (C{bool}).

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

866

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

868

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

870 '''

871 if toOsgr_kwds:

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

873 else:

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

875 return r

876

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

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

879

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

881 @kwarg height: Optional height, overriding the converted

882 height (C{meter}).

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

884

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

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

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

888

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

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

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

892

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

894 '''

895 if not self.reframe:

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

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

898

899 trf = _MODS.trf

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

901

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

903 if xs:

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

905 n = name or self.name

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

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

908 else:

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

910 return ll

911

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

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

914

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

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

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

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

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

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

921

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

923

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

925 '''

926 if self._upsOK(pole, falsed):

927 u = self._ups

928 else:

929 ups = _MODS.ups

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

931 pole=pole, falsed=falsed)

932 return _lowerleft(u, center)

933

934 def toUtm(self, center=False):

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

936

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

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

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

940

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

942

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

944 '''

945 return _lowerleft(self._utm, center)

946

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

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

949

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

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

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

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

954 meter} (C{scalar}).

955

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

957

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

959 '''

960 if self._utmOK():

961 u = self._utm

962 elif self._upsOK(pole):

963 u = self._ups

964 else: # no cover

965 utmups = _MODS.utmups

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

967 Utm=utmups.Utm, Ups=utmups.Ups)

968 if isinstance(u, utmups.Utm):

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

970 elif isinstance(u, utmups.Ups):

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

972 else:

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

974 return _lowerleft(u, center)

975

976 @deprecated_method

977 def to3xyz(self): # PYCHOK no cover

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

979

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

981

982 @note: Overloads C{LatLonBase.to3xyz}

983 '''

984 r = self.toEcef()

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

986

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

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

989 bearing at this and at the other point.

990

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

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

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

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

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

996

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

998

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

1000 '''

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

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

1003 return r.point

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

1005

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

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

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

1009 intersection} of three intersecting circles.

1010

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

1012 as B{C{eps}}).

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

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

1015 B{C{eps}}).

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

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

1018 B{C{eps}}).

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

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

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

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

1023 (C{meter}, conventionally).

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

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

1026

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

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

1029 the corresponding trilaterated points C{minPoint} and

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

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

1032

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

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

1035

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

1037 respectively largest I{radial} overlap found.

1038

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

1040 nearest respectively farthest intersection margin.

1041

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

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

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

1045 largest B{C{distance#}}.

1046

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

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

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

1050 all circles are (near-)concentric.

1051

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

1053

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

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

1056

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

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

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

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

1061 '''

1062 return _trilaterate5(self, distance1,

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

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

1065 area=area, eps=eps, wrap=wrap)

1066

1067 @Property_RO

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

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

1070 see L{pygeodesy.toUps8}.

1071 '''

1072 ups = _MODS.ups

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

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

1075

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

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

1078 '''

1079 try:

1080 u = self._ups

1081 except RangeError:

1082 return False

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

1084

1085 @Property_RO

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

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

1088 see L{pygeodesy.toUtm8}.

1089 '''

1090 utm = _MODS.utm

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

1092

1093 def _utmOK(self):

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

1095 '''

1096 try:

1097 _ = self._utm

1098 except RangeError:

1099 return False

1100 return True

1101

1102

1103 def _lowerleft(utmups, center):

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

1105 '''

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

1107 u = utmups

1108 elif center in (True,):

1109 u = utmups._lowerleft

1110 else:

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

1112 return u

1113

1114

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

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

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

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

1119 '''

1120 try:

1121 p = _xellipsoidal(point=point)

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

1123 height=height, wrap=wrap,

1124 equidistant=equidistant,

1125 tol=tol, **LatLon_and_kwds)

1126 except (TypeError, ValueError) as x:

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

1128 return t.closest

1129

1130

1131 def _set_reframe(inst, reframe):

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

1133 '''

1134 if reframe is not None:

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

1136 inst._reframe = reframe

1137 elif inst.reframe is not None:

1138 inst._reframe = None

1139

1140

1141__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)

1142

1143# **) MIT License

1144#

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

1146#

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

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

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

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

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

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

1153#

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

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

1156#

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

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

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

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

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

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

1163# OTHER DEALINGS IN THE SOFTWARE.