Coverage for pygeodesy/ellipsoidalBase.py: 94%
260 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-09-09 13:03 -0400
« prev ^ index » next coverage.py v7.6.1, created at 2025-09-09 13:03 -0400
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 _ # noqa: E702 ;
15# from pygeodesy.azimuthal import EquidistantExact, EquidistantKarney # _MODS
16from pygeodesy.basics import _isin, _xinstanceof
17from pygeodesy.constants import EPS, EPS0, EPS1, _0_0, _0_5
18from pygeodesy.cartesianBase import CartesianBase # PYCHOK used!
19# from pygeodesy.css import toCss # _MODS
20from pygeodesy.datums import Datum, Datums, _earth_ellipsoid, _ellipsoidal_datum, \
21 Transform, _WGS84, _EWGS84 # _spherical_datum
22# from pygeodesy.dms import parse3llh # _MODS
23# from pygeodesy.elevations import elevation2, geoidHeight2 # _MODS
24# from pygeodesy.ellipsoidalBaseDI import _intersect3, _intersections2, _nearestOn2 # _MODS
25# from pygeodesy.ellipsoids import _EWGS84 # from .datums
26from pygeodesy.errors import _IsnotError, RangeError, _TypeError, _xattr, _xellipsoidal, \
27 _xellipsoids, _xError, _xkwds, _xkwds_not
28# from pygeodesy.etm import etm, toEtm8 # _MODS
29# from pygeodesy.fmath import favg # _MODS
30from pygeodesy.interns import NN, _COMMA_, _ellipsoidal_
31from pygeodesy.latlonBase import LatLonBase, _trilaterate5, fabs, _Wrap
32from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS
33# from pygeodesy.lcc import toLcc # _MODS
34# from pygeodesy.namedTuples import Vector3Tuple # _MODS
35# from pygeodesy.osgr import toOsgr # _MODS
36# from pygeodesy.points import isenclosedBy # _MODS
37from pygeodesy.props import deprecated_method, deprecated_property_RO, \
38 Property_RO, property_doc_, property_RO, _update_all
39# from pygeodesy.trf import RefFrame, _toRefFrame # _MODS
40from pygeodesy.units import Epoch, _isDegrees, Radius_, _1mm as _TOL_M
41# from pygeodesy import ups, utm, utmups # MODS
42# from pygeodesy.utmupsBase import _lowerleft # MODS
43# from pygeodesy.utily import _Wrap # from .latlonBase
44# from pygeodesy.vector3d import _intersects2 # _MODS
46# from math import fabs # from .latlonBase
48__all__ = _ALL_LAZY.ellipsoidalBase
49__version__ = '25.07.21'
52class CartesianEllipsoidalBase(CartesianBase):
53 '''(INTERNAL) Base class for ellipsoidal C{Cartesian}s.
54 '''
55 _datum = _WGS84 # L{Datum}
56 _epoch = None # overriding .reframe.epoch (C{float})
57 _reframe = None # reference frame (L{RefFrame})
59 def __init__(self, x_xyz, y=None, z=None, reframe=None, epoch=None,
60 **datum_ll_name):
61 '''New ellispoidal C{Cartesian...}.
63 @kwarg reframe: Optional reference frame (L{RefFrame}).
64 @kwarg epoch: Optional epoch to observe for B{C{reframe}} (C{scalar}),
65 a non-zero, fractional calendar year; silently ignored
66 if C{B{reframe}=None}.
68 @raise TypeError: Non-scalar B{C{x_xyz}}, B{C{y}} or B{C{z}} coordinate
69 or B{C{x_xyz}} not a C{Cartesian} L{Ecef9Tuple},
70 L{Vector3Tuple} or L{Vector4Tuple} or B{C{datum}} is
71 not a L{Datum}, B{C{reframe}} is not a L{RefFrame} or
72 B{C{epoch}} is not C{scalar} non-zero.
74 @see: Class L{CartesianBase<CartesianBase.__init__>} for more details.
75 '''
76 CartesianBase.__init__(self, x_xyz, y=y, z=z, **datum_ll_name)
77 if reframe:
78 self.reframe = reframe
79 self.epoch = epoch
81# def __matmul__(self, other): # PYCHOK Python 3.5+
82# '''Return C{NotImplemented} for C{c_ = c @ datum}, C{c_ = c @ reframe} and C{c_ = c @ Transform}.
83# '''
84# RefFrame = _MODS.trf.RefFrame
85# return NotImplemented if isinstance(other, (Datum, RefFrame, Transform)) else \
86# _NotImplemented(self, other)
88 @deprecated_method
89 def convertRefFrame(self, reframe2, reframe, epoch=None):
90 '''DEPRECATED, use method L{toRefFrame}.'''
91 return self.toRefFrame(reframe2, reframe=reframe, epoch=epoch) # PYCHOK no cover
93 @property_RO
94 def ellipsoidalCartesian(self):
95 '''Get this C{Cartesian}'s ellipsoidal class.
96 '''
97 return type(self)
99 @property_doc_(''' this cartesian's observed or C{reframe} epoch (C{float}).''')
100 def epoch(self):
101 '''Get this cartesian's observed or C{reframe} epoch (C{Epoch}) or C{None}.
102 '''
103 return self._epoch or (self.reframe.epoch if self.reframe else None)
105 @epoch.setter # PYCHOK setter!
106 def epoch(self, epoch):
107 '''Set or clear this cartesian's observed epoch, a fractional
108 calendar year (L{Epoch}, C{scalar} or C{str}) or C{None}.
110 @raise TRFError: Invalid B{C{epoch}}.
111 '''
112 self._epoch = None if epoch is None else Epoch(epoch)
114 def intersections2(self, radius, center2, radius2, sphere=True,
115 Vector=None, **Vector_kwds):
116 '''Compute the intersection of two spheres or circles, each defined by a
117 cartesian center point and a radius.
119 @arg radius: Radius of this sphere or circle (same units as this point's
120 coordinates).
121 @arg center2: Center of the second sphere or circle (C{Cartesian}, L{Vector3d},
122 C{Vector3Tuple} or C{Vector4Tuple}).
123 @arg radius2: Radius of the second sphere or circle (same units as this and
124 the B{C{other}} point's coordinates).
125 @kwarg sphere: If C{True}, compute the center and radius of the intersection
126 of two I{spheres}. If C{False}, ignore the C{z}-component and
127 compute the intersection of two I{circles} (C{bool}).
128 @kwarg Vector: Class to return intersections (C{Cartesian}, L{Vector3d} or
129 C{Vector3Tuple}) or C{None} for an instance of this (sub-)class.
130 @kwarg Vector_kwds: Optional, additional B{C{Vector}} keyword arguments,
131 ignored if C{B{Vector} is None}.
133 @return: If C{B{sphere} is True}, a 2-tuple of the C{center} and C{radius} of
134 the intersection of the I{spheres}. The C{radius} is C{0.0} for
135 abutting spheres (and the C{center} is aka the I{radical center}).
137 If C{B{sphere} is False}, a 2-tuple with the two intersection points
138 of the I{circles}. For abutting circles, both points are the same
139 instance (aka the I{radical center}).
141 @raise IntersectionError: Concentric, invalid or non-intersecting spheres or circles.
143 @raise TypeError: Invalid B{C{center2}}.
145 @raise UnitError: Invalid B{C{radius}} or B{C{radius2}}.
147 @see: U{Sphere-Sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>},
148 U{Circle-Circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>}
149 Intersection and function L{pygeodesy.radical2}.
150 '''
151 try:
152 return _MODS.vector3d._intersects2(self, Radius_(radius=radius),
153 center2, Radius_(radius2=radius2),
154 sphere=sphere, clas=self.classof,
155 Vector=Vector, **Vector_kwds)
156 except (TypeError, ValueError) as x:
157 raise _xError(x, center=self, radius=radius, center2=center2, radius2=radius2)
159 @property_doc_(''' this cartesian's reference frame (L{RefFrame}).''')
160 def reframe(self):
161 '''Get this cartesian's reference frame (L{RefFrame}) or C{None}.
162 '''
163 return self._reframe
165 @reframe.setter # PYCHOK setter!
166 def reframe(self, reframe):
167 '''Set or clear this cartesian's reference frame (L{RefFrame}) or C{None}.
169 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}.
170 '''
171 _set_reframe(self, reframe)
173 def toLatLon(self, datum=None, height=None, **LatLon_and_kwds): # PYCHOK signature
174 '''Convert this cartesian to a I{geodetic} (lat-/longitude) point.
176 @see: Method L{toLatLon<cartesianBase.CartesianBase.toLatLon>}
177 for further details.
178 '''
179 kwds = LatLon_and_kwds
180 if kwds:
181 kwds = _xkwds(kwds, reframe=self.reframe, epoch=self.epoch)
182 return CartesianBase.toLatLon(self, datum=datum, height=height, **kwds)
184 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, **name):
185 '''Convert this point to an other reference frame and epoch.
187 @arg reframe2: Reference frame to convert I{to} (L{RefFrame}).
188 @kwarg reframe: Optional reference frame to convert I{from} (L{RefFrame}),
189 overriding this point's reference frame.
190 @kwarg epoch: Optional epoch (L{Epoch}, C{scalar} or C{str}), overriding
191 this point's C{epoch or B{reframe}.epoch}.
192 @kwarg epoch2: Optional epoch to observe for the converted point (L{Epoch},
193 C{scalar} or C{str}), otherwise B{C{epoch}}.
194 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding C{B{reframe2}.name}.
196 @return: The converted point (ellipsoidal C{Cartesian}) or if conversion
197 C{isunity}, this point or a copy of this point if the B{C{name}}
198 is non-empty.
200 @raise TRFError: This point's C{reframe} is not defined, invalid B{C{epoch}}
201 or B{C{epoch2}} or conversion from this point's C{reframe}
202 to B{C{reframe2}} is not available.
204 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a L{RefFrame}.
205 '''
206 return _MODS.trf._toRefFrame(self, reframe2, reframe=reframe, epoch=epoch,
207 epoch2=epoch2, **name)
209 @deprecated_method
210 def toTransforms_(self, *transforms, **datum): # PYCHOK no cover
211 '''DEPRECATED on 2024.02.14, use method C{toTransform}.'''
212 r = self
213 for t in transforms:
214 r = r.toTransform(t)
215 return r.dup(**datum) if datum else r
218class LatLonEllipsoidalBase(LatLonBase):
219 '''(INTERNAL) Base class for ellipsoidal C{LatLon}s.
220 '''
221 _datum = _WGS84 # L{Datum}
222 _elevation2to = None # _elevation2 timeout (C{secs})
223 _epoch = None # overriding .reframe.epoch (C{float})
224 _gamma = None # UTM/UPS meridian convergence (C{degrees})
225 _geoidHeight2to = None # _geoidHeight2 timeout (C{secs})
226 _reframe = None # reference frame (L{RefFrame})
227 _scale = None # UTM/UPS scale factor (C{float})
228 _toLLEB_args = () # Etm/Utm/Ups._toLLEB arguments
230 def __init__(self, latlonh, lon=None, height=0, datum=_WGS84, reframe=None,
231 epoch=None, wrap=False, **name):
232 '''Create an ellipsoidal C{LatLon} point from the given lat-, longitude
233 and height on the given datum, reference frame and epoch.
235 @arg latlonh: Latitude (C{degrees} or DMS C{str} with N or S suffix) or
236 a previous C{LatLon} instance provided C{B{lon}=None}.
237 @kwarg lon: Longitude (C{degrees} or DMS C{str} with E or W suffix) or C(None),
238 indicating B{C{latlonh}} is a C{LatLon}.
239 @kwarg height: Optional height above (or below) the earth surface (C{meter},
240 same units as the datum's ellipsoid axes).
241 @kwarg datum: Optional, ellipsoidal datum to use (L{Datum}, L{Ellipsoid},
242 L{Ellipsoid2} or L{a_f2Tuple}).
243 @kwarg reframe: Optional reference frame (L{RefFrame}).
244 @kwarg epoch: Optional epoch to observe for B{C{reframe}} (C{scalar}), a
245 non-zero, fractional calendar year, but silently ignored if
246 C{B{reframe}=None}.
247 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{lat}} and B{C{lon}} (C{bool}).
248 @kwarg name: Optional C{B{name}=NN} (C{str}).
250 @raise RangeError: Value of C{lat} or B{C{lon}} outside the valid range and
251 L{rangerrors} set to C{True}.
253 @raise TypeError: If B{C{latlonh}} is not a C{LatLon}, B{C{datum}} is not a
254 L{Datum}, B{C{reframe}} is not a L{RefFrame} or B{C{epoch}}
255 is not C{scalar} non-zero.
257 @raise UnitError: Invalid B{C{lat}}, B{C{lon}} or B{C{height}}.
258 '''
259 LatLonBase.__init__(self, latlonh, lon=lon, height=height, wrap=wrap, **name)
260 if not _isin(datum, None, self._datum, _EWGS84):
261 self.datum = _ellipsoidal_datum(datum, name=self.name)
262 if reframe:
263 self.reframe = reframe
264 self.epoch = epoch
266# def __matmul__(self, other): # PYCHOK Python 3.5+
267# '''Return C{NotImplemented} for C{ll_ = ll @ datum} and C{ll_ = ll @ reframe}.
268# '''
269# RefFrame = _MODS.trf.RefFrame
270# return NotImplemented if isinstance(other, (Datum, RefFrame)) else \
271# _NotImplemented(self, other)
273 def antipode(self, height=None):
274 '''Return the antipode, the point diametrically opposite
275 to this point.
277 @kwarg height: Optional height of the antipode, height
278 of this point otherwise (C{meter}).
280 @return: The antipodal point (C{LatLon}).
281 '''
282 lla = LatLonBase.antipode(self, height=height)
283 if lla.datum != self.datum:
284 lla.datum = self.datum
285 return lla
287 @deprecated_property_RO
288 def convergence(self):
289 '''DEPRECATED, use property C{gamma}.'''
290 return self.gamma # PYCHOK no cover
292 @deprecated_method
293 def convertDatum(self, datum2):
294 '''DEPRECATED, use method L{toDatum}.'''
295 return self.toDatum(datum2)
297 @deprecated_method
298 def convertRefFrame(self, reframe2):
299 '''DEPRECATED, use method L{toRefFrame}.'''
300 return self.toRefFrame(reframe2)
302 @property_doc_(''' this points's datum (L{Datum}).''')
303 def datum(self):
304 '''Get this point's datum (L{Datum}).
305 '''
306 return self._datum
308 @datum.setter # PYCHOK setter!
309 def datum(self, datum):
310 '''Set this point's datum I{without conversion} (L{Datum}).
312 @raise TypeError: The B{C{datum}} is not a L{Datum} or not ellipsoidal.
313 '''
314 _xinstanceof(Datum, datum=datum)
315 if not datum.isEllipsoidal:
316 raise _IsnotError(_ellipsoidal_, datum=datum)
317 if self._datum != datum:
318 _update_all(self)
319 self._datum = datum
321 def distanceTo2(self, other, wrap=False):
322 '''I{Approximate} the distance and (initial) bearing between this
323 and an other (ellipsoidal) point based on the radii of curvature.
325 I{Suitable only for short distances up to a few hundred Km
326 or Miles and only between points not near-polar}.
328 @arg other: The other point (C{LatLon}).
329 @kwarg wrap: If C{True}, wrap or I{normalize} the B{C{other}}
330 point (C{bool}).
332 @return: An L{Distance2Tuple}C{(distance, initial)}.
334 @raise TypeError: The B{C{other}} point is not C{LatLon}.
336 @raise ValueError: Incompatible datum ellipsoids.
338 @see: Method L{Ellipsoid.distance2} and U{Local, flat earth
339 approximation<https://www.EdWilliams.org/avform.htm#flat>}
340 aka U{Hubeny<https://www.OVG.AT/de/vgi/files/pdf/3781/>}
341 formula.
342 '''
343 p = self.others(other)
344 if wrap: # PYCHOK no cover
345 p = _Wrap.point(p)
346 E = self.ellipsoids(other)
347 return E.distance2(*(self.latlon + p.latlon))
349 @Property_RO
350 def _elevation2(self):
351 '''(INTERNAL) Get elevation and data source.
352 '''
353 return _MODS.elevations.elevation2(self.lat, self.lon,
354 timeout=self._elevation2to)
356 def elevation2(self, adjust=True, datum=None, timeout=2):
357 '''Return elevation of this point for its or the given datum, ellipsoid
358 or sphere.
360 @kwarg adjust: Adjust the elevation for a B{C{datum}} other than
361 C{NAD83} (C{bool}).
362 @kwarg datum: Optional datum overriding this point's datum (L{Datum},
363 L{Ellipsoid}, L{Ellipsoid2}, L{a_f2Tuple} or C{scalar}
364 radius).
365 @kwarg timeout: Optional query timeout (C{seconds}).
367 @return: An L{Elevation2Tuple}C{(elevation, data_source)} or
368 C{(None, error)} in case of errors.
370 @note: The adjustment applied is the difference in geocentric earth
371 radius between the B{C{datum}} and C{NAV83} upon which the
372 L{elevations.elevation2} is based.
374 @note: NED elevation is only available for locations within the U{Conterminous
375 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}.
377 @see: Function L{elevations.elevation2} and method C{Ellipsoid.Rgeocentric}
378 for further details and possible C{error}s.
379 '''
380 if self._elevation2to != timeout:
381 self._elevation2to = timeout
382 LatLonEllipsoidalBase._elevation2._update(self)
383 return self._Radjust2(adjust, datum, self._elevation2)
385 def ellipsoid(self, datum=_WGS84):
386 '''Return the ellipsoid of this point's datum or the given datum.
388 @kwarg datum: Default datum (L{Datum}).
390 @return: The ellipsoid (L{Ellipsoid} or L{Ellipsoid2}).
391 '''
392 return _xattr(self, datum=datum).ellipsoid
394 @property_RO
395 def ellipsoidalLatLon(self):
396 '''Get this C{LatLon}'s ellipsoidal class.
397 '''
398 return type(self)
400 def ellipsoids(self, other):
401 '''Check the type and ellipsoid of this and an other point's datum.
403 @arg other: The other point (C{LatLon}).
405 @return: This point's datum ellipsoid (L{Ellipsoid} or L{Ellipsoid2}).
407 @raise TypeError: The B{C{other}} point is not C{LatLon}.
409 @raise ValueError: Incompatible datum ellipsoids.
410 '''
411 self.others(other, up=2) # ellipsoids' caller
413 E = self.ellipsoid()
414 try: # other may be Sphere, etc.
415 e = other.ellipsoid()
416 except AttributeError:
417 try: # no ellipsoid method, try datum
418 e = other.datum.ellipsoid
419 except AttributeError:
420 e = E # no datum, XXX assume equivalent?
421 return _xellipsoids(E, e)
423 @property_doc_(''' this point's observed or C{reframe} epoch (C{float}).''')
424 def epoch(self):
425 '''Get this point's observed or C{reframe} epoch (L{Epoch}) or C{None}.
426 '''
427 return self._epoch or (self.reframe.epoch if self.reframe else None)
429 @epoch.setter # PYCHOK setter!
430 def epoch(self, epoch):
431 '''Set or clear this point's observed epoch, a fractional
432 calendar year (L{Epoch}, C{scalar} or C{str}) or C{None}.
434 @raise TRFError: Invalid B{C{epoch}}.
435 '''
436 self._epoch = None if epoch is None else Epoch(epoch)
438 @Property_RO
439 def Equidistant(self):
440 '''Get the prefered azimuthal equidistant projection I{class} (L{EquidistantKarney} or L{EquidistantExact}).
441 '''
442 try:
443 _ = self.datum.ellipsoid.geodesic
444 return _MODS.azimuthal.EquidistantKarney
445 except ImportError: # no geographiclib
446 return _MODS.azimuthal.EquidistantExact # XXX no longer L{azimuthal.Equidistant}
448 @Property_RO
449 def _etm(self):
450 '''(INTERNAL) Get this C{LatLon} point as an ETM coordinate (L{pygeodesy.toEtm8}).
451 '''
452 return self._toX8(_MODS.etm.toEtm8)
454 @property_RO
455 def gamma(self):
456 '''Get this point's UTM or UPS meridian convergence (C{degrees}) or
457 C{None} if not available or not converted from L{Utm} or L{Ups}.
458 '''
459 return self._gamma
461 @Property_RO
462 def _geoidHeight2(self):
463 '''(INTERNAL) Get geoid height and model.
464 '''
465 return _MODS.elevations.geoidHeight2(self.lat, self.lon, model=0,
466 timeout=self._geoidHeight2to)
468 def geoidHeight2(self, adjust=False, datum=None, timeout=2):
469 '''Return geoid height of this point for its or the given datum, ellipsoid
470 or sphere.
472 @kwarg adjust: Adjust the geoid height for a B{C{datum}} other than
473 C{NAD83/NADV88} (C{bool}).
474 @kwarg datum: Optional datum overriding this point's datum (L{Datum},
475 L{Ellipsoid}, L{Ellipsoid2}, L{a_f2Tuple} or C{scalar}
476 radius).
477 @kwarg timeout: Optional query timeout (C{seconds}).
479 @return: A L{GeoidHeight2Tuple}C{(height, model_name)} or
480 C{(None, error)} in case of errors.
482 @note: The adjustment applied is the difference in geocentric earth
483 radius between the B{C{datum}} and C{NAV83/NADV88} upon which
484 the L{elevations.geoidHeight2} is based.
486 @note: The geoid height is only available for locations within the U{Conterminous
487 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}.
489 @see: Function L{elevations.geoidHeight2} and method C{Ellipsoid.Rgeocentric}
490 for further details and possible C{error}s.
491 '''
492 if self._geoidHeight2to != timeout:
493 self._geoidHeight2to = timeout
494 LatLonEllipsoidalBase._geoidHeight2._update(self)
495 return self._Radjust2(adjust, datum, self._geoidHeight2)
497 def intermediateTo(self, other, fraction, height=None, wrap=False): # PYCHOK no cover
498 '''I{Must be overloaded}.'''
499 self._notOverloaded(other, fraction, height=height, wrap=wrap)
501 def intersection3(self, end1, start2, end2, height=None, wrap=False, # was=True
502 equidistant=None, tol=_TOL_M):
503 '''I{Iteratively} compute the intersection point of two geodesic lines, each
504 given as two points or as a start point and a bearing from North.
506 @arg end1: End point of this line (C{LatLon}) or the initial bearing at
507 this point (compass C{degrees360}).
508 @arg start2: Start point of the second line (this C{LatLon}).
509 @arg end2: End point of the second line (this C{LatLon}) or the initial
510 bearing at B{C{start2}} (compass C{degrees360}).
511 @kwarg height: Optional height at the intersection (C{meter}, conventionally)
512 or C{None} for the mean height.
513 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{start2}} and
514 both B{C{end*}} points (C{bool}).
515 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function
516 L{pygeodesy.equidistant}), or C{None} for this point's
517 preferred C{.Equidistant}.
518 @kwarg tol: Tolerance for convergence and skew line distance and length
519 (C{meter}, conventionally).
521 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)} with C{point}
522 a C{LatLon} instance.
524 @raise ImportError: Package U{geographiclib
525 <https://PyPI.org/project/geographiclib>}
526 not installed or not found, but only if
527 C{B{equidistant}=}L{EquidistantKarney}.
529 @raise IntersectionError: Skew, colinear, parallel or otherwise non-intersecting
530 lines or no convergence for the given B{C{tol}}.
532 @raise TypeError: Invalid B{C{end1}}, B{C{start2}} or B{C{end2}}.
534 @note: For each line specified with an initial bearing, a pseudo-end point is
535 computed as the C{destination} along that bearing at about 1.5 times the
536 distance from the start point to an initial gu-/estimate of the intersection
537 point (and between 1/8 and 3/8 of the C{authalic} earth perimeter).
539 @see: I{Karney's} U{intersect.cpp<https://SourceForge.net/p/geographiclib/
540 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https://
541 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>}
542 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section
543 B{14. MARITIME BOUNDARIES} for more details about the iteration algorithm.
544 '''
545 try:
546 s2 = self.others(start2=start2)
547 return _MODS.ellipsoidalBaseDI._intersect3(self, end1,
548 s2, end2,
549 height=height, wrap=wrap,
550 equidistant=equidistant, tol=tol,
551 LatLon=self.classof, datum=self.datum)
552 except (TypeError, ValueError) as x:
553 raise _xError(x, start1=self, end1=end1, start2=start2, end2=end2,
554 height=height, wrap=wrap, tol=tol)
556 def intersections2(self, radius1, center2, radius2, height=None, wrap=False, # was=True
557 equidistant=None, tol=_TOL_M):
558 '''I{Iteratively} compute the intersection points of two circles, each
559 defined by a center point and a radius.
561 @arg radius1: Radius of this circle (C{meter}, conventionally).
562 @arg center2: Center of the other circle (this C{LatLon}).
563 @arg radius2: Radius of the other circle (C{meter}, same units as
564 B{C{radius1}}).
565 @kwarg height: Optional height for the intersection points (C{meter},
566 conventionally) or C{None} for the I{"radical height"}
567 at the I{radical line} between both centers.
568 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{center2}}
569 (C{bool}).
570 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
571 function L{pygeodesy.equidistant}) or C{None}
572 for this point's preferred C{.Equidistant}.
573 @kwarg tol: Convergence tolerance (C{meter}, same units as
574 B{C{radius1}} and B{C{radius2}}).
576 @return: 2-Tuple of the intersection points, each a C{LatLon}
577 instance. For abutting circles, both intersection
578 points are the same instance, aka the I{radical center}.
580 @raise ImportError: Package U{geographiclib
581 <https://PyPI.org/project/geographiclib>}
582 not installed or not found, but only if
583 C{B{equidistant}=}L{EquidistantKarney}.
585 @raise IntersectionError: Concentric, antipodal, invalid or
586 non-intersecting circles or no
587 convergence for the given B{C{tol}}.
589 @raise TypeError: Invalid B{C{center2}} or B{C{equidistant}}.
591 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.
593 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
594 calculating-intersection-of-two-circles>}, U{Karney's paper
595 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},
596 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and
597 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}
598 intersections.
599 '''
600 try:
601 c2 = self.others(center2=center2)
602 return _MODS.ellipsoidalBaseDI._intersections2(self, radius1,
603 c2, radius2,
604 height=height, wrap=wrap,
605 equidistant=equidistant, tol=tol,
606 LatLon=self.classof, datum=self.datum)
607 except (AssertionError, TypeError, ValueError) as x:
608 raise _xError(x, center=self, radius1=radius1, center2=center2, radius2=radius2,
609 height=height, wrap=wrap, tol=tol)
611 def isenclosedBy(self, points, wrap=False):
612 '''Check whether a polygon or composite encloses this point.
614 @arg points: The polygon points or clips (C{LatLon}[],
615 L{BooleanFHP} or L{BooleanGH}).
616 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
617 B{C{points}} (C{bool}).
619 @return: C{True} if this point is inside the polygon or composite,
620 C{False} otherwise.
622 @raise PointsError: Insufficient number of B{C{points}}.
624 @raise TypeError: Some B{C{points}} are not C{LatLon}.
626 @raise ValueError: Invalid B{C{point}}, lat- or longitude.
628 @see: Functions L{pygeodesy.isconvex}, L{pygeodesy.isenclosedBy}
629 and L{pygeodesy.ispolar} especially if the B{C{points}} may
630 enclose a pole or wrap around the earth I{longitudinally}.
631 '''
632 return _MODS.points.isenclosedBy(self, points, wrap=wrap)
634 @property_RO
635 def iteration(self):
636 '''Get the most recent C{intersections2} or C{nearestOn} iteration
637 number (C{int}) or C{None} if not available/applicable.
638 '''
639 return self._iteration
641 def midpointTo(self, other, height=None, fraction=_0_5, wrap=False):
642 '''Find the midpoint on a geodesic between this and an other point.
644 @arg other: The other point (C{LatLon}).
645 @kwarg height: Optional height for midpoint, overriding the
646 mean height (C{meter}).
647 @kwarg fraction: Midpoint location from this point (C{scalar}),
648 may be negative or greater than 1.0.
649 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
650 B{C{other}} point (C{bool}).
652 @return: Midpoint (C{LatLon}).
654 @raise TypeError: The B{C{other}} point is not C{LatLon}.
656 @raise ValueError: Invalid B{C{height}}.
658 @see: Methods C{intermediateTo} and C{rhumbMidpointTo}.
659 '''
660 return self.intermediateTo(other, fraction, height=height, wrap=wrap)
662 def nearestOn(self, point1, point2, within=True, height=None, wrap=False, # was=True
663 equidistant=None, tol=_TOL_M):
664 '''I{Iteratively} locate the closest point on the geodesic (line)
665 between two other (ellipsoidal) points.
667 @arg point1: Start point of the geodesic (C{LatLon}).
668 @arg point2: End point of the geodesic (C{LatLon}).
669 @kwarg within: If C{True}, return the closest point I{between} B{C{point1}} and
670 B{C{point2}}, otherwise the closest point elsewhere on the geodesic
671 (C{bool}).
672 @kwarg height: Optional height for the closest point (C{meter}, conventionally)
673 or C{None} or C{False} for the interpolated height. If C{False},
674 the closest takes the heights of the points into account.
675 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both B{C{point1}} and
676 B{C{point2}} (C{bool}).
677 @kwarg equidistant: An azimuthal equidistant projection (I{class} or function
678 L{pygeodesy.equidistant}) or C{None} for this point's
679 preferred C{Equidistant}, like L{Equidistant}.
680 @kwarg tol: Convergence tolerance (C{meter}, conventionally).
682 @return: Closest point (C{LatLon}).
684 @raise ImportError: Package U{geographiclib
685 <https://PyPI.org/project/geographiclib>}
686 not installed or not found, but only if
687 C{B{equidistant}=}L{EquidistantKarney}.
689 @raise TypeError: Invalid B{C{point1}}, B{C{point2}} or B{C{equidistant}}.
691 @raise ValueError: Datum or ellipsoid of B{C{point1}} or B{C{point2}} is incompatible
692 or no convergence for the given B{C{tol}}.
694 @see: I{Karney}'s U{intercept.cpp<https://SourceForge.net/p/geographiclib/
695 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https://
696 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>}
697 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section
698 B{14. MARITIME BOUNDARIES} for details about the iteration algorithm.
699 '''
700 try:
701 t = _MODS.ellipsoidalBaseDI._nearestOn2(self, point1, point2, within=within,
702 height=height, wrap=wrap,
703 equidistant=equidistant,
704 tol=tol, LatLon=self.classof)
705 except (TypeError, ValueError) as x:
706 raise _xError(x, point=self, point1=point1, point2=point2, within=within,
707 height=height, wrap=wrap, tol=tol)
708 return t.closest
710 def parse(self, strllh, height=0, datum=None, epoch=None, reframe=None,
711 sep=_COMMA_, wrap=False, **name):
712 '''Parse a string consisting of C{"lat, lon[, height]"},
713 representing a similar, ellipsoidal C{LatLon} point.
715 @arg strllh: Lat, lon and optional height (C{str}), see function
716 L{pygeodesy.parse3llh}.
717 @kwarg height: Optional, default height (C{meter} or C{None}).
718 @kwarg datum: Optional datum (L{Datum}), overriding this datum
719 I{without conversion}.
720 @kwarg epoch: Optional datum (L{Epoch}), overriding this epoch
721 I{without conversion}.
722 @kwarg reframe: Optional reference frame (L{RefFrame}), overriding
723 this reframe I{without conversion}.
724 @kwarg sep: Optional separator (C{str}).
725 @kwarg wrap: If C{True}, wrap or I{normalize} the lat- and
726 longitude (C{bool}).
727 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding this name.
729 @return: The similar point (ellipsoidal C{LatLon}).
731 @raise ParseError: Invalid B{C{strllh}}.
732 '''
733 a, b, h = _MODS.dms.parse3llh(strllh, height=height, sep=sep, wrap=wrap)
734 return self.classof(a, b, height=h, datum=datum or self.datum,
735 epoch=epoch or self.epoch,
736 reframe=reframe or self.reframe, **name)
738 def _Radjust2(self, adjust, datum, meter_text2):
739 '''(INTERNAL) Adjust an C{elevation} or C{geoidHeight} with
740 difference in Gaussian radii of curvature of the given
741 datum and NAD83 ellipsoids at this point's latitude.
743 @note: This is an arbitrary, possibly incorrect adjustment.
744 '''
745 if adjust: # Elevation2Tuple or GeoidHeight2Tuple
746 m, t = meter_text2
747 if isinstance(m, float) and fabs(m) > EPS: # PYCHOK no cover
748 n = Datums.NAD83.ellipsoid.rocGauss(self.lat)
749 if n > EPS0:
750 # use ratio, datum and NAD83 units may differ
751 E = self.ellipsoid() if _isin(datum, None, self.datum) else \
752 _earth_ellipsoid(datum)
753 r = E.rocGauss(self.lat)
754 if r > EPS0 and fabs(r - n) > EPS: # EPS1
755 m *= r / n
756 meter_text2 = meter_text2.classof(m, t)
757 return self._xnamed(meter_text2)
759 @property_doc_(''' this point's reference frame (L{RefFrame}).''')
760 def reframe(self):
761 '''Get this point's reference frame (L{RefFrame}) or C{None}.
762 '''
763 return self._reframe
765 @reframe.setter # PYCHOK setter!
766 def reframe(self, reframe):
767 '''Set or clear this point's reference frame (L{RefFrame}) or C{None}.
769 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}.
770 '''
771 _set_reframe(self, reframe)
773 @Property_RO
774 def scale(self):
775 '''Get this point's UTM grid or UPS point scale factor (C{float})
776 or C{None} if not converted from L{Utm} or L{Ups}.
777 '''
778 return self._scale
780 def _toX8(self, toX8, **kwds):
781 '''(INTERNAL) Return toX8(self, ...).
782 '''
783 return toX8(self, **_xkwds(kwds, datum=self.datum, name=self.name))
785 def toCartesian(self, height=None, **Cartesian_and_kwds): # PYCHOK signature
786 '''Convert this point to cartesian, I{geocentric} coordinates,
787 also known as I{Earth-Centered, Earth-Fixed} (ECEF).
789 @see: Method L{toCartesian<latlonBase.LatLonBase.toCartesian>}
790 for further details.
791 '''
792 kwds = Cartesian_and_kwds
793 if kwds:
794 kwds = _xkwds(kwds, reframe=self.reframe, epoch=self.epoch)
795 return LatLonBase.toCartesian(self, height=height, **kwds)
797 def toCss(self, **toCss_kwds):
798 '''Convert this C{LatLon} point to a Cassini-Soldner location.
800 @kwarg toCss_kwds: Optional keyword arguments for function
801 L{pygeodesy.toCss}.
803 @return: The Cassini-Soldner location (L{Css}).
804 '''
805 return _MODS.css.toCss(self, **self._name1__(toCss_kwds))
807 def toDatum(self, datum2, height=None, **name):
808 '''Convert this point to an other datum.
810 @arg datum2: Datum to convert I{to} (L{Datum}).
811 @kwarg height: Optional height, overriding the
812 converted height (C{meter}).
813 @kwarg name: Optional C{B{name}=NN} (C{str}).
815 @return: The converted point (this C{LatLon}) or a copy
816 of this point if B{C{datum2}} matches this
817 point's C{datum}.
819 @raise TypeError: Invalid B{C{datum2}}.
820 '''
821 n = self._name__(name)
822 d2 = _ellipsoidal_datum(datum2, name=n)
823 if self.datum == d2:
824 r = self.copy(name=n)
825 else:
826 kwds = _xkwds_not(None, LatLon=self.classof, name=n,
827 epoch=self.epoch, reframe=self.reframe)
828 c = self.toCartesian().toDatum(d2)
829 r = c.toLatLon(datum=d2, height=height, **kwds)
830 return r
832 def toEtm(self, **toEtm8_kwds):
833 '''Convert this C{LatLon} point to an ETM coordinate.
835 @kwarg toEtm8_kwds: Optional keyword arguments for
836 function L{pygeodesy.toEtm8}.
838 @return: The ETM coordinate (L{Etm}).
839 '''
840 return self._etm if not toEtm8_kwds else \
841 self._toX8(_MODS.etm.toEtm8, **toEtm8_kwds)
843 def toLcc(self, **toLcc_kwds):
844 '''Convert this C{LatLon} point to a Lambert location.
846 @kwarg toLcc_kwds: Optional keyword arguments for
847 function L{pygeodesy.toLcc}.
849 @return: The Lambert location (L{Lcc}).
850 '''
851 return _MODS.lcc.toLcc(self, **self._name1__(toLcc_kwds))
853 def toMgrs(self, center=False, **toUtmUps_kwds):
854 '''Convert this C{LatLon} point to an MGRS coordinate.
856 @kwarg center: If C{True}, try to I{un}-center MGRS
857 to its C{lowerleft} (C{bool}) or by
858 C{B{center} meter} (C{scalar}).
859 @kwarg toUtmUps_kwds: Optional keyword arguments for
860 method L{toUtmUps}.
862 @return: The MGRS coordinate (L{Mgrs}).
864 @see: Methods L{toUtmUps} and L{toMgrs<pygeodesy.utmupsBase.UtmUpsBase.toMgrs>}.
865 '''
866 return self.toUtmUps(center=center, **toUtmUps_kwds).toMgrs(center=False)
868 def toOsgr(self, kTM=False, **toOsgr_kwds):
869 '''Convert this C{LatLon} point to an OSGR coordinate.
871 @kwarg kTM: If C{True}, use I{Karney}'s Krüger method from module
872 L{ktm}, otherwise I{Ordinance Survery}'s recommended
873 formulation (C{bool}).
874 @kwarg toOsgr_kwds: Optional keyword arguments for function
875 L{pygeodesy.toOsgr}.
877 @return: The OSGR coordinate (L{Osgr}).
878 '''
879 return _MODS.osgr.toOsgr(self, kTM=kTM, **self._name1__(toOsgr_kwds))
881 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, height=None, **name):
882 '''Convert this point to an other reference frame and epoch.
884 @arg reframe2: Reference frame to convert I{to} (L{RefFrame}).
885 @kwarg reframe: Optional reference frame to convert I{from} (L{RefFrame}),
886 overriding this point's reference frame.
887 @kwarg epoch: Optional epoch (L{Epoch}, C{scalar} or C{str}), overriding
888 this point's C{epoch or B{reframe}.epoch}.
889 @kwarg epoch2: Optional epoch to observe for the converted point (L{Epoch},
890 C{scalar} or C{str}), otherwise B{C{epoch}}.
891 @kwarg height: Optional height, overriding the converted height (C{meter}).
892 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding C{B{reframe2}.name}.
894 @return: The converted point (ellipsoidal C{LatLon}) or if conversion
895 C{isunity}, this point or a copy of this point if the B{C{name}}
896 is non-empty.
898 @raise TRFError: This point's C{reframe} is not defined, invalid B{C{epoch}}
899 or B{C{epoch2}} or conversion from this point's C{reframe}
900 to B{C{reframe2}} is not available.
902 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a L{RefFrame}.
903 '''
904 return _MODS.trf._toRefFrame(self, reframe2, reframe=reframe, epoch=epoch,
905 epoch2=epoch2, height=height, **name)
907 def toTransform(self, transform, inverse=False, datum=None, **LatLon_kwds):
908 '''Apply a Helmert transform to this geodetic point.
910 @arg transform: Transform to apply (L{Transform} or L{TransformXform}).
911 @kwarg inverse: Apply the inverse of the Helmert transform (C{bool}).
912 @kwarg datum: Datum for the transformed point (L{Datum}), overriding
913 this point's datum but I{not} taken it into account.
914 @kwarg LatLon_kwds: Optional keyword arguments for the transformed
915 point, like C{B{height}=...}.
917 @return: A transformed point (C{LatLon}) or a copy of this point if
918 C{B{transform}.isunity}.
920 @raise TypeError: Invalid B{C{transform}}.
921 '''
922 _xinstanceof(Transform, transform=transform)
923 d = datum or self.datum
924 if transform.isunity:
925 r = self.dup(datum=d, **LatLon_kwds)
926 else:
927 c = self.toCartesian()
928 c = c.toTransform(transform, inverse=inverse, datum=d)
929 r = c.toLatLon(LatLon=self.classof, **_xkwds(LatLon_kwds, height=self.height))
930 return r
932 def toUps(self, center=False, **toUps8_kwds):
933 '''Convert this C{LatLon} point to a UPS coordinate.
935 @kwarg center: If C{True}, I{un}-center the UPS to its
936 C{lowerleft} (C{bool}) or by C{B{center}
937 meter} (C{scalar}).
938 @kwarg toUps8_kwds: Optional keyword arguments for
939 function L{pygeodesy.toUps8}.
941 @return: The UPS coordinate (L{Ups}).
942 '''
943 u = self._ups if (not toUps8_kwds) and self._upsOK() else \
944 self._toX8(_MODS.ups.toUps8, **toUps8_kwds)
945 return _lowerleft(u, center)
947 def toUtm(self, center=False, **toUtm8_kwds):
948 '''Convert this C{LatLon} point to a UTM coordinate.
950 @kwarg center: If C{True}, I{un}-center the UTM to its
951 C{lowerleft} (C{bool}) or by C{B{center}
952 meter} (C{scalar}).
953 @kwarg toUtm8_kwds: Optional keyword arguments for function
954 L{pygeodesy.toUtm8}.
956 @return: The UTM coordinate (L{Utm}).
958 @note: For the highest accuracy, use method L{toEtm} and
959 class L{pygeodesy.Etm} instead of L{pygeodesy.Utm}.
960 '''
961 u = self._utm if not toUtm8_kwds else \
962 self._toX8(_MODS.utm.toUtm8, **toUtm8_kwds)
963 return _lowerleft(u, center)
965 def toUtmUps(self, pole=NN, center=False, **toUtmUps8_kwds):
966 '''Convert this C{LatLon} point to a UTM or UPS coordinate.
968 @kwarg pole: Optional top/center of UPS (stereographic)
969 projection (C{str}, 'N[orth]' or 'S[outh]').
970 @kwarg center: If C{True}, I{un}-center the UTM or UPS to
971 its C{lowerleft} (C{bool}) or by C{B{center}
972 meter} (C{scalar}).
973 @kwarg toUtmUps8_kwds: Optional keyword arguments for
974 function L{pygeodesy.toUtmUps8}.
976 @return: The UTM or UPS coordinate (L{Utm} or L{Ups}).
977 '''
978 x = not toUtmUps8_kwds
979 if x and self._utmOK():
980 u = self._utm
981 elif x and self._upsOK(pole):
982 u = self._ups
983 else: # no cover
984 utmups = _MODS.utmups
985 u = self._toX8(utmups.toUtmUps8, pole=pole, **toUtmUps8_kwds)
986 if isinstance(u, utmups.Utm):
987 self._update(False, _utm=u) # PYCHOK kwds
988 elif isinstance(u, utmups.Ups):
989 self._update(False, _ups=u) # PYCHOK kwds
990 else:
991 _xinstanceof(utmups.Utm, utmups.Ups, toUtmUps8=u)
992 return _lowerleft(u, center)
994 @deprecated_method
995 def to3xyz(self): # PYCHOK no cover
996 '''DEPRECATED, use method C{toEcef}.
998 @return: A L{Vector3Tuple}C{(x, y, z)}.
1000 @note: Overloads C{LatLonBase.to3xyz}
1001 '''
1002 r = self.toEcef()
1003 return _MODS.namedTuples.Vector3Tuple(r.x, r.y, r.z, name=self.name)
1005 def triangulate(self, bearing1, other, bearing2, **height_wrap_tol):
1006 '''I{Iteratively} locate a point given this, an other point and a bearing
1007 from North at each point.
1009 @arg bearing1: Bearing at this point (compass C{degrees360}).
1010 @arg other: The other point (C{LatLon}).
1011 @arg bearing2: Bearing at the B{C{other}} point (compass C{degrees360}).
1012 @kwarg height_wrap_tol: Optional keyword arguments C{B{height}=None},
1013 C{B{wrap}=False} and C{B{tol}}, see method L{intersection3}.
1015 @return: Triangulated point (C{LatLon}).
1017 @see: Method L{intersection3} for further details.
1018 '''
1019 if _isDegrees(bearing1) and _isDegrees(bearing2):
1020 r = self.intersection3(bearing1, other, bearing2, **height_wrap_tol)
1021 return r.point
1022 raise _TypeError(bearing1=bearing1, bearing2=bearing2 **height_wrap_tol)
1024 def trilaterate5(self, distance1, point2, distance2, point3, distance3,
1025 area=True, eps=EPS1, wrap=False):
1026 '''Trilaterate three points by I{area overlap} or I{perimeter intersection}
1027 of three intersecting circles.
1029 @arg distance1: Distance to this point (C{meter}), same units as B{C{eps}}).
1030 @arg point2: Second center point (C{LatLon}).
1031 @arg distance2: Distance to point2 (C{meter}, same units as B{C{eps}}).
1032 @arg point3: Third center point (C{LatLon}).
1033 @arg distance3: Distance to point3 (C{meter}, same units as B{C{eps}}).
1034 @kwarg area: If C{True}, compute the area overlap, otherwise the perimeter
1035 intersection of the circles (C{bool}).
1036 @kwarg eps: The required I{minimal overlap} for C{B{area}=True} or the
1037 I{intersection margin} for C{B{area}=False} (C{meter},
1038 conventionally).
1039 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{point2}}
1040 and B{C{point3}} (C{bool}).
1042 @return: A L{Trilaterate5Tuple}C{(min, minPoint, max, maxPoint, n)} with
1043 C{min} and C{max} in C{meter}, same units as B{C{eps}}, the
1044 corresponding trilaterated points C{minPoint} and C{maxPoint}
1045 as I{ellipsoidal} C{LatLon} and C{n}, the number of trilatered
1046 points found for the given B{C{eps}}.
1048 If only a single trilaterated point is found, C{min I{is} max},
1049 C{minPoint I{is} maxPoint} and C{n=1}.
1051 If C{B{area}=False}, C{min} and C{max} represent the nearest
1052 respectively farthest intersection margin.
1054 If C{B{area}=True}, C{min} and C{max} are the smallest respectively
1055 largest I{radial} overlap found.
1057 If C{B{area}=True} and all 3 circles are concentric, C{n=0} and
1058 C{minPoint} and C{maxPoint} are the B{C{point#}} with the smallest
1059 B{C{distance#}} C{min} respectively largest B{C{distance#}} C{max}.
1061 @raise IntersectionError: Trilateration failed for the given B{C{eps}},
1062 insufficient overlap for C{B{area}=True}, no
1063 circle intersections for C{B{area}=False} or
1064 all circles are (near-)concentric.
1066 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.
1068 @raise ValueError: Coincident B{C{points}} or invalid B{C{distance1}},
1069 B{C{distance2}} or B{C{distance3}}.
1071 @note: Ellipsoidal trilateration invokes methods C{LatLon.intersections2}
1072 and C{LatLon.nearestOn} based on I{Karney}'s Python U{geographiclib
1073 <https://PyPI.org/project/geographiclib>} if installed, otherwise
1074 the accurate (but slower) C{ellipsoidalExact.LatLon} methods.
1075 '''
1076 return _trilaterate5(self, distance1,
1077 self.others(point2=point2), distance2,
1078 self.others(point3=point3), distance3,
1079 area=area, eps=eps, wrap=wrap)
1081 @Property_RO
1082 def _ups(self): # __dict__ value overwritten by method C{toUtmUps}
1083 '''(INTERNAL) Get this C{LatLon} point as UPS coordinate (L{Ups}),
1084 see L{pygeodesy.toUps8}.
1085 '''
1086 return self._toX8(_MODS.ups.toUps8) # pole=NN, falsed=True
1088 def _upsOK(self, pole=NN, falsed=True, **unused):
1089 '''(INTERNAL) Check matching C{Ups}.
1090 '''
1091 try:
1092 u = self._ups
1093 except RangeError:
1094 return False
1095 return falsed and (u.pole == pole[:1].upper() or not pole)
1097 @Property_RO
1098 def _utm(self): # __dict__ value overwritten by method C{toUtmUps}
1099 '''(INTERNAL) Get this C{LatLon} point as UTM coordinate (L{Utm}),
1100 see L{pygeodesy.toUtm8}.
1101 '''
1102 return self._toX8(_MODS.utm.toUtm8)
1104 def _utmOK(self):
1105 '''(INTERNAL) Check C{Utm}.
1106 '''
1107 try:
1108 _ = self._utm
1109 except RangeError:
1110 return False
1111 return True
1114def _lowerleft(utmups, center):
1115 '''(INTERNAL) Optionally I{un}-center C{utmups}.
1116 '''
1117 if _isin(center, False, 0, _0_0):
1118 u = utmups
1119 elif _isin(center, True):
1120 u = utmups._lowerleft
1121 else:
1122 u = _MODS.utmupsBase._lowerleft(utmups, center)
1123 return u
1126def _nearestOn(point, point1, point2, within=True, height=None, wrap=False, # was=True
1127 equidistant=None, tol=_TOL_M, **LatLon_and_kwds):
1128 '''(INTERNAL) Get closest point, imported by .ellipsoidalExact,
1129 -GeodSolve, -Karney and -Vincenty to embellish exceptions.
1130 '''
1131 try:
1132 p = _xellipsoidal(point=point)
1133 t = _MODS.ellipsoidalBaseDI._nearestOn2(p, point1, point2, within=within,
1134 height=height, wrap=wrap,
1135 equidistant=equidistant,
1136 tol=tol, **LatLon_and_kwds)
1137 except (TypeError, ValueError) as x:
1138 raise _xError(x, point=point, point1=point1, point2=point2)
1139 return t.closest
1142def _set_reframe(inst, reframe):
1143 '''(INTERNAL) Set or clear an instance's reference frame.
1144 '''
1145 if reframe is not None:
1146 _xinstanceof(_MODS.trf.RefFrame, reframe=reframe)
1147 inst._reframe = reframe
1148 elif inst.reframe is not None:
1149 inst._reframe = None
1152__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)
1154# **) MIT License
1155#
1156# Copyright (C) 2016-2025 -- mrJean1 at Gmail -- All Rights Reserved.
1157#
1158# Permission is hereby granted, free of charge, to any person obtaining a
1159# copy of this software and associated documentation files (the "Software"),
1160# to deal in the Software without restriction, including without limitation
1161# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1162# and/or sell copies of the Software, and to permit persons to whom the
1163# Software is furnished to do so, subject to the following conditions:
1164#
1165# The above copyright notice and this permission notice shall be included
1166# in all copies or substantial portions of the Software.
1167#
1168# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1169# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1170# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1171# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1172# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1173# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1174# OTHER DEALINGS IN THE SOFTWARE.