Coverage for pygeodesy/ellipsoidalBase.py: 90%
284 statements
« prev ^ index » next coverage.py v7.2.2, created at 2024-06-10 14:08 -0400
« prev ^ index » next coverage.py v7.2.2, created at 2024-06-10 14:08 -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.06.06'
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, reframe=None, epoch=None,
50 **datum_ll_name):
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: Class L{CartesianBase<CartesianBase.__init__>} for more details.
65 '''
66 CartesianBase.__init__(self, x_xyz, y=y, z=z, **datum_ll_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):
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 C{B{name}=NN} (C{str}), overriding C{B{reframe2}.name}.
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)
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=_WGS84, reframe=None,
221 epoch=None, wrap=False, **name):
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 C{B{name}=NN} (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)
251 if datum not in (None, self._datum, _EWGS84):
252 self.datum = _ellipsoidal_datum(datum, name=self.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_doc_(''' this points's datum (L{Datum}).''')
294 def datum(self):
295 '''Get this point's datum (L{Datum}).
296 '''
297 return self._datum
299 @datum.setter # PYCHOK setter!
300 def datum(self, datum):
301 '''Set this point's datum I{without conversion} (L{Datum}).
303 @raise TypeError: The B{C{datum}} is not a L{Datum}
304 or not ellipsoidal.
305 '''
306 _xinstanceof(Datum, datum=datum)
307 if not datum.isEllipsoidal:
308 raise _IsnotError(_ellipsoidal_, datum=datum)
309 if self._datum != datum:
310 _update_all(self)
311 self._datum = datum
313 def distanceTo2(self, other, wrap=False):
314 '''I{Approximate} the distance and (initial) bearing between this
315 and an other (ellipsoidal) point based on the radii of curvature.
317 I{Suitable only for short distances up to a few hundred Km
318 or Miles and only between points not near-polar}.
320 @arg other: The other point (C{LatLon}).
321 @kwarg wrap: If C{True}, wrap or I{normalize} the B{C{other}}
322 point (C{bool}).
324 @return: An L{Distance2Tuple}C{(distance, initial)}.
326 @raise TypeError: The B{C{other}} point is not C{LatLon}.
328 @raise ValueError: Incompatible datum ellipsoids.
330 @see: Method L{Ellipsoid.distance2} and U{Local, flat earth
331 approximation<https://www.EdWilliams.org/avform.htm#flat>}
332 aka U{Hubeny<https://www.OVG.AT/de/vgi/files/pdf/3781/>}
333 formula.
334 '''
335 p = self.others(other)
336 if wrap:
337 p = _Wrap.point(p)
338 E = self.ellipsoids(other)
339 return E.distance2(*(self.latlon + p.latlon))
341 @Property_RO
342 def _elevation2(self):
343 '''(INTERNAL) Get elevation and data source.
344 '''
345 return _MODS.elevations.elevation2(self.lat, self.lon,
346 timeout=self._elevation2to)
348 def elevation2(self, adjust=True, datum=None, timeout=2):
349 '''Return elevation of this point for its or the given datum, ellipsoid
350 or sphere.
352 @kwarg adjust: Adjust the elevation for a B{C{datum}} other than
353 C{NAD83} (C{bool}).
354 @kwarg datum: Optional datum overriding this point's datum (L{Datum},
355 L{Ellipsoid}, L{Ellipsoid2}, L{a_f2Tuple} or C{scalar}
356 radius).
357 @kwarg timeout: Optional query timeout (C{seconds}).
359 @return: An L{Elevation2Tuple}C{(elevation, data_source)} or
360 C{(None, error)} in case of errors.
362 @note: The adjustment applied is the difference in geocentric earth
363 radius between the B{C{datum}} and C{NAV83} upon which the
364 L{elevations.elevation2} is based.
366 @note: NED elevation is only available for locations within the U{Conterminous
367 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}.
369 @see: Function L{elevations.elevation2} and method C{Ellipsoid.Rgeocentric}
370 for further details and possible C{error}s.
371 '''
372 if self._elevation2to != timeout:
373 self._elevation2to = timeout
374 LatLonEllipsoidalBase._elevation2._update(self)
375 return self._Radjust2(adjust, datum, self._elevation2)
377 def ellipsoid(self, datum=_WGS84):
378 '''Return the ellipsoid of this point's datum or the given datum.
380 @kwarg datum: Default datum (L{Datum}).
382 @return: The ellipsoid (L{Ellipsoid} or L{Ellipsoid2}).
383 '''
384 return _xattr(self, datum=datum).ellipsoid
386 @property_RO
387 def ellipsoidalLatLon(self):
388 '''Get this C{LatLon}'s ellipsoidal class.
389 '''
390 return type(self)
392 def ellipsoids(self, other):
393 '''Check the type and ellipsoid of this and an other point's datum.
395 @arg other: The other point (C{LatLon}).
397 @return: This point's datum ellipsoid (L{Ellipsoid} or L{Ellipsoid2}).
399 @raise TypeError: The B{C{other}} point is not C{LatLon}.
401 @raise ValueError: Incompatible datum ellipsoids.
402 '''
403 self.others(other, up=2) # ellipsoids' caller
405 E = self.ellipsoid()
406 try: # other may be Sphere, etc.
407 e = other.ellipsoid()
408 except AttributeError:
409 try: # no ellipsoid method, try datum
410 e = other.datum.ellipsoid
411 except AttributeError:
412 e = E # no datum, XXX assume equivalent?
413 if e != E:
414 raise _ValueError(e.named2, txt=_incompatible(E.named2))
415 return E
417 @property_doc_(''' this point's observed or C{reframe} epoch (C{float}).''')
418 def epoch(self):
419 '''Get this point's observed or C{reframe} epoch (L{Epoch}) or C{None}.
420 '''
421 return self._epoch or (self.reframe.epoch if self.reframe else None)
423 @epoch.setter # PYCHOK setter!
424 def epoch(self, epoch):
425 '''Set or clear this point's observed epoch, a fractional
426 calendar year (L{Epoch}, C{scalar} or C{str}) or C{None}.
428 @raise TRFError: Invalid B{C{epoch}}.
429 '''
430 self._epoch = None if epoch is None else Epoch(epoch)
432 @Property_RO
433 def Equidistant(self):
434 '''Get the prefered azimuthal equidistant projection I{class} (L{EquidistantKarney} or L{EquidistantExact}).
435 '''
436 try:
437 _ = self.datum.ellipsoid.geodesic
438 return _MODS.azimuthal.EquidistantKarney
439 except ImportError: # no geographiclib
440 return _MODS.azimuthal.EquidistantExact # XXX no longer L{azimuthal.Equidistant}
442 @Property_RO
443 def _etm(self):
444 '''(INTERNAL) Get this C{LatLon} point as an ETM coordinate (L{pygeodesy.toEtm8}).
445 '''
446 etm = _MODS.etm
447 return etm.toEtm8(self, datum=self.datum, Etm=etm.Etm)
449 @property_RO
450 def gamma(self):
451 '''Get this point's UTM or UPS meridian convergence (C{degrees}) or
452 C{None} if not available or not converted from L{Utm} or L{Ups}.
453 '''
454 return self._gamma
456 @Property_RO
457 def _geoidHeight2(self):
458 '''(INTERNAL) Get geoid height and model.
459 '''
460 return _MODS.elevations.geoidHeight2(self.lat, self.lon, model=0,
461 timeout=self._geoidHeight2to)
463 def geoidHeight2(self, adjust=False, datum=None, timeout=2):
464 '''Return geoid height of this point for its or the given datum, ellipsoid
465 or sphere.
467 @kwarg adjust: Adjust the geoid height for a B{C{datum}} other than
468 C{NAD83/NADV88} (C{bool}).
469 @kwarg datum: Optional datum overriding this point's datum (L{Datum},
470 L{Ellipsoid}, L{Ellipsoid2}, L{a_f2Tuple} or C{scalar}
471 radius).
472 @kwarg timeout: Optional query timeout (C{seconds}).
474 @return: A L{GeoidHeight2Tuple}C{(height, model_name)} or
475 C{(None, error)} in case of errors.
477 @note: The adjustment applied is the difference in geocentric earth
478 radius between the B{C{datum}} and C{NAV83/NADV88} upon which
479 the L{elevations.geoidHeight2} is based.
481 @note: The geoid height is only available for locations within the U{Conterminous
482 US (CONUS)<https://WikiPedia.org/wiki/Contiguous_United_States>}.
484 @see: Function L{elevations.geoidHeight2} and method C{Ellipsoid.Rgeocentric}
485 for further details and possible C{error}s.
486 '''
487 if self._geoidHeight2to != timeout:
488 self._geoidHeight2to = timeout
489 LatLonEllipsoidalBase._geoidHeight2._update(self)
490 return self._Radjust2(adjust, datum, self._geoidHeight2)
492 def intermediateTo(self, other, fraction, height=None, wrap=False): # PYCHOK no cover
493 '''I{Must be overloaded}.'''
494 self._notOverloaded(other, fraction, height=height, wrap=wrap)
496 def intersection3(self, end1, other, end2, height=None, wrap=False, # was=True
497 equidistant=None, tol=_TOL_M):
498 '''I{Iteratively} compute the intersection point of two lines, each
499 defined by two points or a start point and bearing from North.
501 @arg end1: End point of this line (C{LatLon}) or the initial
502 bearing at this point (compass C{degrees360}).
503 @arg other: Start point of the other line (C{LatLon}).
504 @arg end2: End point of the other line (C{LatLon}) or the initial
505 bearing at the other point (compass C{degrees360}).
506 @kwarg height: Optional height at the intersection (C{meter},
507 conventionally) or C{None} for the mean height.
508 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
509 B{C{other}} and B{C{end*}} points (C{bool}).
510 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
511 function L{pygeodesy.equidistant}), or C{None}
512 for this point's preferred C{.Equidistant}.
513 @kwarg tol: Tolerance for convergence and skew line distance and
514 length (C{meter}, conventionally).
516 @return: An L{Intersection3Tuple}C{(point, outside1, outside2)}
517 with C{point} a C{LatLon} instance.
519 @raise ImportError: Package U{geographiclib
520 <https://PyPI.org/project/geographiclib>}
521 not installed or not found, but only if
522 C{B{equidistant}=}L{EquidistantKarney}.
524 @raise IntersectionError: Skew, colinear, parallel or otherwise
525 non-intersecting lines or no convergence
526 for the given B{C{tol}}.
528 @raise TypeError: If B{C{end1}}, B{C{other}} or B{C{end2}} point
529 is not C{LatLon}.
531 @note: For each line specified with an initial bearing, a pseudo-end
532 point is computed as the C{destination} along that bearing at
533 about 1.5 times the distance from the start point to an initial
534 gu-/estimate of the intersection point (and between 1/8 and 3/8
535 of the authalic earth perimeter).
537 @see: I{Karney's} U{intersect.cpp<https://SourceForge.net/p/geographiclib/
538 discussion/1026621/thread/21aaff9f/>}, U{The B{ellipsoidal} case<https://
539 GIS.StackExchange.com/questions/48937/calculating-intersection-of-two-circles>}
540 and U{Karney's paper<https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section
541 B{14. MARITIME BOUNDARIES} for more details about the iteration algorithm.
542 '''
543 try:
544 s2 = self.others(other)
545 return _MODS.ellipsoidalBaseDI._intersect3(self, end1,
546 s2, end2,
547 height=height, wrap=wrap,
548 equidistant=equidistant, tol=tol,
549 LatLon=self.classof, datum=self.datum)
550 except (TypeError, ValueError) as x:
551 raise _xError(x, start1=self, end1=end1, other=other, end2=end2,
552 height=height, wrap=wrap, tol=tol)
554 def intersections2(self, radius1, other, radius2, height=None, wrap=False, # was=True
555 equidistant=None, tol=_TOL_M):
556 '''I{Iteratively} compute the intersection points of two circles,
557 each defined by a center point and a radius.
559 @arg radius1: Radius of this circle (C{meter}, conventionally).
560 @arg other: Center of the other circle (C{LatLon}).
561 @arg radius2: Radius of the other circle (C{meter}, same units as
562 B{C{radius1}}).
563 @kwarg height: Optional height for the intersection points (C{meter},
564 conventionally) or C{None} for the I{"radical height"}
565 at the I{radical line} between both centers.
566 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the B{C{other}}
567 center (C{bool}).
568 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
569 function L{pygeodesy.equidistant}) or C{None}
570 for this point's preferred C{.Equidistant}.
571 @kwarg tol: Convergence tolerance (C{meter}, same units as
572 B{C{radius1}} and B{C{radius2}}).
574 @return: 2-Tuple of the intersection points, each a C{LatLon}
575 instance. For abutting circles, both intersection
576 points are the same instance, aka the I{radical center}.
578 @raise ImportError: Package U{geographiclib
579 <https://PyPI.org/project/geographiclib>}
580 not installed or not found, but only if
581 C{B{equidistant}=}L{EquidistantKarney}.
583 @raise IntersectionError: Concentric, antipodal, invalid or
584 non-intersecting circles or no
585 convergence for the given B{C{tol}}.
587 @raise TypeError: Invalid B{C{other}} or B{C{equidistant}}.
589 @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.
591 @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
592 calculating-intersection-of-two-circles>}, U{Karney's paper
593 <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},
594 U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and
595 U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}
596 intersections.
597 '''
598 try:
599 c2 = self.others(other)
600 return _MODS.ellipsoidalBaseDI._intersections2(self, radius1,
601 c2, radius2,
602 height=height, wrap=wrap,
603 equidistant=equidistant, tol=tol,
604 LatLon=self.classof, datum=self.datum)
605 except (AssertionError, TypeError, ValueError) as x:
606 raise _xError(x, center=self, radius1=radius1, other=other, radius2=radius2,
607 height=height, wrap=wrap, tol=tol)
609 def isenclosedBy(self, points, wrap=False):
610 '''Check whether a polygon or composite encloses this point.
612 @arg points: The polygon points or clips (C{LatLon}[],
613 L{BooleanFHP} or L{BooleanGH}).
614 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
615 B{C{points}} (C{bool}).
617 @return: C{True} if this point is inside the polygon or composite,
618 C{False} otherwise.
620 @raise PointsError: Insufficient number of B{C{points}}.
622 @raise TypeError: Some B{C{points}} are not C{LatLon}.
624 @raise ValueError: Invalid B{C{point}}, lat- or longitude.
626 @see: Functions L{pygeodesy.isconvex}, L{pygeodesy.isenclosedBy}
627 and L{pygeodesy.ispolar} especially if the B{C{points}} may
628 enclose a pole or wrap around the earth I{longitudinally}.
629 '''
630 return _MODS.points.isenclosedBy(self, points, wrap=wrap)
632 @property_RO
633 def iteration(self):
634 '''Get the most recent C{intersections2} or C{nearestOn} iteration
635 number (C{int}) or C{None} if not available/applicable.
636 '''
637 return self._iteration
639 def midpointTo(self, other, height=None, fraction=_0_5, wrap=False):
640 '''Find the midpoint on a geodesic between this and an other point.
642 @arg other: The other point (C{LatLon}).
643 @kwarg height: Optional height for midpoint, overriding the
644 mean height (C{meter}).
645 @kwarg fraction: Midpoint location from this point (C{scalar}),
646 may be negative or greater than 1.0.
647 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
648 B{C{other}} point (C{bool}).
650 @return: Midpoint (C{LatLon}).
652 @raise TypeError: The B{C{other}} point is not C{LatLon}.
654 @raise ValueError: Invalid B{C{height}}.
656 @see: Methods C{intermediateTo} and C{rhumbMidpointTo}.
657 '''
658 return self.intermediateTo(other, fraction, height=height, wrap=wrap)
660 def nearestOn(self, point1, point2, within=True, height=None, wrap=False, # was=True
661 equidistant=None, tol=_TOL_M):
662 '''I{Iteratively} locate the closest point on the geodesic between
663 two other (ellipsoidal) points.
665 @arg point1: Start point (C{LatLon}).
666 @arg point2: End point (C{LatLon}).
667 @kwarg within: If C{True} return the closest point I{between}
668 B{C{point1}} and B{C{point2}}, otherwise the
669 closest point elsewhere on the geodesic (C{bool}).
670 @kwarg height: Optional height for the closest point (C{meter},
671 conventionally) or C{None} or C{False} for the
672 interpolated height. If C{False}, the closest
673 takes the heights of the points into account.
674 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both
675 B{C{point1}} and B{C{point2}} (C{bool}).
676 @kwarg equidistant: An azimuthal equidistant projection (I{class} or
677 function L{pygeodesy.equidistant}) or C{None}
678 for this point's preferred C{.Equidistant}.
679 @kwarg tol: Convergence tolerance (C{meter}, conventionally).
681 @return: Closest point (C{LatLon}).
683 @raise ImportError: Package U{geographiclib
684 <https://PyPI.org/project/geographiclib>}
685 not installed or not found, but only if
686 C{B{equidistant}=}L{EquidistantKarney}.
688 @raise TypeError: Invalid B{C{point1}}, B{C{point2}} or
689 B{C{equidistant}}.
691 @raise ValueError: Datum or ellipsoid of B{C{point1}} or B{C{point2}} is
692 incompatible 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 datum (L{RefFrame}), overriding this
723 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 r = self.classof(a, b, height=h, datum=self.datum)
735 if datum not in (None, self.datum):
736 r.datum = datum
737 if epoch not in (None, self.epoch):
738 r.epoch = epoch
739 if reframe not in (None, self.reframe):
740 r.reframe = reframe
741 return self._xnamed(r, force=True, **name) if name else r
743 def _Radjust2(self, adjust, datum, meter_text2):
744 '''(INTERNAL) Adjust an C{elevation} or C{geoidHeight} with
745 difference in Gaussian radii of curvature of the given
746 datum and NAD83 ellipsoids at this point's latitude.
748 @note: This is an arbitrary, possibly incorrect adjustment.
749 '''
750 if adjust: # Elevation2Tuple or GeoidHeight2Tuple
751 m, t = meter_text2
752 if isinstance(m, float) and fabs(m) > EPS:
753 n = Datums.NAD83.ellipsoid.rocGauss(self.lat)
754 if n > EPS0:
755 # use ratio, datum and NAD83 units may differ
756 E = self.ellipsoid() if datum in (None, self.datum) else \
757 _earth_ellipsoid(datum)
758 r = E.rocGauss(self.lat)
759 if r > EPS0 and fabs(r - n) > EPS: # EPS1
760 m *= r / n
761 meter_text2 = meter_text2.classof(m, t)
762 return self._xnamed(meter_text2)
764 @property_doc_(''' this point's reference frame (L{RefFrame}).''')
765 def reframe(self):
766 '''Get this point's reference frame (L{RefFrame}) or C{None}.
767 '''
768 return self._reframe
770 @reframe.setter # PYCHOK setter!
771 def reframe(self, reframe):
772 '''Set or clear this point's reference frame (L{RefFrame}) or C{None}.
774 @raise TypeError: The B{C{reframe}} is not a L{RefFrame}.
775 '''
776 _set_reframe(self, reframe)
778 @Property_RO
779 def scale(self):
780 '''Get this point's UTM grid or UPS point scale factor (C{float})
781 or C{None} if not converted from L{Utm} or L{Ups}.
782 '''
783 return self._scale
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 L{pygeodesy.toCss} keyword arguments.
802 @return: The Cassini-Soldner location (L{Css}).
804 @see: Function L{pygeodesy.toCss}.
805 '''
806 return _MODS.css.toCss(self, **self._name1__(toCss_kwds))
808 def toDatum(self, datum2, height=None, **name):
809 '''Convert this point to an other datum.
811 @arg datum2: Datum to convert I{to} (L{Datum}).
812 @kwarg height: Optional height, overriding the
813 converted height (C{meter}).
814 @kwarg name: Optional C{B{name}=NN} (C{str}).
816 @return: The converted point (ellipsoidal C{LatLon})
817 or a copy of this point if B{C{datum2}}
818 matches this point's C{datum}.
820 @raise TypeError: Invalid B{C{datum2}}.
821 '''
822 n = self._name__(name)
823 d2 = _ellipsoidal_datum(datum2, name=n)
824 if self.datum == d2:
825 r = self.copy(name=n)
826 else:
827 kwds = _xkwds_not(None, LatLon=self.classof, name=n,
828 epoch=self.epoch, reframe=self.reframe)
829 c = self.toCartesian().toDatum(d2)
830 r = c.toLatLon(datum=d2, height=height, **kwds)
831 return r
833 def toEtm(self, **toEtm8_kwds):
834 '''Convert this C{LatLon} point to an ETM coordinate.
836 @kwarg toEtm8_kwds: Optional L{pygeodesy.toEtm8} keyword arguments.
838 @return: The ETM coordinate (L{Etm}).
840 @see: Function L{pygeodesy.toEtm8}.
841 '''
842 return _MODS.etm.toEtm8(self, **self._name1__(toEtm8_kwds)) if toEtm8_kwds else self._etm
844 def toLcc(self, **toLcc_kwds):
845 '''Convert this C{LatLon} point to a Lambert location.
847 @kwarg toLcc_kwds: Optional L{pygeodesy.toLcc} keyword arguments.
849 @return: The Lambert location (L{Lcc}).
851 @see: Function L{pygeodesy.toLcc}.
852 '''
853 return _MODS.lcc.toLcc(self, **self._name1__(toLcc_kwds))
855 def toMgrs(self, center=False, pole=NN):
856 '''Convert this C{LatLon} point to an MGRS coordinate.
858 @kwarg center: If C{True}, try to I{un}-center MGRS
859 to its C{lowerleft} (C{bool}) or by
860 C{B{center} meter} (C{scalar}).
861 @kwarg pole: Optional top/center for the MGRS UPS
862 projection (C{str}, 'N[orth]' or 'S[outh]').
864 @return: The MGRS coordinate (L{Mgrs}).
866 @see: Method L{toUtmUps} and L{Mgrs.toLatLon}.
867 '''
868 return self.toUtmUps(center=center, pole=pole).toMgrs(center=False)
870 def toOsgr(self, kTM=False, **toOsgr_kwds):
871 '''Convert this C{LatLon} point to an OSGR coordinate.
873 @kwarg kTM: If C{True} use I{Karney}'s Krüger method from module
874 L{ktm}, otherwise I{Ordinance Survery}'s recommended
875 formulation (C{bool}).
876 @kwarg toOsgr_kwds: Optional L{pygeodesy.toOsgr} keyword arguments.
878 @return: The OSGR coordinate (L{Osgr}).
880 @see: Function L{pygeodesy.toOsgr}.
881 '''
882 return _MODS.osgr.toOsgr(self, kTM=kTM, **self._name1__(toOsgr_kwds))
884 def toRefFrame(self, reframe2, reframe=None, epoch=None, epoch2=None, height=None, **name):
885 '''Convert this point to an other reference frame and epoch.
887 @arg reframe2: Reference frame to convert I{to} (L{RefFrame}).
888 @kwarg reframe: Optional reference frame to convert I{from} (L{RefFrame}),
889 overriding this point's reference frame.
890 @kwarg epoch: Optional epoch (L{Epoch}, C{scalar} or C{str}), overriding
891 this point's C{epoch or B{reframe}.epoch}.
892 @kwarg epoch2: Optional epoch to observe for the converted point (L{Epoch},
893 C{scalar} or C{str}), otherwise B{C{epoch}}.
894 @kwarg height: Optional height, overriding the converted height (C{meter}).
895 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding C{B{reframe2}.name}.
897 @return: The converted point (ellipsoidal C{LatLon}) or if conversion
898 C{isunity}, this point or a copy of this point if the B{C{name}}
899 is non-empty.
901 @raise TRFError: This point's C{reframe} is not defined, invalid B{C{epoch}}
902 or B{C{epoch2}} or conversion from this point's C{reframe}
903 to B{C{reframe2}} is not available.
905 @raise TypeError: B{C{reframe2}} or B{C{reframe}} not a L{RefFrame}.
906 '''
907 return _MODS.trf._toRefFrame(self, reframe2, reframe=reframe, epoch=epoch,
908 epoch2=epoch2, height=height, **name)
910 def toTransform(self, transform, inverse=False, datum=None, **LatLon_kwds):
911 '''Apply a Helmert transform to this geodetic point.
913 @arg transform: Transform to apply (L{Transform} or L{TransformXform}).
914 @kwarg inverse: Apply the inverse of the Helmert transform (C{bool}).
915 @kwarg datum: Datum for the transformed point (L{Datum}), overriding
916 this point's datum but I{not} taken it into account.
917 @kwarg LatLon_kwds: Optional keyword arguments for the transformed
918 point, like C{B{height}=...}.
920 @return: A transformed point (C{LatLon}) or a copy of this point if
921 C{B{transform}.isunity}.
923 @raise TypeError: Invalid B{C{transform}}.
924 '''
925 _xinstanceof(Transform, transform=transform)
926 d = datum or self.datum
927 if transform.isunity:
928 r = self.dup(datum=d, **LatLon_kwds)
929 else:
930 c = self.toCartesian()
931 c = c.toTransform(transform, inverse=inverse, datum=d)
932 r = c.toLatLon(LatLon=self.classof, **_xkwds(LatLon_kwds, height=self.height))
933 return r
935 def toUps(self, pole=NN, falsed=True, center=False):
936 '''Convert this C{LatLon} point to a UPS coordinate.
938 @kwarg pole: Optional top/center of (stereographic)
939 projection (C{str}, 'N[orth]' or 'S[outh]').
940 @kwarg falsed: False easting and northing (C{bool}).
941 @kwarg center: If C{True}, I{un}-center the UPS
942 to its C{lowerleft} (C{bool}) or
943 by C{B{center} meter} (C{scalar}).
945 @return: The UPS coordinate (L{Ups}).
947 @see: Function L{pygeodesy.toUps8}.
948 '''
949 if self._upsOK(pole, falsed):
950 u = self._ups
951 else:
952 ups = _MODS.ups
953 u = ups.toUps8(self, datum=self.datum, Ups=ups.Ups,
954 pole=pole, falsed=falsed)
955 return _lowerleft(u, center)
957 def toUtm(self, center=False):
958 '''Convert this C{LatLon} point to a UTM coordinate.
960 @kwarg center: If C{True}, I{un}-center the UTM
961 to its C{lowerleft} (C{bool}) or
962 by C{B{center} meter} (C{scalar}).
964 @return: The UTM coordinate (L{Utm}).
966 @see: Method L{Mgrs.toUtm} and function L{pygeodesy.toUtm8}.
967 '''
968 return _lowerleft(self._utm, center)
970 def toUtmUps(self, pole=NN, center=False):
971 '''Convert this C{LatLon} point to a UTM or UPS coordinate.
973 @kwarg pole: Optional top/center of UPS (stereographic)
974 projection (C{str}, 'N[orth]' or 'S[outh]').
975 @kwarg center: If C{True}, I{un}-center the UTM or UPS to
976 its C{lowerleft} (C{bool}) or by C{B{center}
977 meter} (C{scalar}).
979 @return: The UTM or UPS coordinate (L{Utm} or L{Ups}).
981 @see: Function L{pygeodesy.toUtmUps8}.
982 '''
983 if self._utmOK():
984 u = self._utm
985 elif self._upsOK(pole):
986 u = self._ups
987 else: # no cover
988 utmups = _MODS.utmups
989 u = utmups.toUtmUps8(self, datum=self.datum, pole=pole, name=self.name,
990 Utm=utmups.Utm, Ups=utmups.Ups)
991 if isinstance(u, utmups.Utm):
992 self._update(False, _utm=u) # PYCHOK kwds
993 elif isinstance(u, utmups.Ups):
994 self._update(False, _ups=u) # PYCHOK kwds
995 else:
996 _xinstanceof(utmups.Utm, utmups.Ups, toUtmUps8=u)
997 return _lowerleft(u, center)
999 @deprecated_method
1000 def to3xyz(self): # PYCHOK no cover
1001 '''DEPRECATED, use method C{toEcef}.
1003 @return: A L{Vector3Tuple}C{(x, y, z)}.
1005 @note: Overloads C{LatLonBase.to3xyz}
1006 '''
1007 r = self.toEcef()
1008 return _MODS.namedTuples.Vector3Tuple(r.x, r.y, r.z, name=self.name)
1010 def triangulate(self, bearing1, other, bearing2, **height_wrap_tol):
1011 '''I{Iteratively} locate a point given this, an other point and the (initial)
1012 bearing at this and at the other point.
1014 @arg bearing1: Bearing at this point (compass C{degrees360}).
1015 @arg other: Start point of the other line (C{LatLon}).
1016 @arg bearing2: Bearing at the other point (compass C{degrees360}).
1017 @kwarg height_wrap_tol: Optional keyword arguments C{B{height}=None},
1018 C{B{wrap}=False} and C{B{tol}}, see method L{intersection3}.
1020 @return: Triangulated point (C{LatLon}).
1022 @see: Method L{intersection3} for further details.
1023 '''
1024 if _isDegrees(bearing1) and _isDegrees(bearing2):
1025 r = self.intersection3(bearing1, other, bearing2, **height_wrap_tol)
1026 return r.point
1027 raise _TypeError(bearing1=bearing1, bearing2=bearing2 **height_wrap_tol)
1029 def trilaterate5(self, distance1, point2, distance2, point3, distance3,
1030 area=True, eps=EPS1, wrap=False):
1031 '''Trilaterate three points by I{area overlap} or I{perimeter
1032 intersection} of three intersecting circles.
1034 @arg distance1: Distance to this point (C{meter}), same units
1035 as B{C{eps}}).
1036 @arg point2: Second center point (C{LatLon}).
1037 @arg distance2: Distance to point2 (C{meter}, same units as
1038 B{C{eps}}).
1039 @arg point3: Third center point (C{LatLon}).
1040 @arg distance3: Distance to point3 (C{meter}, same units as
1041 B{C{eps}}).
1042 @kwarg area: If C{True} compute the area overlap, otherwise the
1043 perimeter intersection of the circles (C{bool}).
1044 @kwarg eps: The required I{minimal overlap} for C{B{area}=True}
1045 or the I{intersection margin} for C{B{area}=False}
1046 (C{meter}, conventionally).
1047 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll
1048 B{C{point2}} and B{C{point3}} (C{bool}).
1050 @return: A L{Trilaterate5Tuple}C{(min, minPoint, max, maxPoint, n)}
1051 with C{min} and C{max} in C{meter}, same units as B{C{eps}},
1052 the corresponding trilaterated points C{minPoint} and
1053 C{maxPoint} as I{ellipsoidal} C{LatLon} and C{n}, the number
1054 of trilatered points found for the given B{C{eps}}.
1056 If only a single trilaterated point is found, C{min I{is}
1057 max}, C{minPoint I{is} maxPoint} and C{n = 1}.
1059 For C{B{area}=True}, C{min} and C{max} are the smallest
1060 respectively largest I{radial} overlap found.
1062 For C{B{area}=False}, C{min} and C{max} represent the
1063 nearest respectively farthest intersection margin.
1065 If C{B{area}=True} and all 3 circles are concentric, C{n=0}
1066 and C{minPoint} and C{maxPoint} are the B{C{point#}} with
1067 the smallest B{C{distance#}} C{min} respectively C{max} the
1068 largest B{C{distance#}}.
1070 @raise IntersectionError: Trilateration failed for the given B{C{eps}},
1071 insufficient overlap for C{B{area}=True}, no
1072 circle intersections for C{B{area}=False} or
1073 all circles are (near-)concentric.
1075 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.
1077 @raise ValueError: Coincident B{C{points}} or invalid B{C{distance1}},
1078 B{C{distance2}} or B{C{distance3}}.
1080 @note: Ellipsoidal trilateration invokes methods C{LatLon.intersections2}
1081 and C{LatLon.nearestOn} based on I{Karney}'s Python U{geographiclib
1082 <https://PyPI.org/project/geographiclib>} if installed, otherwise
1083 the accurate (but slower) C{ellipsoidalExact.LatLon} methods.
1084 '''
1085 return _trilaterate5(self, distance1,
1086 self.others(point2=point2), distance2,
1087 self.others(point3=point3), distance3,
1088 area=area, eps=eps, wrap=wrap)
1090 @Property_RO
1091 def _ups(self): # __dict__ value overwritten by method C{toUtmUps}
1092 '''(INTERNAL) Get this C{LatLon} point as UPS coordinate (L{Ups}),
1093 see L{pygeodesy.toUps8}.
1094 '''
1095 ups = _MODS.ups
1096 return ups.toUps8(self, datum=self.datum, Ups=ups.Ups,
1097 pole=NN, falsed=True, name=self.name)
1099 def _upsOK(self, pole=NN, falsed=True):
1100 '''(INTERNAL) Check matching C{Ups}.
1101 '''
1102 try:
1103 u = self._ups
1104 except RangeError:
1105 return False
1106 return falsed and (u.pole == pole[:1].upper() or not pole)
1108 @Property_RO
1109 def _utm(self): # __dict__ value overwritten by method C{toUtmUps}
1110 '''(INTERNAL) Get this C{LatLon} point as UTM coordinate (L{Utm}),
1111 see L{pygeodesy.toUtm8}.
1112 '''
1113 utm = _MODS.utm
1114 return utm.toUtm8(self, datum=self.datum, Utm=utm.Utm, name=self.name)
1116 def _utmOK(self):
1117 '''(INTERNAL) Check C{Utm}.
1118 '''
1119 try:
1120 _ = self._utm
1121 except RangeError:
1122 return False
1123 return True
1126def _lowerleft(utmups, center):
1127 '''(INTERNAL) Optionally I{un}-center C{utmups}.
1128 '''
1129 if center in (False, 0, _0_0):
1130 u = utmups
1131 elif center in (True,):
1132 u = utmups._lowerleft
1133 else:
1134 u = _MODS.utmupsBase._lowerleft(utmups, center)
1135 return u
1138def _nearestOn(point, point1, point2, within=True, height=None, wrap=False, # was=True
1139 equidistant=None, tol=_TOL_M, **LatLon_and_kwds):
1140 '''(INTERNAL) Get closest point, imported by .ellipsoidalExact,
1141 -GeodSolve, -Karney and -Vincenty to embellish exceptions.
1142 '''
1143 try:
1144 p = _xellipsoidal(point=point)
1145 t = _MODS.ellipsoidalBaseDI._nearestOn2(p, point1, point2, within=within,
1146 height=height, wrap=wrap,
1147 equidistant=equidistant,
1148 tol=tol, **LatLon_and_kwds)
1149 except (TypeError, ValueError) as x:
1150 raise _xError(x, point=point, point1=point1, point2=point2)
1151 return t.closest
1154def _set_reframe(inst, reframe):
1155 '''(INTERNAL) Set or clear an instance's reference frame.
1156 '''
1157 if reframe is not None:
1158 _xinstanceof(_MODS.trf.RefFrame, reframe=reframe)
1159 inst._reframe = reframe
1160 elif inst.reframe is not None:
1161 inst._reframe = None
1164__all__ += _ALL_DOCS(CartesianEllipsoidalBase, LatLonEllipsoidalBase)
1166# **) MIT License
1167#
1168# Copyright (C) 2016-2024 -- mrJean1 at Gmail -- All Rights Reserved.
1169#
1170# Permission is hereby granted, free of charge, to any person obtaining a
1171# copy of this software and associated documentation files (the "Software"),
1172# to deal in the Software without restriction, including without limitation
1173# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1174# and/or sell copies of the Software, and to permit persons to whom the
1175# Software is furnished to do so, subject to the following conditions:
1176#
1177# The above copyright notice and this permission notice shall be included
1178# in all copies or substantial portions of the Software.
1179#
1180# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1181# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1182# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1183# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1184# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1185# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1186# OTHER DEALINGS IN THE SOFTWARE.