Coverage for pygeodesy/ellipsoidalBase.py: 94%
261 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-01-10 16:55 -0500
« prev ^ index » next coverage.py v7.6.1, created at 2025-01-10 16:55 -0500
2# -*- coding: utf-8 -*-
4u'''(INTERNAL) Private ellipsoidal base classes C{CartesianEllipsoidalBase}
5and C{LatLonEllipsoidalBase}.
7A pure Python implementation of geodesy tools for ellipsoidal earth models,
8transcoded in part from JavaScript originals by I{(C) Chris Veness 2005-2024}
9and 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
13from __future__ import division as _; del _ # PYCHOK semicolon
15# from pygeodesy.basics import _xinstanceof # from .datums
16from pygeodesy.constants import EPS, EPS0, EPS1, _0_0, _0_5
17from pygeodesy.cartesianBase import CartesianBase # PYCHOK used!
18from pygeodesy.datums import Datum, Datums, _earth_ellipsoid, _ellipsoidal_datum, \
19 Transform, _WGS84, _EWGS84, _xinstanceof # _spherical_datum
20# from pygeodesy.ellipsoids import _EWGS84 # from .datums
21from pygeodesy.errors import _IsnotError, RangeError, _TypeError, _xattr, _xellipsoidal, \
22 _xellipsoids, _xError, _xkwds, _xkwds_not
23# from pygeodesy.fmath import favg # _MODS
24from pygeodesy.interns import NN, _COMMA_, _ellipsoidal_
25from pygeodesy.latlonBase import LatLonBase, _trilaterate5, fabs, _Wrap
26from 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
29from pygeodesy.props import deprecated_method, deprecated_property_RO, \
30 Property_RO, property_doc_, property_RO, _update_all
31# from pygeodesy.trf import _eT0Ds4 # _MODS
32from pygeodesy.units import Epoch, _isDegrees, Radius_, _1mm as _TOL_M
33# from pygeodesy.utily import _Wrap # from .latlonBase
35# from math import fabs # from .latlonBase
37__all__ = _ALL_LAZY.ellipsoidalBase
38__version__ = '24.12.04'
41class 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})
48 def __init__(self, x_xyz, y=None, z=None, reframe=None, epoch=None,
49 **datum_ll_name):
50 '''New ellispoidal C{Cartesian...}.
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}.
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.
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
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)
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) # PYCHOK no cover
82 @property_RO
83 def ellipsoidalCartesian(self):
84 '''Get this C{Cartesian}'s ellipsoidal class.
85 '''
86 return type(self)
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)
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}.
99 @raise TRFError: Invalid B{C{epoch}}.
100 '''
101 self._epoch = None if epoch is None else Epoch(epoch)
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.
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}.
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}).
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}.
130 @raise IntersectionError: Concentric, invalid or non-intersecting spheres or circles.
132 @raise TypeError: Invalid B{C{center2}}.
134 @raise UnitError: Invalid B{C{radius}} or B{C{radius2}}.
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)
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
154 @reframe.setter # PYCHOK setter!
155 def reframe(self, reframe):
156 '''Set or clear this cartesian's reference frame (L{RefFrame}) or C{None}.
158 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}.
159 '''
160 _set_reframe(self, reframe)
162 def toLatLon(self, datum=None, height=None, **LatLon_and_kwds): # PYCHOK signature
163 '''Convert this cartesian to a I{geodetic} (lat-/longitude) point.
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)
173 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, **name):
174 '''Convert this point to an other reference frame and epoch.
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}.
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.
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.
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)
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
207class 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
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.
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}).
239 @raise RangeError: Value of C{lat} or B{C{lon}} outside the valid range and
240 L{rangerrors} set to C{True}.
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.
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
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)
262 def antipode(self, height=None):
263 '''Return the antipode, the point diametrically opposite
264 to this point.
266 @kwarg height: Optional height of the antipode, height
267 of this point otherwise (C{meter}).
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
276 @deprecated_property_RO
277 def convergence(self):
278 '''DEPRECATED, use property C{gamma}.'''
279 return self.gamma # PYCHOK no cover
281 @deprecated_method
282 def convertDatum(self, datum2):
283 '''DEPRECATED, use method L{toDatum}.'''
284 return self.toDatum(datum2)
286 @deprecated_method
287 def convertRefFrame(self, reframe2):
288 '''DEPRECATED, use method L{toRefFrame}.'''
289 return self.toRefFrame(reframe2)
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
297 @datum.setter # PYCHOK setter!
298 def datum(self, datum):
299 '''Set this point's datum I{without conversion} (L{Datum}).
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
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.
314 I{Suitable only for short distances up to a few hundred Km
315 or Miles and only between points not near-polar}.
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}).
321 @return: An L{Distance2Tuple}C{(distance, initial)}.
323 @raise TypeError: The B{C{other}} point is not C{LatLon}.
325 @raise ValueError: Incompatible datum ellipsoids.
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: # PYCHOK no cover
334 p = _Wrap.point(p)
335 E = self.ellipsoids(other)
336 return E.distance2(*(self.latlon + p.latlon))
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)
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.
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}).
356 @return: An L{Elevation2Tuple}C{(elevation, data_source)} or
357 C{(None, error)} in case of errors.
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.
363 @note: NED elevation is only available for locations within the U{Conterminous
364 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}.
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)
374 def ellipsoid(self, datum=_WGS84):
375 '''Return the ellipsoid of this point's datum or the given datum.
377 @kwarg datum: Default datum (L{Datum}).
379 @return: The ellipsoid (L{Ellipsoid} or L{Ellipsoid2}).
380 '''
381 return _xattr(self, datum=datum).ellipsoid
383 @property_RO
384 def ellipsoidalLatLon(self):
385 '''Get this C{LatLon}'s ellipsoidal class.
386 '''
387 return type(self)
389 def ellipsoids(self, other):
390 '''Check the type and ellipsoid of this and an other point's datum.
392 @arg other: The other point (C{LatLon}).
394 @return: This point's datum ellipsoid (L{Ellipsoid} or L{Ellipsoid2}).
396 @raise TypeError: The B{C{other}} point is not C{LatLon}.
398 @raise ValueError: Incompatible datum ellipsoids.
399 '''
400 self.others(other, up=2) # ellipsoids' caller
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)
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)
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}.
423 @raise TRFError: Invalid B{C{epoch}}.
424 '''
425 self._epoch = None if epoch is None else Epoch(epoch)
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}
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)
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
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)
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.
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}).
469 @return: A L{GeoidHeight2Tuple}C{(height, model_name)} or
470 C{(None, error)} in case of errors.
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.
476 @note: The geoid height is only available for locations within the U{Conterminous
477 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}.
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)
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)
491 def intersection3(self, end1, start2, end2, height=None, wrap=False, # was=True
492 equidistant=None, tol=_TOL_M):
493 '''I{Iteratively} compute the intersection point of two geodesic lines, each
494 given as two points or as a start point and a bearing from North.
496 @arg end1: End point of this line (C{LatLon}) or the initial bearing at
497 this point (compass C{degrees360}).
498 @arg start2: Start point of the second line (this C{LatLon}).
499 @arg end2: End point of the second line (this C{LatLon}) or the initial
500 bearing at B{C{start2}} (compass C{degrees360}).
501 @kwarg height: Optional height at the intersection (C{meter}, conventionally)
502 or C{None} for the mean height.
503 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{start2}} and
504 both B{C{end*}} points (C{bool}).
505 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function
506 L{pygeodesy.equidistant}), or C{None} for this point's
507 preferred C{.Equidistant}.
508 @kwarg tol: Tolerance for convergence and skew line distance and length
509 (C{meter}, conventionally).
511 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)} with C{point}
512 a C{LatLon} instance.
514 @raise ImportError: Package U{geographiclib
515 <https://PyPI.org/project/geographiclib>} not
516 installed or not found, but only in case
517 C{B{equidistant}=}L{EquidistantKarney}.
519 @raise IntersectionError: Skew, colinear, parallel or otherwise non-intersecting
520 lines or no convergence for the given B{C{tol}}.
522 @raise TypeError: Invalid B{C{end1}}, B{C{start2}} or B{C{end2}}.
524 @note: For each line specified with an initial bearing, a pseudo-end point is
525 computed as the C{destination} along that bearing at about 1.5 times the
526 distance from the start point to an initial gu-/estimate of the intersection
527 point (and between 1/8 and 3/8 of the C{authalic} earth perimeter).
529 @see: I{Karney's} U{intersect.cpp<https://SourceForge.net/p/geographiclib/
530 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https://
531 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>}
532 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section
533 B{14. MARITIME BOUNDARIES} for more details about the iteration algorithm.
534 '''
535 try:
536 s2 = self.others(start2=start2)
537 return _MODS.ellipsoidalBaseDI._intersect3(self, end1,
538 s2, end2,
539 height=height, wrap=wrap,
540 equidistant=equidistant, tol=tol,
541 LatLon=self.classof, datum=self.datum)
542 except (TypeError, ValueError) as x:
543 raise _xError(x, start1=self, end1=end1, start2=start2, end2=end2,
544 height=height, wrap=wrap, tol=tol)
546 def intersections2(self, radius1, center2, radius2, height=None, wrap=False, # was=True
547 equidistant=None, tol=_TOL_M):
548 '''I{Iteratively} compute the intersection points of two circles, each
549 defined by a center point and a radius.
551 @arg radius1: Radius of this circle (C{meter}, conventionally).
552 @arg center2: Center of the other circle (this C{LatLon}).
553 @arg radius2: Radius of the other circle (C{meter}, same units as
554 B{C{radius1}}).
555 @kwarg height: Optional height for the intersection points (C{meter},
556 conventionally) or C{None} for the I{"radical height"}
557 at the I{radical line} between both centers.
558 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{center2}}
559 (C{bool}).
560 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
561 function L{pygeodesy.equidistant}) or C{None}
562 for this point's preferred C{.Equidistant}.
563 @kwarg tol: Convergence tolerance (C{meter}, same units as
564 B{C{radius1}} and B{C{radius2}}).
566 @return: 2-Tuple of the intersection points, each a C{LatLon}
567 instance. For abutting circles, both intersection
568 points are the same instance, aka the I{radical center}.
570 @raise ImportError: Package U{geographiclib
571 <https://PyPI.org/project/geographiclib>}
572 not installed or not found, but only if
573 C{B{equidistant}=}L{EquidistantKarney}.
575 @raise IntersectionError: Concentric, antipodal, invalid or
576 non-intersecting circles or no
577 convergence for the given B{C{tol}}.
579 @raise TypeError: Invalid B{C{center2}} or B{C{equidistant}}.
581 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.
583 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
584 calculating-intersection-of-two-circles>}, U{Karney's paper
585 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},
586 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and
587 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}
588 intersections.
589 '''
590 try:
591 c2 = self.others(center2=center2)
592 return _MODS.ellipsoidalBaseDI._intersections2(self, radius1,
593 c2, radius2,
594 height=height, wrap=wrap,
595 equidistant=equidistant, tol=tol,
596 LatLon=self.classof, datum=self.datum)
597 except (AssertionError, TypeError, ValueError) as x:
598 raise _xError(x, center=self, radius1=radius1, center2=center2, radius2=radius2,
599 height=height, wrap=wrap, tol=tol)
601 def isenclosedBy(self, points, wrap=False):
602 '''Check whether a polygon or composite encloses this point.
604 @arg points: The polygon points or clips (C{LatLon}[],
605 L{BooleanFHP} or L{BooleanGH}).
606 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
607 B{C{points}} (C{bool}).
609 @return: C{True} if this point is inside the polygon or composite,
610 C{False} otherwise.
612 @raise PointsError: Insufficient number of B{C{points}}.
614 @raise TypeError: Some B{C{points}} are not C{LatLon}.
616 @raise ValueError: Invalid B{C{point}}, lat- or longitude.
618 @see: Functions L{pygeodesy.isconvex}, L{pygeodesy.isenclosedBy}
619 and L{pygeodesy.ispolar} especially if the B{C{points}} may
620 enclose a pole or wrap around the earth I{longitudinally}.
621 '''
622 return _MODS.points.isenclosedBy(self, points, wrap=wrap)
624 @property_RO
625 def iteration(self):
626 '''Get the most recent C{intersections2} or C{nearestOn} iteration
627 number (C{int}) or C{None} if not available/applicable.
628 '''
629 return self._iteration
631 def midpointTo(self, other, height=None, fraction=_0_5, wrap=False):
632 '''Find the midpoint on a geodesic between this and an other point.
634 @arg other: The other point (C{LatLon}).
635 @kwarg height: Optional height for midpoint, overriding the
636 mean height (C{meter}).
637 @kwarg fraction: Midpoint location from this point (C{scalar}),
638 may be negative or greater than 1.0.
639 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
640 B{C{other}} point (C{bool}).
642 @return: Midpoint (C{LatLon}).
644 @raise TypeError: The B{C{other}} point is not C{LatLon}.
646 @raise ValueError: Invalid B{C{height}}.
648 @see: Methods C{intermediateTo} and C{rhumbMidpointTo}.
649 '''
650 return self.intermediateTo(other, fraction, height=height, wrap=wrap)
652 def nearestOn(self, point1, point2, within=True, height=None, wrap=False, # was=True
653 equidistant=None, tol=_TOL_M):
654 '''I{Iteratively} locate the closest point on the geodesic (line)
655 between two other (ellipsoidal) points.
657 @arg point1: Start point of the geodesic (C{LatLon}).
658 @arg point2: End point of the geodesic (C{LatLon}).
659 @kwarg within: If C{True}, return the closest point I{between} B{C{point1}} and
660 B{C{point2}}, otherwise the closest point elsewhere on the geodesic
661 (C{bool}).
662 @kwarg height: Optional height for the closest point (C{meter}, conventionally)
663 or C{None} or C{False} for the interpolated height. If C{False},
664 the closest takes the heights of the points into account.
665 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both B{C{point1}} and
666 B{C{point2}} (C{bool}).
667 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function
668 L{pygeodesy.equidistant}) or C{None} for this point's preferred
669 C{Equidistant}, like L{Equidistant<LatLonEllipsoidalBase.Equidistant>}.
670 @kwarg tol: Convergence tolerance (C{meter}, conventionally).
672 @return: Closest point (C{LatLon}).
674 @raise ImportError: Package U{geographiclib
675 <https://PyPI.org/project/geographiclib>}
676 not installed or not found, but only if
677 C{B{equidistant}=}L{EquidistantKarney}.
679 @raise TypeError: Invalid B{C{point1}}, B{C{point2}} or B{C{equidistant}}.
681 @raise ValueError: Datum or ellipsoid of B{C{point1}} or B{C{point2}} is incompatible
682 or no convergence for the given B{C{tol}}.
684 @see: I{Karney}'s U{intercept.cpp<https://SourceForge.net/p/geographiclib/
685 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https://
686 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>}
687 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section
688 B{14. MARITIME BOUNDARIES} for details about the iteration algorithm.
689 '''
690 try:
691 t = _MODS.ellipsoidalBaseDI._nearestOn2(self, point1, point2, within=within,
692 height=height, wrap=wrap,
693 equidistant=equidistant,
694 tol=tol, LatLon=self.classof)
695 except (TypeError, ValueError) as x:
696 raise _xError(x, point=self, point1=point1, point2=point2, within=within,
697 height=height, wrap=wrap, tol=tol)
698 return t.closest
700 def parse(self, strllh, height=0, datum=None, epoch=None, reframe=None,
701 sep=_COMMA_, wrap=False, **name):
702 '''Parse a string consisting of C{"lat, lon[, height]"},
703 representing a similar, ellipsoidal C{LatLon} point.
705 @arg strllh: Lat, lon and optional height (C{str}), see function
706 L{pygeodesy.parse3llh}.
707 @kwarg height: Optional, default height (C{meter} or C{None}).
708 @kwarg datum: Optional datum (L{Datum}), overriding this datum
709 I{without conversion}.
710 @kwarg epoch: Optional datum (L{Epoch}), overriding this epoch
711 I{without conversion}.
712 @kwarg reframe: Optional reference frame (L{RefFrame}), overriding
713 this reframe I{without conversion}.
714 @kwarg sep: Optional separator (C{str}).
715 @kwarg wrap: If C{True}, wrap or I{normalize} the lat- and
716 longitude (C{bool}).
717 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding this name.
719 @return: The similar point (ellipsoidal C{LatLon}).
721 @raise ParseError: Invalid B{C{strllh}}.
722 '''
723 a, b, h = _MODS.dms.parse3llh(strllh, height=height, sep=sep, wrap=wrap)
724 return self.classof(a, b, height=h, datum=datum or self.datum,
725 epoch=epoch or self.epoch,
726 reframe=reframe or self.reframe, **name)
728 def _Radjust2(self, adjust, datum, meter_text2):
729 '''(INTERNAL) Adjust an C{elevation} or C{geoidHeight} with
730 difference in Gaussian radii of curvature of the given
731 datum and NAD83 ellipsoids at this point's latitude.
733 @note: This is an arbitrary, possibly incorrect adjustment.
734 '''
735 if adjust: # Elevation2Tuple or GeoidHeight2Tuple
736 m, t = meter_text2
737 if isinstance(m, float) and fabs(m) > EPS: # PYCHOK no cover
738 n = Datums.NAD83.ellipsoid.rocGauss(self.lat)
739 if n > EPS0:
740 # use ratio, datum and NAD83 units may differ
741 E = self.ellipsoid() if datum in (None, self.datum) else \
742 _earth_ellipsoid(datum)
743 r = E.rocGauss(self.lat)
744 if r > EPS0 and fabs(r - n) > EPS: # EPS1
745 m *= r / n
746 meter_text2 = meter_text2.classof(m, t)
747 return self._xnamed(meter_text2)
749 @property_doc_(''' this point's reference frame (L{RefFrame}).''')
750 def reframe(self):
751 '''Get this point's reference frame (L{RefFrame}) or C{None}.
752 '''
753 return self._reframe
755 @reframe.setter # PYCHOK setter!
756 def reframe(self, reframe):
757 '''Set or clear this point's reference frame (L{RefFrame}) or C{None}.
759 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}.
760 '''
761 _set_reframe(self, reframe)
763 @Property_RO
764 def scale(self):
765 '''Get this point's UTM grid or UPS point scale factor (C{float})
766 or C{None} if not converted from L{Utm} or L{Ups}.
767 '''
768 return self._scale
770 def toCartesian(self, height=None, **Cartesian_and_kwds): # PYCHOK signature
771 '''Convert this point to cartesian, I{geocentric} coordinates,
772 also known as I{Earth-Centered, Earth-Fixed} (ECEF).
774 @see: Method L{toCartesian<latlonBase.LatLonBase.toCartesian>}
775 for further details.
776 '''
777 kwds = Cartesian_and_kwds
778 if kwds:
779 kwds = _xkwds(kwds, reframe=self.reframe, epoch=self.epoch)
780 return LatLonBase.toCartesian(self, height=height, **kwds)
782 def toCss(self, **toCss_kwds):
783 '''Convert this C{LatLon} point to a Cassini-Soldner location.
785 @kwarg toCss_kwds: Optional L{pygeodesy.toCss} keyword arguments.
787 @return: The Cassini-Soldner location (L{Css}).
789 @see: Function L{pygeodesy.toCss}.
790 '''
791 return _MODS.css.toCss(self, **self._name1__(toCss_kwds))
793 def toDatum(self, datum2, height=None, **name):
794 '''Convert this point to an other datum.
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 C{B{name}=NN} (C{str}).
801 @return: The converted point (this C{LatLon}) or a copy
802 of this point if B{C{datum2}} matches this
803 point's C{datum}.
805 @raise TypeError: Invalid B{C{datum2}}.
806 '''
807 n = self._name__(name)
808 d2 = _ellipsoidal_datum(datum2, name=n)
809 if self.datum == d2:
810 r = self.copy(name=n)
811 else:
812 kwds = _xkwds_not(None, LatLon=self.classof, name=n,
813 epoch=self.epoch, reframe=self.reframe)
814 c = self.toCartesian().toDatum(d2)
815 r = c.toLatLon(datum=d2, height=height, **kwds)
816 return r
818 def toEtm(self, **toEtm8_kwds):
819 '''Convert this C{LatLon} point to an ETM coordinate.
821 @kwarg toEtm8_kwds: Optional L{pygeodesy.toEtm8} keyword arguments.
823 @return: The ETM coordinate (L{Etm}).
825 @see: Function L{pygeodesy.toEtm8}.
826 '''
827 return _MODS.etm.toEtm8(self, **self._name1__(toEtm8_kwds)) if toEtm8_kwds else self._etm
829 def toLcc(self, **toLcc_kwds):
830 '''Convert this C{LatLon} point to a Lambert location.
832 @kwarg toLcc_kwds: Optional L{pygeodesy.toLcc} keyword arguments.
834 @return: The Lambert location (L{Lcc}).
836 @see: Function L{pygeodesy.toLcc}.
837 '''
838 return _MODS.lcc.toLcc(self, **self._name1__(toLcc_kwds))
840 def toMgrs(self, center=False, pole=NN):
841 '''Convert this C{LatLon} point to an MGRS coordinate.
843 @kwarg center: If C{True}, try to I{un}-center MGRS
844 to its C{lowerleft} (C{bool}) or by
845 C{B{center} meter} (C{scalar}).
846 @kwarg pole: Optional top/center for the MGRS UPS
847 projection (C{str}, 'N[orth]' or 'S[outh]').
849 @return: The MGRS coordinate (L{Mgrs}).
851 @see: Method L{toUtmUps} and L{Mgrs.toLatLon}.
852 '''
853 return self.toUtmUps(center=center, pole=pole).toMgrs(center=False)
855 def toOsgr(self, kTM=False, **toOsgr_kwds):
856 '''Convert this C{LatLon} point to an OSGR coordinate.
858 @kwarg kTM: If C{True}, use I{Karney}'s Krüger method from module
859 L{ktm}, otherwise I{Ordinance Survery}'s recommended
860 formulation (C{bool}).
861 @kwarg toOsgr_kwds: Optional L{pygeodesy.toOsgr} keyword arguments.
863 @return: The OSGR coordinate (L{Osgr}).
865 @see: Function L{pygeodesy.toOsgr}.
866 '''
867 return _MODS.osgr.toOsgr(self, kTM=kTM, **self._name1__(toOsgr_kwds))
869 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, height=None, **name):
870 '''Convert this point to an other reference frame and epoch.
872 @arg reframe2: Reference frame to convert I{to} (L{RefFrame}).
873 @kwarg reframe: Optional reference frame to convert I{from} (L{RefFrame}),
874 overriding this point's reference frame.
875 @kwarg epoch: Optional epoch (L{Epoch}, C{scalar} or C{str}), overriding
876 this point's C{epoch or B{reframe}.epoch}.
877 @kwarg epoch2: Optional epoch to observe for the converted point (L{Epoch},
878 C{scalar} or C{str}), otherwise B{C{epoch}}.
879 @kwarg height: Optional height, overriding the converted height (C{meter}).
880 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding C{B{reframe2}.name}.
882 @return: The converted point (ellipsoidal C{LatLon}) or if conversion
883 C{isunity}, this point or a copy of this point if the B{C{name}}
884 is non-empty.
886 @raise TRFError: This point's C{reframe} is not defined, invalid B{C{epoch}}
887 or B{C{epoch2}} or conversion from this point's C{reframe}
888 to B{C{reframe2}} is not available.
890 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a L{RefFrame}.
891 '''
892 return _MODS.trf._toRefFrame(self, reframe2, reframe=reframe, epoch=epoch,
893 epoch2=epoch2, height=height, **name)
895 def toTransform(self, transform, inverse=False, datum=None, **LatLon_kwds):
896 '''Apply a Helmert transform to this geodetic point.
898 @arg transform: Transform to apply (L{Transform} or L{TransformXform}).
899 @kwarg inverse: Apply the inverse of the Helmert transform (C{bool}).
900 @kwarg datum: Datum for the transformed point (L{Datum}), overriding
901 this point's datum but I{not} taken it into account.
902 @kwarg LatLon_kwds: Optional keyword arguments for the transformed
903 point, like C{B{height}=...}.
905 @return: A transformed point (C{LatLon}) or a copy of this point if
906 C{B{transform}.isunity}.
908 @raise TypeError: Invalid B{C{transform}}.
909 '''
910 _xinstanceof(Transform, transform=transform)
911 d = datum or self.datum
912 if transform.isunity:
913 r = self.dup(datum=d, **LatLon_kwds)
914 else:
915 c = self.toCartesian()
916 c = c.toTransform(transform, inverse=inverse, datum=d)
917 r = c.toLatLon(LatLon=self.classof, **_xkwds(LatLon_kwds, height=self.height))
918 return r
920 def toUps(self, pole=NN, falsed=True, center=False):
921 '''Convert this C{LatLon} point to a UPS coordinate.
923 @kwarg pole: Optional top/center of (stereographic)
924 projection (C{str}, 'N[orth]' or 'S[outh]').
925 @kwarg falsed: False easting and northing (C{bool}).
926 @kwarg center: If C{True}, I{un}-center the UPS to its
927 C{lowerleft} (C{bool}) or by C{B{center}
928 meter} (C{scalar}).
930 @return: The UPS coordinate (L{Ups}).
932 @see: Function L{pygeodesy.toUps8}.
933 '''
934 if self._upsOK(pole, falsed):
935 u = self._ups
936 else:
937 ups = _MODS.ups
938 u = ups.toUps8(self, datum=self.datum, Ups=ups.Ups,
939 pole=pole, falsed=falsed)
940 return _lowerleft(u, center)
942 def toUtm(self, center=False):
943 '''Convert this C{LatLon} point to a UTM coordinate.
945 @kwarg center: If C{True}, I{un}-center the UTM to its
946 C{lowerleft} (C{bool}) or by C{B{center}
947 meter} (C{scalar}).
949 @return: The UTM coordinate (L{Utm}).
951 @see: Method L{Mgrs.toUtm} and function L{pygeodesy.toUtm8}.
952 '''
953 return _lowerleft(self._utm, center)
955 def toUtmUps(self, pole=NN, center=False):
956 '''Convert this C{LatLon} point to a UTM or UPS coordinate.
958 @kwarg pole: Optional top/center of UPS (stereographic)
959 projection (C{str}, 'N[orth]' or 'S[outh]').
960 @kwarg center: If C{True}, I{un}-center the UTM or UPS to
961 its C{lowerleft} (C{bool}) or by C{B{center}
962 meter} (C{scalar}).
964 @return: The UTM or UPS coordinate (L{Utm} or L{Ups}).
966 @see: Function L{pygeodesy.toUtmUps8}.
967 '''
968 if self._utmOK():
969 u = self._utm
970 elif self._upsOK(pole):
971 u = self._ups
972 else: # no cover
973 utmups = _MODS.utmups
974 u = utmups.toUtmUps8(self, datum=self.datum, pole=pole, name=self.name,
975 Utm=utmups.Utm, Ups=utmups.Ups)
976 if isinstance(u, utmups.Utm):
977 self._update(False, _utm=u) # PYCHOK kwds
978 elif isinstance(u, utmups.Ups):
979 self._update(False, _ups=u) # PYCHOK kwds
980 else:
981 _xinstanceof(utmups.Utm, utmups.Ups, toUtmUps8=u)
982 return _lowerleft(u, center)
984 @deprecated_method
985 def to3xyz(self): # PYCHOK no cover
986 '''DEPRECATED, use method C{toEcef}.
988 @return: A L{Vector3Tuple}C{(x, y, z)}.
990 @note: Overloads C{LatLonBase.to3xyz}
991 '''
992 r = self.toEcef()
993 return _MODS.namedTuples.Vector3Tuple(r.x, r.y, r.z, name=self.name)
995 def triangulate(self, bearing1, other, bearing2, **height_wrap_tol):
996 '''I{Iteratively} locate a point given this, an other point and a bearing
997 from North at each point.
999 @arg bearing1: Bearing at this point (compass C{degrees360}).
1000 @arg other: The other point (C{LatLon}).
1001 @arg bearing2: Bearing at the B{C{other}} point (compass C{degrees360}).
1002 @kwarg height_wrap_tol: Optional keyword arguments C{B{height}=None},
1003 C{B{wrap}=False} and C{B{tol}}, see method L{intersection3
1004 <pygeodesy.ellipsoidalBase.LatLonEllipsoidalBase>}.
1006 @return: Triangulated point (C{LatLon}).
1008 @see: Method L{intersection3<pygeodesy.ellipsoidalBase.LatLonEllipsoidalBase>}
1009 for further details.
1010 '''
1011 if _isDegrees(bearing1) and _isDegrees(bearing2):
1012 r = self.intersection3(bearing1, other, bearing2, **height_wrap_tol)
1013 return r.point
1014 raise _TypeError(bearing1=bearing1, bearing2=bearing2 **height_wrap_tol)
1016 def trilaterate5(self, distance1, point2, distance2, point3, distance3,
1017 area=True, eps=EPS1, wrap=False):
1018 '''Trilaterate three points by I{area overlap} or I{perimeter intersection}
1019 of three intersecting circles.
1021 @arg distance1: Distance to this point (C{meter}), same units as B{C{eps}}).
1022 @arg point2: Second center point (C{LatLon}).
1023 @arg distance2: Distance to point2 (C{meter}, same units as B{C{eps}}).
1024 @arg point3: Third center point (C{LatLon}).
1025 @arg distance3: Distance to point3 (C{meter}, same units as B{C{eps}}).
1026 @kwarg area: If C{True}, compute the area overlap, otherwise the perimeter
1027 intersection of the circles (C{bool}).
1028 @kwarg eps: The required I{minimal overlap} for C{B{area}=True} or the
1029 I{intersection margin} for C{B{area}=False} (C{meter},
1030 conventionally).
1031 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{point2}}
1032 and B{C{point3}} (C{bool}).
1034 @return: A L{Trilaterate5Tuple}C{(min, minPoint, max, maxPoint, n)} with
1035 C{min} and C{max} in C{meter}, same units as B{C{eps}}, the
1036 corresponding trilaterated points C{minPoint} and C{maxPoint}
1037 as I{ellipsoidal} C{LatLon} and C{n}, the number of trilatered
1038 points found for the given B{C{eps}}.
1040 If only a single trilaterated point is found, C{min I{is} max},
1041 C{minPoint I{is} maxPoint} and C{n=1}.
1043 If C{B{area}=False}, C{min} and C{max} represent the nearest
1044 respectively farthest intersection margin.
1046 If C{B{area}=True}, C{min} and C{max} are the smallest respectively
1047 largest I{radial} overlap found.
1049 If C{B{area}=True} and all 3 circles are concentric, C{n=0} and
1050 C{minPoint} and C{maxPoint} are the B{C{point#}} with the smallest
1051 B{C{distance#}} C{min} respectively largest B{C{distance#}} C{max}.
1053 @raise IntersectionError: Trilateration failed for the given B{C{eps}},
1054 insufficient overlap for C{B{area}=True}, no
1055 circle intersections for C{B{area}=False} or
1056 all circles are (near-)concentric.
1058 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.
1060 @raise ValueError: Coincident B{C{points}} or invalid B{C{distance1}},
1061 B{C{distance2}} or B{C{distance3}}.
1063 @note: Ellipsoidal trilateration invokes methods C{LatLon.intersections2}
1064 and C{LatLon.nearestOn} based on I{Karney}'s Python U{geographiclib
1065 <https://PyPI.org/project/geographiclib>} if installed, otherwise
1066 the accurate (but slower) C{ellipsoidalExact.LatLon} methods.
1067 '''
1068 return _trilaterate5(self, distance1,
1069 self.others(point2=point2), distance2,
1070 self.others(point3=point3), distance3,
1071 area=area, eps=eps, wrap=wrap)
1073 @Property_RO
1074 def _ups(self): # __dict__ value overwritten by method C{toUtmUps}
1075 '''(INTERNAL) Get this C{LatLon} point as UPS coordinate (L{Ups}),
1076 see L{pygeodesy.toUps8}.
1077 '''
1078 ups = _MODS.ups
1079 return ups.toUps8(self, datum=self.datum, Ups=ups.Ups,
1080 pole=NN, falsed=True, name=self.name)
1082 def _upsOK(self, pole=NN, falsed=True):
1083 '''(INTERNAL) Check matching C{Ups}.
1084 '''
1085 try:
1086 u = self._ups
1087 except RangeError:
1088 return False
1089 return falsed and (u.pole == pole[:1].upper() or not pole)
1091 @Property_RO
1092 def _utm(self): # __dict__ value overwritten by method C{toUtmUps}
1093 '''(INTERNAL) Get this C{LatLon} point as UTM coordinate (L{Utm}),
1094 see L{pygeodesy.toUtm8}.
1095 '''
1096 utm = _MODS.utm
1097 return utm.toUtm8(self, datum=self.datum, Utm=utm.Utm, name=self.name)
1099 def _utmOK(self):
1100 '''(INTERNAL) Check C{Utm}.
1101 '''
1102 try:
1103 _ = self._utm
1104 except RangeError:
1105 return False
1106 return True
1109def _lowerleft(utmups, center):
1110 '''(INTERNAL) Optionally I{un}-center C{utmups}.
1111 '''
1112 if center in (False, 0, _0_0):
1113 u = utmups
1114 elif center in (True,):
1115 u = utmups._lowerleft
1116 else:
1117 u = _MODS.utmupsBase._lowerleft(utmups, center)
1118 return u
1121def _nearestOn(point, point1, point2, within=True, height=None, wrap=False, # was=True
1122 equidistant=None, tol=_TOL_M, **LatLon_and_kwds):
1123 '''(INTERNAL) Get closest point, imported by .ellipsoidalExact,
1124 -GeodSolve, -Karney and -Vincenty to embellish exceptions.
1125 '''
1126 try:
1127 p = _xellipsoidal(point=point)
1128 t = _MODS.ellipsoidalBaseDI._nearestOn2(p, point1, point2, within=within,
1129 height=height, wrap=wrap,
1130 equidistant=equidistant,
1131 tol=tol, **LatLon_and_kwds)
1132 except (TypeError, ValueError) as x:
1133 raise _xError(x, point=point, point1=point1, point2=point2)
1134 return t.closest
1137def _set_reframe(inst, reframe):
1138 '''(INTERNAL) Set or clear an instance's reference frame.
1139 '''
1140 if reframe is not None:
1141 _xinstanceof(_MODS.trf.RefFrame, reframe=reframe)
1142 inst._reframe = reframe
1143 elif inst.reframe is not None:
1144 inst._reframe = None
1147__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)
1149# **) MIT License
1150#
1151# Copyright (C) 2016-2025 -- mrJean1 at Gmail -- All Rights Reserved.
1152#
1153# Permission is hereby granted, free of charge, to any person obtaining a
1154# copy of this software and associated documentation files (the "Software"),
1155# to deal in the Software without restriction, including without limitation
1156# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1157# and/or sell copies of the Software, and to permit persons to whom the
1158# Software is furnished to do so, subject to the following conditions:
1159#
1160# The above copyright notice and this permission notice shall be included
1161# in all copies or substantial portions of the Software.
1162#
1163# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1164# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1165# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1166# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1167# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1168# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1169# OTHER DEALINGS IN THE SOFTWARE.