Coverage for pygeodesy/ellipsoidalBase.py: 91%
301 statements
« prev ^ index » next coverage.py v7.2.2, created at 2024-05-15 16:36 -0400
« prev ^ index » next coverage.py v7.2.2, created at 2024-05-15 16:36 -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-2016}
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 _incompatible, _IsnotError, RangeError, _TypeError, \
22 _ValueError, _xattr, _xellipsoidal, _xError, _xkwds, \
23 _xkwds_not
24# from pygeodesy.fmath import favg # _MODS
25from pygeodesy.interns import NN, _COMMA_, _ellipsoidal_
26from pygeodesy.latlonBase import LatLonBase, _trilaterate5, fabs, _Wrap
27from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS
28# from pygeodesy.lcc import toLcc # _MODS
29# from pygeodesy.namedTuples import Vector3Tuple # _MODS
30from pygeodesy.props import deprecated_method, deprecated_property_RO, \
31 Property_RO, property_doc_, property_RO, _update_all
32# from pygeodesy.trf import _eT0Ds4 # _MODS
33from pygeodesy.units import Epoch, _isDegrees, Radius_, _1mm as _TOL_M
34# from pygeodesy.utily import _Wrap # from .latlonBase
36# from math import fabs # from .latlonBase
38__all__ = _ALL_LAZY.ellipsoidalBase
39__version__ = '24.04.07'
42class CartesianEllipsoidalBase(CartesianBase):
43 '''(INTERNAL) Base class for ellipsoidal C{Cartesian}s.
44 '''
45 _datum = _WGS84 # L{Datum}
46 _epoch = None # overriding .reframe.epoch (C{float})
47 _reframe = None # reference frame (L{RefFrame})
49 def __init__(self, x_xyz, y=None, z=None, datum=None, reframe=None,
50 epoch=None, ll=None, name=NN):
51 '''New ellispoidal C{Cartesian...}.
53 @kwarg reframe: Optional reference frame (L{RefFrame}).
54 @kwarg epoch: Optional epoch to observe for B{C{reframe}} (C{scalar}),
55 a non-zero, fractional calendar year; silently ignored
56 if C{B{reframe}=None}.
58 @raise TypeError: Non-scalar B{C{x_xyz}}, B{C{y}} or B{C{z}} coordinate
59 or B{C{x_xyz}} not a C{Cartesian} L{Ecef9Tuple},
60 L{Vector3Tuple} or L{Vector4Tuple} or B{C{datum}} is
61 not a L{Datum}, B{C{reframe}} is not a L{RefFrame} or
62 B{C{epoch}} is not C{scalar} non-zero.
64 @see: Super-class L{CartesianBase<CartesianBase.__init__>} for more details.
65 '''
66 CartesianBase.__init__(self, x_xyz, y=y, z=z, datum=datum, ll=ll, name=name)
67 if reframe:
68 self.reframe = reframe
69 self.epoch = epoch
71# def __matmul__(self, other): # PYCHOK Python 3.5+
72# '''Return C{NotImplemented} for C{c_ = c @ datum}, C{c_ = c @ reframe} and C{c_ = c @ Transform}.
73# '''
74# RefFrame = _MODS.trf.RefFrame
75# return NotImplemented if isinstance(other, (Datum, RefFrame, Transform)) else \
76# _NotImplemented(self, other)
78 @deprecated_method
79 def convertRefFrame(self, reframe2, reframe, epoch=None):
80 '''DEPRECATED, use method L{toRefFrame}.'''
81 return self.toRefFrame(reframe2, reframe=reframe, epoch=epoch)
83 @property_RO
84 def ellipsoidalCartesian(self):
85 '''Get this C{Cartesian}'s ellipsoidal class.
86 '''
87 return type(self)
89 @property_doc_(''' this cartesian's observed or C{reframe} epoch (C{float}).''')
90 def epoch(self):
91 '''Get this cartesian's observed or C{reframe} epoch (C{Epoch}) or C{None}.
92 '''
93 return self._epoch or (self.reframe.epoch if self.reframe else None)
95 @epoch.setter # PYCHOK setter!
96 def epoch(self, epoch):
97 '''Set or clear this cartesian's observed epoch, a fractional
98 calendar year (L{Epoch}, C{scalar} or C{str}) or C{None}.
100 @raise TRFError: Invalid B{C{epoch}}.
101 '''
102 self._epoch = None if epoch is None else Epoch(epoch)
104 def intersections2(self, radius, center2, radius2, sphere=True,
105 Vector=None, **Vector_kwds):
106 '''Compute the intersection of two spheres or circles, each defined by a
107 cartesian center point and a radius.
109 @arg radius: Radius of this sphere or circle (same units as this point's
110 coordinates).
111 @arg center2: Center of the second sphere or circle (C{Cartesian}, L{Vector3d},
112 C{Vector3Tuple} or C{Vector4Tuple}).
113 @arg radius2: Radius of the second sphere or circle (same units as this and
114 the B{C{other}} point's coordinates).
115 @kwarg sphere: If C{True} compute the center and radius of the intersection
116 of two I{spheres}. If C{False}, ignore the C{z}-component and
117 compute the intersection of two I{circles} (C{bool}).
118 @kwarg Vector: Class to return intersections (C{Cartesian}, L{Vector3d} or
119 C{Vector3Tuple}) or C{None} for an instance of this (sub-)class.
120 @kwarg Vector_kwds: Optional, additional B{C{Vector}} keyword arguments,
121 ignored if C{B{Vector} is None}.
123 @return: If B{C{sphere}} is C{True}, a 2-tuple of the C{center} and C{radius}
124 of the intersection of the I{spheres}. The C{radius} is C{0.0} for
125 abutting spheres (and the C{center} is aka the I{radical center}).
127 If B{C{sphere}} is C{False}, a 2-tuple with the two intersection
128 points of the I{circles}. For abutting circles, both points are
129 the same instance, aka the I{radical center}.
131 @raise IntersectionError: Concentric, invalid or non-intersecting spheres or circles.
133 @raise TypeError: Invalid B{C{center2}}.
135 @raise UnitError: Invalid B{C{radius}} or B{C{radius2}}.
137 @see: U{Sphere-Sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>},
138 U{Circle-Circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>}
139 Intersection and function L{pygeodesy.radical2}.
140 '''
141 try:
142 return _MODS.vector3d._intersects2(self, Radius_(radius=radius),
143 center2, Radius_(radius2=radius2),
144 sphere=sphere, clas=self.classof,
145 Vector=Vector, **Vector_kwds)
146 except (TypeError, ValueError) as x:
147 raise _xError(x, center=self, radius=radius, center2=center2, radius2=radius2)
149 @property_doc_(''' this cartesian's reference frame (L{RefFrame}).''')
150 def reframe(self):
151 '''Get this cartesian's reference frame (L{RefFrame}) or C{None}.
152 '''
153 return self._reframe
155 @reframe.setter # PYCHOK setter!
156 def reframe(self, reframe):
157 '''Set or clear this cartesian's reference frame (L{RefFrame}) or C{None}.
159 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}.
160 '''
161 _set_reframe(self, reframe)
163 def toLatLon(self, datum=None, height=None, **LatLon_and_kwds): # PYCHOK signature
164 '''Convert this cartesian to a I{geodetic} (lat-/longitude) point.
166 @see: Method L{toLatLon<cartesianBase.CartesianBase.toLatLon>}
167 for further details.
168 '''
169 kwds = LatLon_and_kwds
170 if kwds:
171 kwds = _xkwds(kwds, reframe=self.reframe, epoch=self.epoch)
172 return CartesianBase.toLatLon(self, datum=datum, height=height, **kwds)
174 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, name=NN):
175 '''Convert this point to an other reference frame and epoch.
177 @arg reframe2: Reference frame to convert I{to} (L{RefFrame}).
178 @kwarg reframe: Optional reference frame to convert I{from} (L{RefFrame}),
179 overriding this point's reference frame.
180 @kwarg epoch: Optional epoch (L{Epoch}, C{scalar} or C{str}), overriding
181 this point's C{epoch or B{reframe}.epoch}.
182 @kwarg epoch2: Optional epoch to observe for the converted point (L{Epoch},
183 C{scalar} or C{str}), otherwise B{C{epoch}}.
184 @kwarg name: Optional name (C{str}), C{B{reframe2}.name} iff converted.
186 @return: The converted point (ellipsoidal C{Cartesian}) or if conversion
187 C{isunity}, this point or a copy of this point if the B{C{name}}
188 is non-empty.
190 @raise TRFError: This point's C{reframe} is not defined, invalid B{C{epoch}}
191 or B{C{epoch2}} or conversion from this point's C{reframe}
192 to B{C{reframe2}} is not available.
194 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a L{RefFrame}.
195 '''
196 return _MODS.trf._toRefFrame(self, reframe2, reframe=reframe, epoch=epoch,
197 epoch2=epoch2, name=name)
199 @deprecated_method
200 def toTransforms_(self, *transforms, **datum): # PYCHOK no cover
201 '''DEPRECATED on 2024.02.14, use method C{toTransform}.'''
202 r = self
203 for t in transforms:
204 r = r.toTransform(t)
205 return r.dup(**datum) if datum else r
208class LatLonEllipsoidalBase(LatLonBase):
209 '''(INTERNAL) Base class for ellipsoidal C{LatLon}s.
210 '''
211 _datum = _WGS84 # L{Datum}
212 _elevation2to = None # _elevation2 timeout (C{secs})
213 _epoch = None # overriding .reframe.epoch (C{float})
214 _gamma = None # UTM/UPS meridian convergence (C{degrees})
215 _geoidHeight2to = None # _geoidHeight2 timeout (C{secs})
216 _reframe = None # reference frame (L{RefFrame})
217 _scale = None # UTM/UPS scale factor (C{float})
218 _toLLEB_args = () # Etm/Utm/Ups._toLLEB arguments
220 def __init__(self, latlonh, lon=None, height=0, datum=None, reframe=None,
221 epoch=None, wrap=False, name=NN):
222 '''Create an ellipsoidal C{LatLon} point from the given lat-, longitude
223 and height on the given datum, reference frame and epoch.
225 @arg latlonh: Latitude (C{degrees} or DMS C{str} with N or S suffix) or
226 a previous C{LatLon} instance provided C{B{lon}=None}.
227 @kwarg lon: Longitude (C{degrees} or DMS C{str} with E or W suffix) or
228 C(None), indicating B{C{latlonh}} is a C{LatLon}.
229 @kwarg height: Optional height above (or below) the earth surface
230 (C{meter}, same units as the datum's ellipsoid axes).
231 @kwarg datum: Optional, ellipsoidal datum to use (L{Datum}, L{Ellipsoid},
232 L{Ellipsoid2} or L{a_f2Tuple}).
233 @kwarg reframe: Optional reference frame (L{RefFrame}).
234 @kwarg epoch: Optional epoch to observe for B{C{reframe}} (C{scalar}),
235 a non-zero, fractional calendar year; silently ignored
236 if C{B{reframe}=None}.
237 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{lat}} and B{C{lon}}
238 (C{bool}).
239 @kwarg name: Optional name (C{str}).
241 @raise RangeError: Value of C{lat} or B{C{lon}} outside the valid
242 range and L{rangerrors} set to C{True}.
244 @raise TypeError: If B{C{latlonh}} is not a C{LatLon}, B{C{datum}} is
245 not a L{Datum}, B{C{reframe}} is not a L{RefFrame}
246 or B{C{epoch}} is not C{scalar} non-zero.
248 @raise UnitError: Invalid B{C{lat}}, B{C{lon}} or B{C{height}}.
249 '''
250 LatLonBase.__init__(self, latlonh, lon=lon, height=height, wrap=wrap, name=name)
251 if datum not in (None, self._datum, _EWGS84):
252 self.datum = _ellipsoidal_datum(datum, name=name)
253 if reframe:
254 self.reframe = reframe
255 self.epoch = epoch
257# def __matmul__(self, other): # PYCHOK Python 3.5+
258# '''Return C{NotImplemented} for C{ll_ = ll @ datum} and C{ll_ = ll @ reframe}.
259# '''
260# RefFrame = _MODS.trf.RefFrame
261# return NotImplemented if isinstance(other, (Datum, RefFrame)) else \
262# _NotImplemented(self, other)
264 def antipode(self, height=None):
265 '''Return the antipode, the point diametrically opposite
266 to this point.
268 @kwarg height: Optional height of the antipode, height
269 of this point otherwise (C{meter}).
271 @return: The antipodal point (C{LatLon}).
272 '''
273 lla = LatLonBase.antipode(self, height=height)
274 if lla.datum != self.datum:
275 lla.datum = self.datum
276 return lla
278 @deprecated_property_RO
279 def convergence(self):
280 '''DEPRECATED, use property C{gamma}.'''
281 return self.gamma
283 @deprecated_method
284 def convertDatum(self, datum2):
285 '''DEPRECATED, use method L{toDatum}.'''
286 return self.toDatum(datum2)
288 @deprecated_method
289 def convertRefFrame(self, reframe2):
290 '''DEPRECATED, use method L{toRefFrame}.'''
291 return self.toRefFrame(reframe2)
293 @Property_RO
294 def _css(self):
295 '''(INTERNAL) Get this C{LatLon} point as a Cassini-Soldner location (L{Css}).
296 '''
297 css = _MODS.css
298 return css.toCss(self, height=self.height, Css=css.Css, name=self.name)
300 @property_doc_(''' this points's datum (L{Datum}).''')
301 def datum(self):
302 '''Get this point's datum (L{Datum}).
303 '''
304 return self._datum
306 @datum.setter # PYCHOK setter!
307 def datum(self, datum):
308 '''Set this point's datum I{without conversion} (L{Datum}).
310 @raise TypeError: The B{C{datum}} is not a L{Datum}
311 or not ellipsoidal.
312 '''
313 _xinstanceof(Datum, datum=datum)
314 if not datum.isEllipsoidal:
315 raise _IsnotError(_ellipsoidal_, datum=datum)
316 if self._datum != datum:
317 _update_all(self)
318 self._datum = datum
320 def distanceTo2(self, other, wrap=False):
321 '''I{Approximate} the distance and (initial) bearing between this
322 and an other (ellipsoidal) point based on the radii of curvature.
324 I{Suitable only for short distances up to a few hundred Km
325 or Miles and only between points not near-polar}.
327 @arg other: The other point (C{LatLon}).
328 @kwarg wrap: If C{True}, wrap or I{normalize} the B{C{other}}
329 point (C{bool}).
331 @return: An L{Distance2Tuple}C{(distance, initial)}.
333 @raise TypeError: The B{C{other}} point is not C{LatLon}.
335 @raise ValueError: Incompatible datum ellipsoids.
337 @see: Method L{Ellipsoid.distance2} and U{Local, flat earth
338 approximation<https://www.EdWilliams.org/avform.htm#flat>}
339 aka U{Hubeny<https://www.OVG.AT/de/vgi/files/pdf/3781/>}
340 formula.
341 '''
342 p = self.others(other)
343 if wrap:
344 p = _Wrap.point(p)
345 E = self.ellipsoids(other)
346 return E.distance2(*(self.latlon + p.latlon))
348 @Property_RO
349 def _elevation2(self):
350 '''(INTERNAL) Get elevation and data source.
351 '''
352 return _MODS.elevations.elevation2(self.lat, self.lon,
353 timeout=self._elevation2to)
355 def elevation2(self, adjust=True, datum=None, timeout=2):
356 '''Return elevation of this point for its or the given datum, ellipsoid
357 or sphere.
359 @kwarg adjust: Adjust the elevation for a B{C{datum}} other than
360 C{NAD83} (C{bool}).
361 @kwarg datum: Optional datum overriding this point's datum (L{Datum},
362 L{Ellipsoid}, L{Ellipsoid2}, L{a_f2Tuple} or C{scalar}
363 radius).
364 @kwarg timeout: Optional query timeout (C{seconds}).
366 @return: An L{Elevation2Tuple}C{(elevation, data_source)} or
367 C{(None, error)} in case of errors.
369 @note: The adjustment applied is the difference in geocentric earth
370 radius between the B{C{datum}} and C{NAV83} upon which the
371 L{elevations.elevation2} is based.
373 @note: NED elevation is only available for locations within the U{Conterminous
374 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}.
376 @see: Function L{elevations.elevation2} and method C{Ellipsoid.Rgeocentric}
377 for further details and possible C{error}s.
378 '''
379 if self._elevation2to != timeout:
380 self._elevation2to = timeout
381 LatLonEllipsoidalBase._elevation2._update(self)
382 return self._Radjust2(adjust, datum, self._elevation2)
384 def ellipsoid(self, datum=_WGS84):
385 '''Return the ellipsoid of this point's datum or the given datum.
387 @kwarg datum: Default datum (L{Datum}).
389 @return: The ellipsoid (L{Ellipsoid} or L{Ellipsoid2}).
390 '''
391 return _xattr(self, datum=datum).ellipsoid
393 @property_RO
394 def ellipsoidalLatLon(self):
395 '''Get this C{LatLon}'s ellipsoidal class.
396 '''
397 return type(self)
399 def ellipsoids(self, other):
400 '''Check the type and ellipsoid of this and an other point's datum.
402 @arg other: The other point (C{LatLon}).
404 @return: This point's datum ellipsoid (L{Ellipsoid} or L{Ellipsoid2}).
406 @raise TypeError: The B{C{other}} point is not C{LatLon}.
408 @raise ValueError: Incompatible datum ellipsoids.
409 '''
410 self.others(other, up=2) # ellipsoids' caller
412 E = self.ellipsoid()
413 try: # other may be Sphere, etc.
414 e = other.ellipsoid()
415 except AttributeError:
416 try: # no ellipsoid method, try datum
417 e = other.datum.ellipsoid
418 except AttributeError:
419 e = E # no datum, XXX assume equivalent?
420 if e != E:
421 raise _ValueError(e.named2, txt=_incompatible(E.named2))
422 return E
424 @property_doc_(''' this point's observed or C{reframe} epoch (C{float}).''')
425 def epoch(self):
426 '''Get this point's observed or C{reframe} epoch (L{Epoch}) or C{None}.
427 '''
428 return self._epoch or (self.reframe.epoch if self.reframe else None)
430 @epoch.setter # PYCHOK setter!
431 def epoch(self, epoch):
432 '''Set or clear this point's observed epoch, a fractional
433 calendar year (L{Epoch}, C{scalar} or C{str}) or C{None}.
435 @raise TRFError: Invalid B{C{epoch}}.
436 '''
437 self._epoch = None if epoch is None else Epoch(epoch)
439 @Property_RO
440 def Equidistant(self):
441 '''Get the prefered azimuthal equidistant projection I{class} (L{EquidistantKarney} or L{EquidistantExact}).
442 '''
443 try:
444 _ = self.datum.ellipsoid.geodesic
445 return _MODS.azimuthal.EquidistantKarney
446 except ImportError: # no geographiclib
447 return _MODS.azimuthal.EquidistantExact # XXX no longer L{azimuthal.Equidistant}
449 @Property_RO
450 def _etm(self):
451 '''(INTERNAL) Get this C{LatLon} point as an ETM coordinate (L{pygeodesy.toEtm8}).
452 '''
453 etm = _MODS.etm
454 return etm.toEtm8(self, datum=self.datum, Etm=etm.Etm)
456 @property_RO
457 def gamma(self):
458 '''Get this point's UTM or UPS meridian convergence (C{degrees}) or
459 C{None} if not available or not converted from L{Utm} or L{Ups}.
460 '''
461 return self._gamma
463 @Property_RO
464 def _geoidHeight2(self):
465 '''(INTERNAL) Get geoid height and model.
466 '''
467 return _MODS.elevations.geoidHeight2(self.lat, self.lon, model=0,
468 timeout=self._geoidHeight2to)
470 def geoidHeight2(self, adjust=False, datum=None, timeout=2):
471 '''Return geoid height of this point for its or the given datum, ellipsoid
472 or sphere.
474 @kwarg adjust: Adjust the geoid height for a B{C{datum}} other than
475 C{NAD83/NADV88} (C{bool}).
476 @kwarg datum: Optional datum overriding this point's datum (L{Datum},
477 L{Ellipsoid}, L{Ellipsoid2}, L{a_f2Tuple} or C{scalar}
478 radius).
479 @kwarg timeout: Optional query timeout (C{seconds}).
481 @return: A L{GeoidHeight2Tuple}C{(height, model_name)} or
482 C{(None, error)} in case of errors.
484 @note: The adjustment applied is the difference in geocentric earth
485 radius between the B{C{datum}} and C{NAV83/NADV88} upon which
486 the L{elevations.geoidHeight2} is based.
488 @note: The geoid height is only available for locations within the U{Conterminous
489 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}.
491 @see: Function L{elevations.geoidHeight2} and method C{Ellipsoid.Rgeocentric}
492 for further details and possible C{error}s.
493 '''
494 if self._geoidHeight2to != timeout:
495 self._geoidHeight2to = timeout
496 LatLonEllipsoidalBase._geoidHeight2._update(self)
497 return self._Radjust2(adjust, datum, self._geoidHeight2)
499 def intermediateTo(self, other, fraction, height=None, wrap=False): # PYCHOK no cover
500 '''I{Must be overloaded}.'''
501 self._notOverloaded(other, fraction, height=height, wrap=wrap)
503 def intersection3(self, end1, other, end2, height=None, wrap=False, # was=True
504 equidistant=None, tol=_TOL_M):
505 '''I{Iteratively} compute the intersection point of two lines, each
506 defined by two points or a start point and bearing from North.
508 @arg end1: End point of this line (C{LatLon}) or the initial
509 bearing at this point (compass C{degrees360}).
510 @arg other: Start point of the other line (C{LatLon}).
511 @arg end2: End point of the other line (C{LatLon}) or the initial
512 bearing at the other point (compass C{degrees360}).
513 @kwarg height: Optional height at the intersection (C{meter},
514 conventionally) or C{None} for the mean height.
515 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
516 B{C{other}} and B{C{end*}} points (C{bool}).
517 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
518 function L{pygeodesy.equidistant}), or C{None}
519 for this point's preferred C{.Equidistant}.
520 @kwarg tol: Tolerance for convergence and skew line distance and
521 length (C{meter}, conventionally).
523 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)}
524 with C{point} a C{LatLon} instance.
526 @raise ImportError: Package U{geographiclib
527 <https://PyPI.org/project/geographiclib>}
528 not installed or not found, but only if
529 C{B{equidistant}=}L{EquidistantKarney}.
531 @raise IntersectionError: Skew, colinear, parallel or otherwise
532 non-intersecting lines or no convergence
533 for the given B{C{tol}}.
535 @raise TypeError: If B{C{end1}}, B{C{other}} or B{C{end2}} point
536 is not C{LatLon}.
538 @note: For each line specified with an initial bearing, a pseudo-end
539 point is computed as the C{destination} along that bearing at
540 about 1.5 times the distance from the start point to an initial
541 gu-/estimate of the intersection point (and between 1/8 and 3/8
542 of the authalic earth perimeter).
544 @see: I{Karney's} U{intersect.cpp<https://SourceForge.net/p/geographiclib/
545 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https://
546 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>}
547 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section
548 B{14. MARITIME BOUNDARIES} for more details about the iteration algorithm.
549 '''
550 try:
551 s2 = self.others(other)
552 return _MODS.ellipsoidalBaseDI._intersect3(self, end1,
553 s2, end2,
554 height=height, wrap=wrap,
555 equidistant=equidistant, tol=tol,
556 LatLon=self.classof, datum=self.datum)
557 except (TypeError, ValueError) as x:
558 raise _xError(x, start1=self, end1=end1, other=other, end2=end2,
559 height=height, wrap=wrap, tol=tol)
561 def intersections2(self, radius1, other, radius2, height=None, wrap=False, # was=True
562 equidistant=None, tol=_TOL_M):
563 '''I{Iteratively} compute the intersection points of two circles,
564 each defined by a center point and a radius.
566 @arg radius1: Radius of this circle (C{meter}, conventionally).
567 @arg other: Center of the other circle (C{LatLon}).
568 @arg radius2: Radius of the other circle (C{meter}, same units as
569 B{C{radius1}}).
570 @kwarg height: Optional height for the intersection points (C{meter},
571 conventionally) or C{None} for the I{"radical height"}
572 at the I{radical line} between both centers.
573 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the B{C{other}}
574 center (C{bool}).
575 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
576 function L{pygeodesy.equidistant}) or C{None}
577 for this point's preferred C{.Equidistant}.
578 @kwarg tol: Convergence tolerance (C{meter}, same units as
579 B{C{radius1}} and B{C{radius2}}).
581 @return: 2-Tuple of the intersection points, each a C{LatLon}
582 instance. For abutting circles, both intersection
583 points are the same instance, aka the I{radical center}.
585 @raise ImportError: Package U{geographiclib
586 <https://PyPI.org/project/geographiclib>}
587 not installed or not found, but only if
588 C{B{equidistant}=}L{EquidistantKarney}.
590 @raise IntersectionError: Concentric, antipodal, invalid or
591 non-intersecting circles or no
592 convergence for the given B{C{tol}}.
594 @raise TypeError: Invalid B{C{other}} or B{C{equidistant}}.
596 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.
598 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
599 calculating-intersection-of-two-circles>}, U{Karney's paper
600 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},
601 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and
602 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}
603 intersections.
604 '''
605 try:
606 c2 = self.others(other)
607 return _MODS.ellipsoidalBaseDI._intersections2(self, radius1,
608 c2, radius2,
609 height=height, wrap=wrap,
610 equidistant=equidistant, tol=tol,
611 LatLon=self.classof, datum=self.datum)
612 except (AssertionError, TypeError, ValueError) as x:
613 raise _xError(x, center=self, radius1=radius1, other=other, radius2=radius2,
614 height=height, wrap=wrap, tol=tol)
616 def isenclosedBy(self, points, wrap=False):
617 '''Check whether a polygon or composite encloses this point.
619 @arg points: The polygon points or clips (C{LatLon}[],
620 L{BooleanFHP} or L{BooleanGH}).
621 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
622 B{C{points}} (C{bool}).
624 @return: C{True} if this point is inside the polygon or composite,
625 C{False} otherwise.
627 @raise PointsError: Insufficient number of B{C{points}}.
629 @raise TypeError: Some B{C{points}} are not C{LatLon}.
631 @raise ValueError: Invalid B{C{point}}, lat- or longitude.
633 @see: Functions L{pygeodesy.isconvex}, L{pygeodesy.isenclosedBy}
634 and L{pygeodesy.ispolar} especially if the B{C{points}} may
635 enclose a pole or wrap around the earth I{longitudinally}.
636 '''
637 return _MODS.points.isenclosedBy(self, points, wrap=wrap)
639 @property_RO
640 def iteration(self):
641 '''Get the most recent C{intersections2} or C{nearestOn} iteration
642 number (C{int}) or C{None} if not available/applicable.
643 '''
644 return self._iteration
646 @Property_RO
647 def _lcc(self):
648 '''(INTERNAL) Get this C{LatLon} point as a Lambert location (L{Lcc}).
649 '''
650 lcc = _MODS.lcc
651 return lcc.toLcc(self, height=self.height, Lcc=lcc.Lcc, name=self.name)
653 def midpointTo(self, other, height=None, fraction=_0_5, wrap=False):
654 '''Find the midpoint on a geodesic between this and an other point.
656 @arg other: The other point (C{LatLon}).
657 @kwarg height: Optional height for midpoint, overriding the
658 mean height (C{meter}).
659 @kwarg fraction: Midpoint location from this point (C{scalar}),
660 may be negative or greater than 1.0.
661 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
662 B{C{other}} point (C{bool}).
664 @return: Midpoint (C{LatLon}).
666 @raise TypeError: The B{C{other}} point is not C{LatLon}.
668 @raise ValueError: Invalid B{C{height}}.
670 @see: Methods C{intermediateTo} and C{rhumbMidpointTo}.
671 '''
672 return self.intermediateTo(other, fraction, height=height, wrap=wrap)
674 def nearestOn(self, point1, point2, within=True, height=None, wrap=False, # was=True
675 equidistant=None, tol=_TOL_M):
676 '''I{Iteratively} locate the closest point on the geodesic between
677 two other (ellipsoidal) points.
679 @arg point1: Start point (C{LatLon}).
680 @arg point2: End point (C{LatLon}).
681 @kwarg within: If C{True} return the closest point I{between}
682 B{C{point1}} and B{C{point2}}, otherwise the
683 closest point elsewhere on the geodesic (C{bool}).
684 @kwarg height: Optional height for the closest point (C{meter},
685 conventionally) or C{None} or C{False} for the
686 interpolated height. If C{False}, the closest
687 takes the heights of the points into account.
688 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both
689 B{C{point1}} and B{C{point2}} (C{bool}).
690 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
691 function L{pygeodesy.equidistant}) or C{None}
692 for this point's preferred C{.Equidistant}.
693 @kwarg tol: Convergence tolerance (C{meter}, conventionally).
695 @return: Closest point (C{LatLon}).
697 @raise ImportError: Package U{geographiclib
698 <https://PyPI.org/project/geographiclib>}
699 not installed or not found, but only if
700 C{B{equidistant}=}L{EquidistantKarney}.
702 @raise TypeError: Invalid B{C{point1}}, B{C{point2}} or
703 B{C{equidistant}}.
705 @raise ValueError: Datum or ellipsoid of B{C{point1}} or B{C{point2}} is
706 incompatible or no convergence for the given B{C{tol}}.
708 @see: I{Karney}'s U{intercept.cpp<https://SourceForge.net/p/geographiclib/
709 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https://
710 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>}
711 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section
712 B{14. MARITIME BOUNDARIES} for details about the iteration algorithm.
713 '''
714 try:
715 t = _MODS.ellipsoidalBaseDI._nearestOn2(self, point1, point2, within=within,
716 height=height, wrap=wrap,
717 equidistant=equidistant,
718 tol=tol, LatLon=self.classof)
719 except (TypeError, ValueError) as x:
720 raise _xError(x, point=self, point1=point1, point2=point2, within=within,
721 height=height, wrap=wrap, tol=tol)
722 return t.closest
724 @Property_RO
725 def _osgr(self):
726 '''(INTERNAL) Get this C{LatLon} point as an OSGR coordinate (L{Osgr}),
727 based on the OS recommendation.
728 '''
729 return _MODS.osgr.toOsgr(self, kTM=False, name=self.name) # datum=self.datum
731 @Property_RO
732 def _osgrTM(self):
733 '''(INTERNAL) Get this C{LatLon} point as an OSGR coordinate (L{Osgr})
734 based on I{Karney}'s Krüger implementation.
735 '''
736 return _MODS.osgr.toOsgr(self, kTM=True, name=self.name) # datum=self.datum
738 def parse(self, strllh, height=0, datum=None, epoch=None, reframe=None,
739 sep=_COMMA_, wrap=False, name=NN):
740 '''Parse a string consisting of C{"lat, lon[, height]"},
741 representing a similar, ellipsoidal C{LatLon} point.
743 @arg strllh: Lat, lon and optional height (C{str}),
744 see function L{pygeodesy.parse3llh}.
745 @kwarg height: Optional, default height (C{meter} or
746 C{None}).
747 @kwarg datum: Optional datum (L{Datum}), overriding this
748 datum I{without conversion}.
749 @kwarg epoch: Optional datum (L{Epoch}), overriding this
750 epoch I{without conversion}.
751 @kwarg reframe: Optional datum (L{RefFrame}), overriding
752 this reframe I{without conversion}.
753 @kwarg sep: Optional separator (C{str}).
754 @kwarg wrap: If C{True}, wrap or I{normalize} the lat-
755 and longitude (C{bool}).
756 @kwarg name: Optional instance name (C{str}), overriding
757 this name.
759 @return: The similar point (ellipsoidal C{LatLon}).
761 @raise ParseError: Invalid B{C{strllh}}.
762 '''
763 a, b, h = _MODS.dms.parse3llh(strllh, height=height, sep=sep, wrap=wrap)
764 r = self.classof(a, b, height=h, datum=self.datum)
765 if datum not in (None, self.datum):
766 r.datum = datum
767 if epoch not in (None, self.epoch):
768 r.epoch = epoch
769 if reframe not in (None, self.reframe):
770 r.reframe = reframe
771 return self._xnamed(r, name=name, force=True) if name else r
773 def _Radjust2(self, adjust, datum, meter_text2):
774 '''(INTERNAL) Adjust an C{elevation} or C{geoidHeight} with
775 difference in Gaussian radii of curvature of the given
776 datum and NAD83 ellipsoids at this point's latitude.
778 @note: This is an arbitrary, possibly incorrect adjustment.
779 '''
780 if adjust: # Elevation2Tuple or GeoidHeight2Tuple
781 m, t = meter_text2
782 if isinstance(m, float) and fabs(m) > EPS:
783 n = Datums.NAD83.ellipsoid.rocGauss(self.lat)
784 if n > EPS0:
785 # use ratio, datum and NAD83 units may differ
786 E = self.ellipsoid() if datum in (None, self.datum) else \
787 _earth_ellipsoid(datum)
788 r = E.rocGauss(self.lat)
789 if r > EPS0 and fabs(r - n) > EPS: # EPS1
790 m *= r / n
791 meter_text2 = meter_text2.classof(m, t)
792 return self._xnamed(meter_text2)
794 @property_doc_(''' this point's reference frame (L{RefFrame}).''')
795 def reframe(self):
796 '''Get this point's reference frame (L{RefFrame}) or C{None}.
797 '''
798 return self._reframe
800 @reframe.setter # PYCHOK setter!
801 def reframe(self, reframe):
802 '''Set or clear this point's reference frame (L{RefFrame}) or C{None}.
804 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}.
805 '''
806 _set_reframe(self, reframe)
808 @Property_RO
809 def scale(self):
810 '''Get this point's UTM grid or UPS point scale factor (C{float})
811 or C{None} if not converted from L{Utm} or L{Ups}.
812 '''
813 return self._scale
815 def toCartesian(self, height=None, **Cartesian_and_kwds): # PYCHOK signature
816 '''Convert this point to cartesian, I{geocentric} coordinates,
817 also known as I{Earth-Centered, Earth-Fixed} (ECEF).
819 @see: Method L{toCartesian<latlonBase.LatLonBase.toCartesian>}
820 for further details.
821 '''
822 kwds = Cartesian_and_kwds
823 if kwds:
824 kwds = _xkwds(kwds, reframe=self.reframe, epoch=self.epoch)
825 return LatLonBase.toCartesian(self, height=height, **kwds)
827 def toCss(self, **toCss_kwds):
828 '''Convert this C{LatLon} point to a Cassini-Soldner location.
830 @kwarg toCss_kwds: Optional L{pygeodesy.toCss} keyword arguments.
832 @return: The Cassini-Soldner location (L{Css}).
834 @see: Function L{pygeodesy.toCss}.
835 '''
836 return self._css if not toCss_kwds else _MODS.css.toCss(
837 self, **_xkwds(toCss_kwds, name=self.name))
839 def toDatum(self, datum2, height=None, name=NN):
840 '''Convert this point to an other datum.
842 @arg datum2: Datum to convert I{to} (L{Datum}).
843 @kwarg height: Optional height, overriding the
844 converted height (C{meter}).
845 @kwarg name: Optional name (C{str}), iff converted.
847 @return: The converted point (ellipsoidal C{LatLon})
848 or a copy of this point if B{C{datum2}}
849 matches this point's C{datum}.
851 @raise TypeError: Invalid B{C{datum2}}.
852 '''
853 n = name or self.name
854 d2 = _ellipsoidal_datum(datum2, name=n)
855 if self.datum == d2:
856 r = self.copy(name=name)
857 else:
858 kwds = _xkwds_not(None, LatLon=self.classof, name=n,
859 epoch=self.epoch, reframe=self.reframe)
860 c = self.toCartesian().toDatum(d2)
861 r = c.toLatLon(datum=d2, height=height, **kwds)
862 return r
864 def toEtm(self, **toEtm8_kwds):
865 '''Convert this C{LatLon} point to an ETM coordinate.
867 @kwarg toEtm8_kwds: Optional L{pygeodesy.toEtm8} keyword arguments.
869 @return: The ETM coordinate (L{Etm}).
871 @see: Function L{pygeodesy.toEtm8}.
872 '''
873 return self._etm if not toEtm8_kwds else _MODS.etm.toEtm8(
874 self, **_xkwds(toEtm8_kwds, name=self.name))
876 def toLcc(self, **toLcc_kwds):
877 '''Convert this C{LatLon} point to a Lambert location.
879 @kwarg toLcc_kwds: Optional L{pygeodesy.toLcc} keyword arguments.
881 @return: The Lambert location (L{Lcc}).
883 @see: Function L{pygeodesy.toLcc}.
884 '''
885 return self._lcc if not toLcc_kwds else _MODS.lcc.toLcc(
886 self, **_xkwds(toLcc_kwds, name=self.name))
888 def toMgrs(self, center=False, pole=NN):
889 '''Convert this C{LatLon} point to an MGRS coordinate.
891 @kwarg center: If C{True}, try to I{un}-center MGRS
892 to its C{lowerleft} (C{bool}) or by
893 C{B{center} meter} (C{scalar}).
894 @kwarg pole: Optional top/center for the MGRS UPS
895 projection (C{str}, 'N[orth]' or 'S[outh]').
897 @return: The MGRS coordinate (L{Mgrs}).
899 @see: Method L{toUtmUps} and L{Mgrs.toLatLon}.
900 '''
901 return self.toUtmUps(center=center, pole=pole).toMgrs(center=False)
903 def toOsgr(self, kTM=False, **toOsgr_kwds):
904 '''Convert this C{LatLon} point to an OSGR coordinate.
906 @kwarg kTM: If C{True} use I{Karney}'s Krüger method from module
907 L{ktm}, otherwise I{Ordinance Survery}'s recommended
908 formulation (C{bool}).
909 @kwarg toOsgr_kwds: Optional L{pygeodesy.toOsgr} keyword arguments.
911 @return: The OSGR coordinate (L{Osgr}).
913 @see: Function L{pygeodesy.toOsgr}.
914 '''
915 if toOsgr_kwds:
916 r = _MODS.osgr.toOsgr(self, kTM=kTM, **_xkwds(toOsgr_kwds, name=self.name))
917 else:
918 r = self._osgrTM if kTM else self._osgr
919 return r
921 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, height=None, name=NN):
922 '''Convert this point to an other reference frame and epoch.
924 @arg reframe2: Reference frame to convert I{to} (L{RefFrame}).
925 @kwarg reframe: Optional reference frame to convert I{from} (L{RefFrame}),
926 overriding this point's reference frame.
927 @kwarg epoch: Optional epoch (L{Epoch}, C{scalar} or C{str}), overriding
928 this point's C{epoch or B{reframe}.epoch}.
929 @kwarg epoch2: Optional epoch to observe for the converted point (L{Epoch},
930 C{scalar} or C{str}), otherwise B{C{epoch}}.
931 @kwarg height: Optional height, overriding the converted height (C{meter}).
932 @kwarg name: Optional name (C{str}), C{B{reframe2}.name} iff converted.
934 @return: The converted point (ellipsoidal C{LatLon}) or if conversion
935 C{isunity}, this point or a copy of this point if the B{C{name}}
936 is non-empty.
938 @raise TRFError: This point's C{reframe} is not defined, invalid B{C{epoch}}
939 or B{C{epoch2}} or conversion from this point's C{reframe}
940 to B{C{reframe2}} is not available.
942 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a L{RefFrame}.
943 '''
944 return _MODS.trf._toRefFrame(self, reframe2, reframe=reframe, epoch=epoch,
945 epoch2=epoch2, name=name, height=height)
947 def toTransform(self, transform, inverse=False, datum=None, **LatLon_kwds):
948 '''Apply a Helmert transform to this geodetic point.
950 @arg transform: Transform to apply (L{Transform} or L{TransformXform}).
951 @kwarg inverse: Apply the inverse of the Helmert transform (C{bool}).
952 @kwarg datum: Datum for the transformed point (L{Datum}), overriding
953 this point's datum but I{not} taken it into account.
954 @kwarg LatLon_kwds: Optional keyword arguments for the transformed
955 point, like C{B{height}=...}.
957 @return: A transformed point (C{LatLon}) or a copy of this point if
958 C{B{transform}.isunity}.
960 @raise TypeError: Invalid B{C{transform}}.
961 '''
962 _xinstanceof(Transform, transform=transform)
963 d = datum or self.datum
964 if transform.isunity:
965 r = self.dup(datum=d, **LatLon_kwds)
966 else:
967 c = self.toCartesian()
968 c = c.toTransform(transform, inverse=inverse, datum=d)
969 r = c.toLatLon(LatLon=self.classof, **_xkwds(LatLon_kwds, height=self.height))
970 return r
972 def toUps(self, pole=NN, falsed=True, center=False):
973 '''Convert this C{LatLon} point to a UPS coordinate.
975 @kwarg pole: Optional top/center of (stereographic)
976 projection (C{str}, 'N[orth]' or 'S[outh]').
977 @kwarg falsed: False easting and northing (C{bool}).
978 @kwarg center: If C{True}, I{un}-center the UPS
979 to its C{lowerleft} (C{bool}) or
980 by C{B{center} meter} (C{scalar}).
982 @return: The UPS coordinate (L{Ups}).
984 @see: Function L{pygeodesy.toUps8}.
985 '''
986 if self._upsOK(pole, falsed):
987 u = self._ups
988 else:
989 ups = _MODS.ups
990 u = ups.toUps8(self, datum=self.datum, Ups=ups.Ups,
991 pole=pole, falsed=falsed)
992 return _lowerleft(u, center)
994 def toUtm(self, center=False):
995 '''Convert this C{LatLon} point to a UTM coordinate.
997 @kwarg center: If C{True}, I{un}-center the UTM
998 to its C{lowerleft} (C{bool}) or
999 by C{B{center} meter} (C{scalar}).
1001 @return: The UTM coordinate (L{Utm}).
1003 @see: Method L{Mgrs.toUtm} and function L{pygeodesy.toUtm8}.
1004 '''
1005 return _lowerleft(self._utm, center)
1007 def toUtmUps(self, pole=NN, center=False):
1008 '''Convert this C{LatLon} point to a UTM or UPS coordinate.
1010 @kwarg pole: Optional top/center of UPS (stereographic)
1011 projection (C{str}, 'N[orth]' or 'S[outh]').
1012 @kwarg center: If C{True}, I{un}-center the UTM or UPS to
1013 its C{lowerleft} (C{bool}) or by C{B{center}
1014 meter} (C{scalar}).
1016 @return: The UTM or UPS coordinate (L{Utm} or L{Ups}).
1018 @see: Function L{pygeodesy.toUtmUps8}.
1019 '''
1020 if self._utmOK():
1021 u = self._utm
1022 elif self._upsOK(pole):
1023 u = self._ups
1024 else: # no cover
1025 utmups = _MODS.utmups
1026 u = utmups.toUtmUps8(self, datum=self.datum, pole=pole, name=self.name,
1027 Utm=utmups.Utm, Ups=utmups.Ups)
1028 if isinstance(u, utmups.Utm):
1029 self._update(False, _utm=u) # PYCHOK kwds
1030 elif isinstance(u, utmups.Ups):
1031 self._update(False, _ups=u) # PYCHOK kwds
1032 else:
1033 _xinstanceof(utmups.Utm, utmups.Ups, toUtmUps8=u)
1034 return _lowerleft(u, center)
1036 @deprecated_method
1037 def to3xyz(self): # PYCHOK no cover
1038 '''DEPRECATED, use method C{toEcef}.
1040 @return: A L{Vector3Tuple}C{(x, y, z)}.
1042 @note: Overloads C{LatLonBase.to3xyz}
1043 '''
1044 r = self.toEcef()
1045 return _MODS.namedTuples.Vector3Tuple(r.x, r.y, r.z, name=self.name)
1047 def triangulate(self, bearing1, other, bearing2, **height_wrap_tol):
1048 '''I{Iteratively} locate a point given this, an other point and the (initial)
1049 bearing at this and at the other point.
1051 @arg bearing1: Bearing at this point (compass C{degrees360}).
1052 @arg other: Start point of the other line (C{LatLon}).
1053 @arg bearing2: Bearing at the other point (compass C{degrees360}).
1054 @kwarg height_wrap_tol: Optional keyword arguments C{B{height}=None},
1055 C{B{wrap}=False} and C{B{tol}}, see method L{intersection3}.
1057 @return: Triangulated point (C{LatLon}).
1059 @see: Method L{intersection3} for further details.
1060 '''
1061 if _isDegrees(bearing1) and _isDegrees(bearing2):
1062 r = self.intersection3(bearing1, other, bearing2, **height_wrap_tol)
1063 return r.point
1064 raise _TypeError(bearing1=bearing1, bearing2=bearing2 **height_wrap_tol)
1066 def trilaterate5(self, distance1, point2, distance2, point3, distance3,
1067 area=True, eps=EPS1, wrap=False):
1068 '''Trilaterate three points by I{area overlap} or I{perimeter
1069 intersection} of three intersecting circles.
1071 @arg distance1: Distance to this point (C{meter}), same units
1072 as B{C{eps}}).
1073 @arg point2: Second center point (C{LatLon}).
1074 @arg distance2: Distance to point2 (C{meter}, same units as
1075 B{C{eps}}).
1076 @arg point3: Third center point (C{LatLon}).
1077 @arg distance3: Distance to point3 (C{meter}, same units as
1078 B{C{eps}}).
1079 @kwarg area: If C{True} compute the area overlap, otherwise the
1080 perimeter intersection of the circles (C{bool}).
1081 @kwarg eps: The required I{minimal overlap} for C{B{area}=True}
1082 or the I{intersection margin} for C{B{area}=False}
1083 (C{meter}, conventionally).
1084 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll
1085 B{C{point2}} and B{C{point3}} (C{bool}).
1087 @return: A L{Trilaterate5Tuple}C{(min, minPoint, max, maxPoint, n)}
1088 with C{min} and C{max} in C{meter}, same units as B{C{eps}},
1089 the corresponding trilaterated points C{minPoint} and
1090 C{maxPoint} as I{ellipsoidal} C{LatLon} and C{n}, the number
1091 of trilatered points found for the given B{C{eps}}.
1093 If only a single trilaterated point is found, C{min I{is}
1094 max}, C{minPoint I{is} maxPoint} and C{n = 1}.
1096 For C{B{area}=True}, C{min} and C{max} are the smallest
1097 respectively largest I{radial} overlap found.
1099 For C{B{area}=False}, C{min} and C{max} represent the
1100 nearest respectively farthest intersection margin.
1102 If C{B{area}=True} and all 3 circles are concentric, C{n=0}
1103 and C{minPoint} and C{maxPoint} are the B{C{point#}} with
1104 the smallest B{C{distance#}} C{min} respectively C{max} the
1105 largest B{C{distance#}}.
1107 @raise IntersectionError: Trilateration failed for the given B{C{eps}},
1108 insufficient overlap for C{B{area}=True}, no
1109 circle intersections for C{B{area}=False} or
1110 all circles are (near-)concentric.
1112 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.
1114 @raise ValueError: Coincident B{C{points}} or invalid B{C{distance1}},
1115 B{C{distance2}} or B{C{distance3}}.
1117 @note: Ellipsoidal trilateration invokes methods C{LatLon.intersections2}
1118 and C{LatLon.nearestOn} based on I{Karney}'s Python U{geographiclib
1119 <https://PyPI.org/project/geographiclib>} if installed, otherwise
1120 the accurate (but slower) C{ellipsoidalExact.LatLon} methods.
1121 '''
1122 return _trilaterate5(self, distance1,
1123 self.others(point2=point2), distance2,
1124 self.others(point3=point3), distance3,
1125 area=area, eps=eps, wrap=wrap)
1127 @Property_RO
1128 def _ups(self): # __dict__ value overwritten by method C{toUtmUps}
1129 '''(INTERNAL) Get this C{LatLon} point as UPS coordinate (L{Ups}),
1130 see L{pygeodesy.toUps8}.
1131 '''
1132 ups = _MODS.ups
1133 return ups.toUps8(self, datum=self.datum, Ups=ups.Ups,
1134 pole=NN, falsed=True, name=self.name)
1136 def _upsOK(self, pole=NN, falsed=True):
1137 '''(INTERNAL) Check matching C{Ups}.
1138 '''
1139 try:
1140 u = self._ups
1141 except RangeError:
1142 return False
1143 return falsed and (u.pole == pole[:1].upper() or not pole)
1145 @Property_RO
1146 def _utm(self): # __dict__ value overwritten by method C{toUtmUps}
1147 '''(INTERNAL) Get this C{LatLon} point as UTM coordinate (L{Utm}),
1148 see L{pygeodesy.toUtm8}.
1149 '''
1150 utm = _MODS.utm
1151 return utm.toUtm8(self, datum=self.datum, Utm=utm.Utm, name=self.name)
1153 def _utmOK(self):
1154 '''(INTERNAL) Check C{Utm}.
1155 '''
1156 try:
1157 _ = self._utm
1158 except RangeError:
1159 return False
1160 return True
1163def _lowerleft(utmups, center):
1164 '''(INTERNAL) Optionally I{un}-center C{utmups}.
1165 '''
1166 if center in (False, 0, _0_0):
1167 u = utmups
1168 elif center in (True,):
1169 u = utmups._lowerleft
1170 else:
1171 u = _MODS.utmupsBase._lowerleft(utmups, center)
1172 return u
1175def _nearestOn(point, point1, point2, within=True, height=None, wrap=False, # was=True
1176 equidistant=None, tol=_TOL_M, **LatLon_and_kwds):
1177 '''(INTERNAL) Get closest point, imported by .ellipsoidalExact,
1178 -GeodSolve, -Karney and -Vincenty to embellish exceptions.
1179 '''
1180 try:
1181 p = _xellipsoidal(point=point)
1182 t = _MODS.ellipsoidalBaseDI._nearestOn2(p, point1, point2, within=within,
1183 height=height, wrap=wrap,
1184 equidistant=equidistant,
1185 tol=tol, **LatLon_and_kwds)
1186 except (TypeError, ValueError) as x:
1187 raise _xError(x, point=point, point1=point1, point2=point2)
1188 return t.closest
1191def _set_reframe(inst, reframe):
1192 '''(INTERNAL) Set or clear an instance's reference frame.
1193 '''
1194 if reframe is not None:
1195 _xinstanceof(_MODS.trf.RefFrame, reframe=reframe)
1196 inst._reframe = reframe
1197 elif inst.reframe is not None:
1198 inst._reframe = None
1201__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)
1203# **) MIT License
1204#
1205# Copyright (C) 2016-2024 -- mrJean1 at Gmail -- All Rights Reserved.
1206#
1207# Permission is hereby granted, free of charge, to any person obtaining a
1208# copy of this software and associated documentation files (the "Software"),
1209# to deal in the Software without restriction, including without limitation
1210# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1211# and/or sell copies of the Software, and to permit persons to whom the
1212# Software is furnished to do so, subject to the following conditions:
1213#
1214# The above copyright notice and this permission notice shall be included
1215# in all copies or substantial portions of the Software.
1216#
1217# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1218# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1219# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1220# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1221# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1222# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1223# OTHER DEALINGS IN THE SOFTWARE.