Coverage for pygeodesy/latlonBase.py: 93%
435 statements
« prev ^ index » next coverage.py v7.2.2, created at 2023-09-01 13:41 -0400
« prev ^ index » next coverage.py v7.2.2, created at 2023-09-01 13:41 -0400
2# -*- coding: utf-8 -*-
4u'''(INTERNAL) Base class L{LatLonBase} for all elliposiodal, spherical and N-vectorial C{LatLon} classes.
6@see: I{(C) Chris Veness}' U{latlong<https://www.Movable-Type.co.UK/scripts/latlong.html>},
7 U{-ellipsoidal<https://www.Movable-Type.co.UK/scripts/geodesy/docs/latlon-ellipsoidal.js.html>} and
8 U{-vectors<https://www.Movable-Type.co.UK/scripts/latlong-vectors.html>} and I{Charles Karney}'s
9 U{Rhumb<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1Rhumb.html>} and
10 U{RhumbLine<https://GeographicLib.SourceForge.io/C++/doc/classGeographicLib_1_1RhumbLine.html>} classes.
11'''
13from pygeodesy.basics import isscalar, isstr, map1, _xinstanceof
14from pygeodesy.constants import EPS, EPS0, EPS1, EPS4, INT0, R_M, \
15 _0_0, _0_5, _1_0
16# from pygeodesy.datums import _spherical_datum # from .formy
17from pygeodesy.dms import F_D, F_DMS, latDMS, lonDMS, parse3llh
18# from pygeodesy.ecef import EcefKarney # _MODS
19from pygeodesy.errors import _incompatible, IntersectionError, _IsnotError, \
20 _TypeError, _ValueError, _xdatum, _xError, \
21 _xkwds, _xkwds_not
22# from pygeodesy.fmath import favg # _MODS
23from pygeodesy.formy import antipode, compassAngle, cosineAndoyerLambert_, \
24 cosineForsytheAndoyerLambert_, cosineLaw, \
25 equirectangular, euclidean, flatLocal_, \
26 flatPolar, hartzell, haversine, isantipode, \
27 _isequalTo, isnormal, normal, philam2n_xyz, \
28 thomas_, vincentys, _spherical_datum
29from pygeodesy.interns import NN, _COMMASPACE_, _concentric_, _height_, \
30 _intersection_, _m_, _LatLon_, _no_, \
31 _overlap_, _point_ # PYCHOK used!
32# from pygeodesy.iters import PointsIter, points2 # from .vector3d, _MODS
33# from pygeodesy.karney import Caps # _MODS
34from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS
35# from pygeodesy.ltp import Ltp, _xLtp # _MODS
36from pygeodesy.named import _NamedBase, notOverloaded, Fmt
37from pygeodesy.namedTuples import Bounds2Tuple, LatLon2Tuple, PhiLam2Tuple, \
38 Trilaterate5Tuple, Vector3Tuple
39# from pygeodesy.nvectorBase import _N_vector_ # _MODS
40from pygeodesy.props import deprecated_method, Property, Property_RO, \
41 property_RO, _update_all
42# from pygeodesy.streprs import Fmt, hstr # from .named, _MODS
43from pygeodesy.units import Distance_, Lat, Lon, Height, Radius, Radius_, \
44 Scalar, Scalar_
45from pygeodesy.utily import _unrollon, _unrollon3, _Wrap
46from pygeodesy.vector2d import _circin6, Circin6Tuple, _circum3, circum4_, \
47 Circum3Tuple, _radii11ABC
48from pygeodesy.vector3d import nearestOn6, Vector3d, PointsIter
50from contextlib import contextmanager
51from math import asin, cos, degrees, fabs, radians
53__all__ = _ALL_LAZY.latlonBase
54__version__ = '23.08.09'
57class LatLonBase(_NamedBase):
58 '''(INTERNAL) Base class for C{LatLon} points on spherical or
59 ellipsoidal earth models.
60 '''
61 _clipid = INT0 # polygonal clip, see .booleans
62 _datum = None # L{Datum}, to be overriden
63 _height = INT0 # height (C{meter}), default
64 _lat = 0 # latitude (C{degrees})
65 _lon = 0 # longitude (C{degrees})
67 def __init__(self, latlonh, lon=None, height=0, wrap=False, name=NN):
68 '''New C{LatLon}.
70 @arg latlonh: Latitude (C{degrees} or DMS C{str} with N or S suffix) or
71 a previous C{LatLon} instance provided C{B{lon}=None}.
72 @kwarg lon: Longitude (C{degrees} or DMS C{str} with E or W suffix) or
73 C(None), indicating B{C{latlonh}} is a C{LatLon}.
74 @kwarg height: Optional height above (or below) the earth surface
75 (C{meter}, conventionally).
76 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{lat}} and B{C{lon}}
77 (C{bool}).
78 @kwarg name: Optional name (C{str}).
80 @return: New instance (C{LatLon}).
82 @raise RangeError: A B{C{lon}} or C{lat} value outside the valid
83 range and L{rangerrors} set to C{True}.
85 @raise TypeError: If B{C{latlonh}} is not a C{LatLon}.
87 @raise UnitError: Invalid B{C{lat}}, B{C{lon}} or B{C{height}}.
89 @example:
91 >>> p = LatLon(50.06632, -5.71475)
92 >>> q = LatLon('50°03′59″N', """005°42'53"W""")
93 >>> r = LatLon(p)
94 '''
95 if name:
96 self.name = name
98 if lon is None:
99 try:
100 lat, lon = latlonh.lat, latlonh.lon
101 height = latlonh.get(_height_, height)
102 except AttributeError:
103 raise _IsnotError(_LatLon_, latlonh=latlonh)
104 if wrap:
105 lat, lon = _Wrap.latlon(lat, lon)
106 elif wrap:
107 lat, lon = _Wrap.latlonDMS2(latlonh, lon)
108 else:
109 lat = latlonh
111 self._lat = Lat(lat) # parseDMS2(lat, lon)
112 self._lon = Lon(lon) # PYCHOK LatLon2Tuple
113 if height: # elevation
114 self._height = Height(height)
116 def __eq__(self, other):
117 return self.isequalTo(other)
119 def __ne__(self, other):
120 return not self.isequalTo(other)
122 def __str__(self):
123 return self.toStr(form=F_D, prec=6)
125 def antipode(self, height=None):
126 '''Return the antipode, the point diametrically opposite
127 to this point.
129 @kwarg height: Optional height of the antipode (C{meter}),
130 this point's height otherwise.
132 @return: The antipodal point (C{LatLon}).
133 '''
134 h = self._heigHt(height)
135 return self.classof(*antipode(*self.latlon), height=h)
137 @deprecated_method
138 def bounds(self, wide, tall, radius=R_M): # PYCHOK no cover
139 '''DEPRECATED, use method C{boundsOf}.'''
140 return self.boundsOf(wide, tall, radius=radius)
142 def boundsOf(self, wide, tall, radius=R_M, height=None):
143 '''Return the SW and NE lat-/longitude of a great circle
144 bounding box centered at this location.
146 @arg wide: Longitudinal box width (C{meter}, same units as
147 B{C{radius}} or C{degrees} if B{C{radius}} is C{None}).
148 @arg tall: Latitudinal box size (C{meter}, same units as
149 B{C{radius}} or C{degrees} if B{C{radius}} is C{None}).
150 @kwarg radius: Mean earth radius (C{meter}) or C{None} if I{both}
151 B{C{wide}} and B{C{tall}} are in C{degrees}.
152 @kwarg height: Height for C{latlonSW} and C{latlonNE} (C{meter}),
153 overriding the point's height.
155 @return: A L{Bounds2Tuple}C{(latlonSW, latlonNE)}, the
156 lower-left and upper-right corner (C{LatLon}).
158 @see: U{https://www.Movable-Type.co.UK/scripts/latlong-db.html}
159 '''
160 w = Scalar_(wide=wide) * _0_5
161 t = Scalar_(tall=tall) * _0_5
162 if radius is not None:
163 r = Radius_(radius)
164 c = cos(self.phi)
165 w = degrees(asin(w / r) / c) if fabs(c) > EPS0 else _0_0 # XXX
166 t = degrees(t / r)
167 y, t = self.lat, fabs(t)
168 x, w = self.lon, fabs(w)
170 h = self._heigHt(height)
171 sw = self.classof(y - t, x - w, height=h)
172 ne = self.classof(y + t, x + w, height=h)
173 return Bounds2Tuple(sw, ne, name=self.name)
175 def chordTo(self, other, height=None, wrap=False):
176 '''Compute the length of the chord through the earth between
177 this and an other point.
179 @arg other: The other point (C{LatLon}).
180 @kwarg height: Overriding height for both points (C{meter})
181 or C{None} for each point's height.
182 @kwarg wrap: If C{True}, wrap or I{normalize} the B{C{other}}
183 point (C{bool}).
185 @return: The chord length (conventionally C{meter}).
187 @raise TypeError: The B{C{other}} point is not C{LatLon}.
188 '''
189 def _v3d(ll):
190 t = ll.toEcef(height=height) # .toVector(Vector=Vector3d)
191 return Vector3d(t.x, t.y, t.z)
193 p = self.others(other)
194 if wrap:
195 p = _Wrap.point(p)
196 return _v3d(self).minus(_v3d(p)).length
198 def circin6(self, point2, point3, eps=EPS4, wrap=False):
199 '''Return the radius and center of the I{inscribed} aka I{In-}circle
200 of the (planar) triangle formed by this and two other points.
202 @arg point2: Second point (C{LatLon}).
203 @arg point3: Third point (C{LatLon}).
204 @kwarg eps: Tolerance for function L{pygeodesy.trilaterate3d2}.
205 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{point2}} and
206 B{C{point3}} (C{bool}).
208 @return: L{Circin6Tuple}C{(radius, center, deltas, cA, cB, cC)}. The
209 C{center} and contact points C{cA}, C{cB} and C{cC}, each an
210 instance of this (sub-)class, are co-planar with this and the
211 two given points, see the B{Note} below.
213 @raise ImportError: Package C{numpy} not found, not installed or older
214 than version 1.10.
216 @raise IntersectionError: Near-coincident or -colinear points or
217 a trilateration or C{numpy} issue.
219 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.
221 @note: The C{center} is trilaterated in cartesian (ECEF) space and converted
222 back to geodetic lat-, longitude and height. The latter, conventionally
223 in C{meter} indicates whether the C{center} is above, below or on the
224 surface of the earth model. If C{deltas} is C{None}, the C{center} is
225 I{un}ambigous. Otherwise C{deltas} is a L{LatLon3Tuple}C{(lat, lon,
226 height)} representing the differences between both results from
227 L{pygeodesy.trilaterate3d2} and C{center} is the mean thereof.
229 @see: Function L{pygeodesy.circin6}, method L{circum3}, U{Incircle
230 <https://MathWorld.Wolfram.com/Incircle.html>} and U{Contact Triangle
231 <https://MathWorld.Wolfram.com/ContactTriangle.html>}.
232 '''
233 with _toCartesian3(self, point2, point3, wrap) as cs:
234 r, c, d, cA, cB, cC = _circin6(*cs, eps=eps, useZ=True, dLL3=True,
235 datum=self.datum) # PYCHOK unpack
236 return Circin6Tuple(r, c.toLatLon(), d, cA.toLatLon(), cB.toLatLon(), cC.toLatLon())
238 def circum3(self, point2, point3, circum=True, eps=EPS4, wrap=False):
239 '''Return the radius and center of the smallest circle I{through} or I{containing}
240 this and two other points.
242 @arg point2: Second point (C{LatLon}).
243 @arg point3: Third point (C{LatLon}).
244 @kwarg circum: If C{True} return the C{circumradius} and C{circumcenter},
245 always, ignoring the I{Meeus}' Type I case (C{bool}).
246 @kwarg eps: Tolerance for function L{pygeodesy.trilaterate3d2}.
247 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{point2}} and
248 B{C{point3}} (C{bool}).
250 @return: A L{Circum3Tuple}C{(radius, center, deltas)}. The C{center}, an
251 instance of this (sub-)class, is co-planar with this and the two
252 given points. If C{deltas} is C{None}, the C{center} is
253 I{un}ambigous. Otherwise C{deltas} is a L{LatLon3Tuple}C{(lat,
254 lon, height)} representing the difference between both results
255 from L{pygeodesy.trilaterate3d2} and C{center} is the mean thereof.
257 @raise ImportError: Package C{numpy} not found, not installed or older than
258 version 1.10.
260 @raise IntersectionError: Near-concentric, -coincident or -colinear points,
261 incompatible C{Ecef} classes or a trilateration
262 or C{numpy} issue.
264 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.
266 @note: The C{center} is trilaterated in cartesian (ECEF) space and converted
267 back to geodetic lat-, longitude and height. The latter, conventionally
268 in C{meter} indicates whether the C{center} is above, below or on the
269 surface of the earth model. If C{deltas} is C{None}, the C{center} is
270 I{un}ambigous. Otherwise C{deltas} is a L{LatLon3Tuple}C{(lat, lon,
271 height)} representing the difference between both results from
272 L{pygeodesy.trilaterate3d2} and C{center} is the mean thereof.
274 @see: Function L{pygeodesy.circum3} and methods L{circin6} and L{circum4_}.
275 '''
276 with _toCartesian3(self, point2, point3, wrap, circum=circum) as cs:
277 r, c, d = _circum3(*cs, circum=circum, eps=eps, useZ=True, dLL3=True, # XXX -3d2
278 clas=cs[0].classof, datum=self.datum) # PYCHOK unpack
279 return Circum3Tuple(r, c.toLatLon(), d)
281 def circum4_(self, *points, **wrap):
282 '''Best-fit a sphere through this and two or more other points.
284 @arg points: The other points (each a C{LatLon}).
285 @kwarg wrap: If C{True}, wrap or I{normalize} the B{C{points}}
286 (C{bool}), default C{False}.
288 @return: L{Circum4Tuple}C{(radius, center, rank, residuals)} with C{center}
289 an instance of this (sub-)class.
291 @raise ImportError: Package C{numpy} not found, not installed or older than
292 version 1.10.
294 @raise NumPyError: Some C{numpy} issue.
296 @raise TypeError: One of the B{C{points}} invalid.
298 @raise ValueError: Too few B{C{points}}.
300 @see: Function L{pygeodesy.circum4_} and L{circum3}.
301 '''
302 def _cs(ps, C, wrap=False):
303 _wp = _Wrap.point if wrap else (lambda p: p)
304 for i, p in enumerate(ps):
305 yield C(i=i, points=_wp(p))
307 C = self._toCartesianEcef
308 c = C(point=self)
309 t = circum4_(c, Vector=c.classof, *_cs(points, C, **wrap))
310 c = t.center.toLatLon(LatLon=self.classof)
311 return t.dup(center=c)
313 @property
314 def clipid(self):
315 '''Get the (polygonal) clip (C{int}).
316 '''
317 return self._clipid
319 @clipid.setter # PYCHOK setter!
320 def clipid(self, clipid):
321 '''Get the (polygonal) clip (C{int}).
322 '''
323 self._clipid = int(clipid)
325 @deprecated_method
326 def compassAngle(self, other, **adjust_wrap): # PYCHOK no cover
327 '''DEPRECATED, use method L{compassAngleTo}.'''
328 return self.compassAngleTo(other, **adjust_wrap)
330 def compassAngleTo(self, other, **adjust_wrap):
331 '''Return the angle from North for the direction vector between
332 this and an other point.
334 Suitable only for short, non-near-polar vectors up to a few
335 hundred Km or Miles. Use method C{initialBearingTo} for
336 larger distances.
338 @arg other: The other point (C{LatLon}).
339 @kwarg adjust_wrap: Optional keyword arguments for function
340 L{pygeodesy.compassAngle}.
342 @return: Compass angle from North (C{degrees360}).
344 @raise TypeError: The B{C{other}} point is not C{LatLon}.
346 @note: Courtesy of Martin Schultz.
348 @see: U{Local, flat earth approximation
349 <https://www.EdWilliams.org/avform.htm#flat>}.
350 '''
351 p = self.others(other)
352 return compassAngle(self.lat, self.lon, p.lat, p.lon, **adjust_wrap)
354 def cosineAndoyerLambertTo(self, other, wrap=False):
355 '''Compute the distance between this and an other point using the U{Andoyer-Lambert correction<https://
356 navlib.net/wp-content/uploads/2013/10/admiralty-manual-of-navigation-vol-1-1964-english501c.pdf>}
357 of the U{Law of Cosines<https://www.Movable-Type.co.UK/scripts/latlong.html#cosine-law>} formula.
359 @arg other: The other point (C{LatLon}).
360 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll
361 the B{C{other}} point (C{bool}).
363 @return: Distance (C{meter}, same units as the axes of this
364 point's datum ellipsoid).
366 @raise TypeError: The B{C{other}} point is not C{LatLon}.
368 @see: Function L{pygeodesy.cosineAndoyerLambert} and methods
369 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo},
370 C{distanceTo*}, L{equirectangularTo}, L{euclideanTo},
371 L{flatLocalTo}/L{hubenyTo}, L{flatPolarTo}, L{haversineTo},
372 L{thomasTo} and L{vincentysTo}.
373 '''
374 return self._distanceTo_(cosineAndoyerLambert_, other, wrap=wrap)
376 def cosineForsytheAndoyerLambertTo(self, other, wrap=False):
377 '''Compute the distance between this and an other point using
378 the U{Forsythe-Andoyer-Lambert correction
379 <https://www2.UNB.Ca/gge/Pubs/TR77.pdf>} of the U{Law of Cosines
380 <https://www.Movable-Type.co.UK/scripts/latlong.html#cosine-law>}
381 formula.
383 @arg other: The other point (C{LatLon}).
384 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll
385 the B{C{other}} point (C{bool}).
387 @return: Distance (C{meter}, same units as the axes of
388 this point's datum ellipsoid).
390 @raise TypeError: The B{C{other}} point is not C{LatLon}.
392 @see: Function L{pygeodesy.cosineForsytheAndoyerLambert} and methods
393 L{cosineAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},
394 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},
395 L{flatPolarTo}, L{haversineTo}, L{thomasTo} and L{vincentysTo}.
396 '''
397 return self._distanceTo_(cosineForsytheAndoyerLambert_, other, wrap=wrap)
399 def cosineLawTo(self, other, radius=None, wrap=False):
400 '''Compute the distance between this and an other point using the
401 U{spherical Law of Cosines
402 <https://www.Movable-Type.co.UK/scripts/latlong.html#cosine-law>}
403 formula.
405 @arg other: The other point (C{LatLon}).
406 @kwarg radius: Mean earth radius (C{meter}) or C{None}
407 for the mean radius of this point's datum
408 ellipsoid.
409 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll
410 the B{C{other}} point (C{bool}).
412 @return: Distance (C{meter}, same units as B{C{radius}}).
414 @raise TypeError: The B{C{other}} point is not C{LatLon}.
416 @see: Function L{pygeodesy.cosineLaw} and methods L{cosineAndoyerLambertTo},
417 L{cosineForsytheAndoyerLambertTo}, C{distanceTo*}, L{equirectangularTo},
418 L{euclideanTo}, L{flatLocalTo}/L{hubenyTo}, L{flatPolarTo},
419 L{haversineTo}, L{thomasTo} and L{vincentysTo}.
420 '''
421 return self._distanceTo(cosineLaw, other, radius, wrap=wrap)
423 @property_RO
424 def datum(self): # PYCHOK no cover
425 '''(INTERNAL) I{Must be overloaded}, see function C{notOverloaded}.
426 '''
427 notOverloaded(self)
429 def destinationXyz(self, delta, LatLon=None, **LatLon_kwds):
430 '''Calculate the destination using a I{local} delta from this point.
432 @arg delta: Local delta to the destination (L{XyzLocal}, L{Enu},
433 L{Ned} or L{Local9Tuple}).
434 @kwarg LatLon: Optional (geodetic) class to return the destination
435 or C{None}.
436 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword
437 arguments, ignored if C{B{LatLon} is None}.
439 @return: Destination as a C{B{LatLon}(lat, lon, **B{LatLon_kwds})}
440 instance or if C{B{LatLon} is None}, a L{LatLon3Tuple}C{(lat,
441 lon, height)} respectively L{LatLon4Tuple}C{(lat, lon,
442 height, datum)} depending on whether a C{datum} keyword
443 is un-/specified.
445 @raise TypeError: Invalid B{C{delta}}, B{C{LatLon}} or B{C{LatLon_kwds}}.
446 '''
447 t = self._ltp._local2ecef(delta, nine=True)
448 return t.toLatLon(LatLon=LatLon, **_xkwds(LatLon_kwds, name=self.name))
450 def _distanceTo(self, func, other, radius=None, **kwds):
451 '''(INTERNAL) Helper for distance methods C{<func>To}.
452 '''
453 p, r = self.others(other, up=2), radius
454 if r is None:
455 r = self._datum.ellipsoid.R1 if self._datum else R_M
456 return func(self.lat, self.lon, p.lat, p.lon, radius=r, **kwds)
458 def _distanceTo_(self, func_, other, wrap=False, radius=None):
459 '''(INTERNAL) Helper for (ellipsoidal) methods C{<func>To}.
460 '''
461 p = self.others(other, up=2)
462 D = self.datum
463 lam21, phi2, _ = _Wrap.philam3(self.lam, p.phi, p.lam, wrap)
464 r = func_(phi2, self.phi, lam21, datum=D)
465 return r * (D.ellipsoid.a if radius is None else radius)
467 @Property_RO
468 def Ecef(self):
469 '''Get the ECEF I{class} (L{EcefKarney}), I{lazily}.
470 '''
471 return _MODS.ecef.EcefKarney # default
473 @Property_RO
474 def _Ecef_forward(self):
475 '''(INTERNAL) Helper for L{_ecef9} and L{toEcef} (C{callable}).
476 '''
477 return self.Ecef(self.datum, name=self.name).forward
479 @Property_RO
480 def _ecef9(self):
481 '''(INTERNAL) Helper for L{toCartesian}, L{toEcef} and L{toCartesian} (L{Ecef9Tuple}).
482 '''
483 return self._Ecef_forward(self, M=True)
485 @deprecated_method
486 def equals(self, other, eps=None): # PYCHOK no cover
487 '''DEPRECATED, use method L{isequalTo}.'''
488 return self.isequalTo(other, eps=eps)
490 @deprecated_method
491 def equals3(self, other, eps=None): # PYCHOK no cover
492 '''DEPRECATED, use method L{isequalTo3}.'''
493 return self.isequalTo3(other, eps=eps)
495 def equirectangularTo(self, other, **radius_adjust_limit_wrap):
496 '''Compute the distance between this and an other point
497 using the U{Equirectangular Approximation / Projection
498 <https://www.Movable-Type.co.UK/scripts/latlong.html#equirectangular>}.
500 Suitable only for short, non-near-polar distances up to a
501 few hundred Km or Miles. Use method L{haversineTo} or
502 C{distanceTo*} for more accurate and/or larger distances.
504 @arg other: The other point (C{LatLon}).
505 @kwarg radius_adjust_limit_wrap: Optional keyword arguments
506 for function L{pygeodesy.equirectangular},
507 overriding the default mean C{radius} of this
508 point's datum ellipsoid.
510 @return: Distance (C{meter}, same units as B{C{radius}}).
512 @raise TypeError: The B{C{other}} point is not C{LatLon}.
514 @see: Function L{pygeodesy.equirectangular} and methods L{cosineAndoyerLambertTo},
515 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},
516 C{euclideanTo}, L{flatLocalTo}/L{hubenyTo}, L{flatPolarTo},
517 L{haversineTo}, L{thomasTo} and L{vincentysTo}.
518 '''
519 return self._distanceTo(equirectangular, other, **radius_adjust_limit_wrap)
521 def euclideanTo(self, other, **radius_adjust_wrap):
522 '''Approximate the C{Euclidian} distance between this and
523 an other point.
525 See function L{pygeodesy.euclidean} for the available B{C{options}}.
527 @arg other: The other point (C{LatLon}).
528 @kwarg radius_adjust_wrap: Optional keyword arguments for function
529 L{pygeodesy.euclidean}, overriding the default mean
530 C{radius} of this point's datum ellipsoid.
532 @return: Distance (C{meter}, same units as B{C{radius}}).
534 @raise TypeError: The B{C{other}} point is not C{LatLon}.
536 @see: Function L{pygeodesy.euclidean} and methods L{cosineAndoyerLambertTo},
537 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},
538 L{equirectangularTo}, L{flatLocalTo}/L{hubenyTo}, L{flatPolarTo},
539 L{haversineTo}, L{thomasTo} and L{vincentysTo}.
540 '''
541 return self._distanceTo(euclidean, other, **radius_adjust_wrap)
543 def flatLocalTo(self, other, radius=None, wrap=False):
544 '''Compute the distance between this and an other point using the
545 U{ellipsoidal Earth to plane projection
546 <https://WikiPedia.org/wiki/Geographical_distance#Ellipsoidal_Earth_projected_to_a_plane>}
547 aka U{Hubeny<https://www.OVG.AT/de/vgi/files/pdf/3781/>} formula.
549 @arg other: The other point (C{LatLon}).
550 @kwarg radius: Mean earth radius (C{meter}) or C{None} for
551 the I{equatorial radius} of this point's
552 datum ellipsoid.
553 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll
554 the B{C{other}} point (C{bool}).
556 @return: Distance (C{meter}, same units as B{C{radius}}).
558 @raise TypeError: The B{C{other}} point is not C{LatLon}.
560 @raise ValueError: Invalid B{C{radius}}.
562 @see: Function L{pygeodesy.flatLocal}/L{pygeodesy.hubeny}, methods
563 L{cosineAndoyerLambertTo}, L{cosineForsytheAndoyerLambertTo},
564 L{cosineLawTo}, C{distanceTo*}, L{equirectangularTo}, L{euclideanTo},
565 L{flatPolarTo}, L{haversineTo}, L{thomasTo} and L{vincentysTo} and
566 U{local, flat Earth approximation<https://www.edwilliams.org/avform.htm#flat>}.
567 '''
568 return self._distanceTo_(flatLocal_, other, wrap=wrap, radius=
569 radius if radius in (None, R_M, _1_0, 1) else Radius(radius)) # PYCHOK kwargs
571 hubenyTo = flatLocalTo # for Karl Hubeny
573 def flatPolarTo(self, other, **radius_wrap):
574 '''Compute the distance between this and an other point using
575 the U{polar coordinate flat-Earth<https://WikiPedia.org/wiki/
576 Geographical_distance#Polar_coordinate_flat-Earth_formula>} formula.
578 @arg other: The other point (C{LatLon}).
579 @kwarg radius_wrap: Optional keyword arguments for function
580 L{pygeodesy.flatPolar}, overriding the
581 default mean C{radius} of this point's
582 datum ellipsoid.
584 @return: Distance (C{meter}, same units as B{C{radius}}).
586 @raise TypeError: The B{C{other}} point is not C{LatLon}.
588 @see: Function L{pygeodesy.flatPolar} and methods L{cosineAndoyerLambertTo},
589 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},
590 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},
591 L{haversineTo}, L{thomasTo} and L{vincentysTo}.
592 '''
593 return self._distanceTo(flatPolar, other, **radius_wrap)
595 def hartzell(self, los=None, earth=None):
596 '''Compute the intersection of a Line-Of-Sight (los) from this Point-Of-View
597 (pov) with this point's ellipsoid surface.
599 @kwarg los: Line-Of-Sight, I{direction} to earth (L{Vector3d}) or
600 C{None} to point to the ellipsoid's center.
601 @kwarg earth: The earth model (L{Datum}, L{Ellipsoid}, L{Ellipsoid2},
602 L{a_f2Tuple} or C{scalar} radius in C{meter}) overriding
603 this point's C{datum} ellipsoid.
605 @return: The ellipsoid intersection (C{LatLon}) or this very instance
606 if this C{pov's height} is C{0}.
608 @raise IntersectionError: Null C{pov} or B{C{los}} vector, this
609 C{pov's height} is negative or B{C{los}}
610 points outside the ellipsoid or in an
611 opposite direction.
613 @raise TypeError: Invalid B{C{los}}.
615 @see: Function C{hartzell} for further details.
616 '''
617 h = self.height
618 if not h:
619 r = self
620 elif h < 0:
621 raise IntersectionError(pov=self, los=los, height=h, txt=_no_(_height_))
622 elif los is None:
623 d = self.datum if earth is None else _spherical_datum(earth)
624 r = self.dup(datum=d, height=0, name=self.hartzell.__name__)
625 else:
626 c = self.toCartesian()
627 r = hartzell(c, los=los, earth=earth or self.datum, LatLon=self.classof)
628 return r
630 def haversineTo(self, other, **radius_wrap):
631 '''Compute the distance between this and an other point using the
632 U{Haversine<https://www.Movable-Type.co.UK/scripts/latlong.html>}
633 formula.
635 @arg other: The other point (C{LatLon}).
636 @kwarg radius_wrap: Optional keyword arguments for function
637 L{pygeodesy.haversine}, overriding the
638 default mean C{radius} of this point's
639 datum ellipsoid.
641 @return: Distance (C{meter}, same units as B{C{radius}}).
643 @raise TypeError: The B{C{other}} point is not C{LatLon}.
645 @see: Function L{pygeodesy.haversine} and methods L{cosineAndoyerLambertTo},
646 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},
647 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},
648 L{flatPolarTo}, L{thomasTo} and L{vincentysTo}.
649 '''
650 return self._distanceTo(haversine, other, **radius_wrap)
652 def _havg(self, other, f=_0_5, h=None):
653 '''(INTERNAL) Weighted, average height.
655 @arg other: An other point (C{LatLon}).
656 @kwarg f: Optional fraction (C{float}).
657 @kwarg h: Overriding height (C{meter}).
659 @return: Average, fractional height (C{float}) or
660 the overriding B{C{height}} (C{Height}).
661 '''
662 return Height(h) if h is not None else \
663 _MODS.fmath.favg(self.height, other.height, f=f)
665 @Property
666 def height(self):
667 '''Get the height (C{meter}).
668 '''
669 return self._height
671 @height.setter # PYCHOK setter!
672 def height(self, height):
673 '''Set the height (C{meter}).
675 @raise TypeError: Invalid B{C{height}} C{type}.
677 @raise ValueError: Invalid B{C{height}}.
678 '''
679 h = Height(height)
680 if self._height != h:
681 _update_all(self)
682 self._height = h
684 def _heigHt(self, height):
685 '''(INTERNAL) Overriding this C{height}.
686 '''
687 return self.height if height is None else Height(height)
689 def height4(self, earth=None, normal=True, LatLon=None, **LatLon_kwds):
690 '''Compute the height above or below and the projection of this point
691 on this datum's or on an other earth's ellipsoid surface.
693 @kwarg earth: A datum, ellipsoid, triaxial ellipsoid or earth radius
694 I{overriding} this datum (L{Datum}, L{Ellipsoid},
695 L{Ellipsoid2}, L{a_f2Tuple}, L{Triaxial}, L{Triaxial_},
696 L{JacobiConformal} or C{meter}, conventionally).
697 @kwarg normal: If C{True} the projection is the nearest point on the
698 ellipsoid's surface, otherwise the intersection of the
699 radial line to the center and the ellipsoid's surface.
700 @kwarg LatLon: Optional class to return the height and projection
701 (C{LatLon}) or C{None}.
702 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
703 ignored if C{B{LatLon} is None}.
705 @note: Use keyword argument C{height=0} to override C{B{LatLon}.height}
706 to {0} or any other C{scalar}, conventionally in C{meter}.
708 @return: An instance of B{C{LatLon}} or if C{B{LatLon} is None}, a
709 L{Vector4Tuple}C{(x, y, z, h)} with the I{projection} C{x}, C{y}
710 and C{z} coordinates and height C{h} in C{meter}, conventionally.
712 @raise TriaxialError: No convergence in triaxial root finding.
714 @raise TypeError: Invalid B{C{earth}}.
716 @see: L{Ellipsoid.height4} and L{Triaxial_.height4} for more information.
717 '''
718 c = self.toCartesian()
719 if LatLon is None:
720 r = c.height4(earth=earth, normal=normal)
721 else:
722 r = c.height4(earth=earth, normal=normal, Cartesian=c.classof, height=0)
723 r = r.toLatLon(LatLon=LatLon, **_xkwds(LatLon_kwds, height=r.height))
724 return r
726 def heightStr(self, prec=-2, m=_m_):
727 '''Return this point's B{C{height}} as C{str}ing.
729 @kwarg prec: Number of (decimal) digits, unstripped (C{int}).
730 @kwarg m: Optional unit of the height (C{str}).
732 @see: Function L{pygeodesy.hstr}.
733 '''
734 return _MODS.streprs.hstr(self.height, prec=prec, m=m)
736 @deprecated_method
737 def isantipode(self, other, eps=EPS): # PYCHOK no cover
738 '''DEPRECATED, use method L{isantipodeTo}.'''
739 return self.isantipodeTo(other, eps=eps)
741 def isantipodeTo(self, other, eps=EPS):
742 '''Check whether this and an other point are antipodal,
743 on diametrically opposite sides of the earth.
745 @arg other: The other point (C{LatLon}).
746 @kwarg eps: Tolerance for near-equality (C{degrees}).
748 @return: C{True} if points are antipodal within the given
749 tolerance, C{False} otherwise.
750 '''
751 p = self.others(other)
752 return isantipode(*(self.latlon + p.latlon), eps=eps)
754 @Property_RO
755 def isEllipsoidal(self):
756 '''Check whether this point is ellipsoidal (C{bool} or C{None} if unknown).
757 '''
758 return self.datum.isEllipsoidal if self._datum else None
760 @Property_RO
761 def isEllipsoidalLatLon(self):
762 '''Get C{LatLon} base.
763 '''
764 return False
766 def isequalTo(self, other, eps=None):
767 '''Compare this point with an other point, I{ignoring} height.
769 @arg other: The other point (C{LatLon}).
770 @kwarg eps: Tolerance for equality (C{degrees}).
772 @return: C{True} if both points are identical,
773 I{ignoring} height, C{False} otherwise.
775 @raise TypeError: The B{C{other}} point is not C{LatLon}
776 or mismatch of the B{C{other}} and
777 this C{class} or C{type}.
779 @raise UnitError: Invalid B{C{eps}}.
781 @see: Method L{isequalTo3}.
782 '''
783 return _isequalTo(self, self.others(other), eps=eps)
785 def isequalTo3(self, other, eps=None):
786 '''Compare this point with an other point, I{including} height.
788 @arg other: The other point (C{LatLon}).
789 @kwarg eps: Tolerance for equality (C{degrees}).
791 @return: C{True} if both points are identical
792 I{including} height, C{False} otherwise.
794 @raise TypeError: The B{C{other}} point is not C{LatLon}
795 or mismatch of the B{C{other}} and
796 this C{class} or C{type}.
798 @see: Method L{isequalTo}.
799 '''
800 return self.height == self.others(other).height and \
801 _isequalTo(self, other, eps=eps)
803 @Property_RO
804 def isnormal(self):
805 '''Return C{True} if this point is normal (C{bool}),
806 meaning C{abs(lat) <= 90} and C{abs(lon) <= 180}.
808 @see: Methods L{normal}, L{toNormal} and functions
809 L{pygeodesy.isnormal} and L{pygeodesy.normal}.
810 '''
811 return isnormal(self.lat, self.lon, eps=0)
813 @Property_RO
814 def isSpherical(self):
815 '''Check whether this point is spherical (C{bool} or C{None} if unknown).
816 '''
817 return self.datum.isSpherical if self._datum else None
819 @Property_RO
820 def lam(self):
821 '''Get the longitude (B{C{radians}}).
822 '''
823 return radians(self.lon)
825 @Property
826 def lat(self):
827 '''Get the latitude (C{degrees90}).
828 '''
829 return self._lat
831 @lat.setter # PYCHOK setter!
832 def lat(self, lat):
833 '''Set the latitude (C{str[N|S]} or C{degrees}).
835 @raise ValueError: Invalid B{C{lat}}.
836 '''
837 lat = Lat(lat) # parseDMS(lat, suffix=_NS_, clip=90)
838 if self._lat != lat:
839 _update_all(self)
840 self._lat = lat
842 @Property
843 def latlon(self):
844 '''Get the lat- and longitude (L{LatLon2Tuple}C{(lat, lon)}).
845 '''
846 return LatLon2Tuple(self._lat, self._lon, name=self.name)
848 @latlon.setter # PYCHOK setter!
849 def latlon(self, latlonh):
850 '''Set the lat- and longitude and optionally the height
851 (2- or 3-tuple or comma- or space-separated C{str}
852 of C{degrees90}, C{degrees180} and C{meter}).
854 @raise TypeError: Height of B{C{latlonh}} not C{scalar} or
855 B{C{latlonh}} not C{list} or C{tuple}.
857 @raise ValueError: Invalid B{C{latlonh}} or M{len(latlonh)}.
859 @see: Function L{pygeodesy.parse3llh} to parse a B{C{latlonh}}
860 string into a 3-tuple C{(lat, lon, h)}.
861 '''
862 if isstr(latlonh):
863 latlonh = parse3llh(latlonh, height=self.height)
864 else:
865 _xinstanceof(list, tuple, latlonh=latlonh)
866 if len(latlonh) == 3:
867 h = Height(latlonh[2], name=Fmt.SQUARE(latlonh=2))
868 elif len(latlonh) != 2:
869 raise _ValueError(latlonh=latlonh)
870 else:
871 h = self.height
873 llh = Lat(latlonh[0]), Lon(latlonh[1]), h # parseDMS2(latlonh[0], latlonh[1])
874 if (self._lat, self._lon, self._height) != llh:
875 _update_all(self)
876 self._lat, self._lon, self._height = llh
878 def latlon2(self, ndigits=0):
879 '''Return this point's lat- and longitude in C{degrees}, rounded.
881 @kwarg ndigits: Number of (decimal) digits (C{int}).
883 @return: A L{LatLon2Tuple}C{(lat, lon)}, both C{float}
884 and rounded away from zero.
886 @note: The C{round}ed values are always C{float}, also
887 if B{C{ndigits}} is omitted.
888 '''
889 return LatLon2Tuple(round(self.lat, ndigits),
890 round(self.lon, ndigits), name=self.name)
892 @deprecated_method
893 def latlon_(self, ndigits=0): # PYCHOK no cover
894 '''DEPRECATED, use method L{latlon2}.'''
895 return self.latlon2(ndigits=ndigits)
897 latlon2round = latlon_ # PYCHOK no cover
899 @Property
900 def latlonheight(self):
901 '''Get the lat-, longitude and height (L{LatLon3Tuple}C{(lat, lon, height)}).
902 '''
903 return self.latlon.to3Tuple(self.height)
905 @latlonheight.setter # PYCHOK setter!
906 def latlonheight(self, latlonh):
907 '''Set the lat- and longitude and optionally the height
908 (2- or 3-tuple or comma- or space-separated C{str}
909 of C{degrees90}, C{degrees180} and C{meter}).
911 @see: Property L{latlon} for more details.
912 '''
913 self.latlon = latlonh
915 @Property
916 def lon(self):
917 '''Get the longitude (C{degrees180}).
918 '''
919 return self._lon
921 @lon.setter # PYCHOK setter!
922 def lon(self, lon):
923 '''Set the longitude (C{str[E|W]} or C{degrees}).
925 @raise ValueError: Invalid B{C{lon}}.
926 '''
927 lon = Lon(lon) # parseDMS(lon, suffix=_EW_, clip=180)
928 if self._lon != lon:
929 _update_all(self)
930 self._lon = lon
932 @Property_RO
933 def _ltp(self):
934 '''(INTERNAL) Cache for L{toLtp}.
935 '''
936 return _MODS.ltp.Ltp(self, ecef=self.Ecef(self.datum), name=self.name)
938 def nearestOn6(self, points, closed=False, height=None, wrap=False):
939 '''Locate the point on a path or polygon closest to this point.
941 Points are converted to and distances are computed in
942 I{geocentric}, cartesian space.
944 @arg points: The path or polygon points (C{LatLon}[]).
945 @kwarg closed: Optionally, close the polygon (C{bool}).
946 @kwarg height: Optional height, overriding the height of
947 this and all other points (C{meter}). If
948 C{None}, take the height of points into
949 account for distances.
950 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll
951 the B{C{points}} (C{bool}).
953 @return: A L{NearestOn6Tuple}C{(closest, distance, fi, j,
954 start, end)} with the C{closest}, the C{start}
955 and the C{end} point each an instance of this
956 C{LatLon} and C{distance} in C{meter}, same
957 units as the cartesian axes.
959 @raise PointsError: Insufficient number of B{C{points}}.
961 @raise TypeError: Some B{C{points}} or some B{C{points}}'
962 C{Ecef} invalid.
964 @raise ValueError: Some B{C{points}}' C{Ecef} is incompatible.
966 @see: Function L{pygeodesy.nearestOn6}.
967 '''
968 def _cs(Ps, h, w, C):
969 p = None # not used
970 for i, q in Ps.enumerate():
971 if w and i:
972 q = _unrollon(p, q)
973 yield C(height=h, i=i, up=3, points=q)
974 p = q
976 C = self._toCartesianEcef # to verify datum and Ecef
977 Ps = self.PointsIter(points, wrap=wrap)
979 c = C(height=height, this=self) # this Cartesian
980 t = nearestOn6(c, _cs(Ps, height, wrap, C), closed=closed)
981 c, s, e = t.closest, t.start, t.end
983 kwds = _xkwds_not(None, LatLon=self.classof, # this LatLon
984 height=height)
985 _r = self.Ecef(self.datum).reverse
986 p = _r(c).toLatLon(**kwds)
987 s = _r(s).toLatLon(**kwds) if s is not c else p
988 e = _r(e).toLatLon(**kwds) if e is not c else p
989 return t.dup(closest=p, start=s, end=e)
991 def normal(self):
992 '''Normalize this point I{in-place} to C{abs(lat) <= 90} and
993 C{abs(lon) <= 180}.
995 @return: C{True} if this point was I{normal}, C{False} if it
996 wasn't (but is now).
998 @see: Property L{isnormal} and method L{toNormal}.
999 '''
1000 n = self.isnormal
1001 if not n:
1002 self.latlon = normal(*self.latlon)
1003 return n
1005 @Property_RO
1006 def _N_vector(self):
1007 '''(INTERNAL) Get the (C{nvectorBase._N_vector_})
1008 '''
1009 return _MODS.nvectorBase._N_vector_(*self.xyzh)
1011 @Property_RO
1012 def phi(self):
1013 '''Get the latitude (B{C{radians}}).
1014 '''
1015 return radians(self.lat)
1017 @Property_RO
1018 def philam(self):
1019 '''Get the lat- and longitude (L{PhiLam2Tuple}C{(phi, lam)}).
1020 '''
1021 return PhiLam2Tuple(self.phi, self.lam, name=self.name)
1023 def philam2(self, ndigits=0):
1024 '''Return this point's lat- and longitude in C{radians}, rounded.
1026 @kwarg ndigits: Number of (decimal) digits (C{int}).
1028 @return: A L{PhiLam2Tuple}C{(phi, lam)}, both C{float}
1029 and rounded away from zero.
1031 @note: The C{round}ed values are always C{float}, also
1032 if B{C{ndigits}} is omitted.
1033 '''
1034 return PhiLam2Tuple(round(self.phi, ndigits),
1035 round(self.lam, ndigits), name=self.name)
1037 @Property_RO
1038 def philamheight(self):
1039 '''Get the lat-, longitude in C{radians} and height (L{PhiLam3Tuple}C{(phi, lam, height)}).
1040 '''
1041 return self.philam.to3Tuple(self.height)
1043 @deprecated_method
1044 def points(self, points, closed=True): # PYCHOK no cover
1045 '''DEPRECATED, use method L{points2}.'''
1046 return self.points2(points, closed=closed)
1048 def points2(self, points, closed=True):
1049 '''Check a path or polygon represented by points.
1051 @arg points: The path or polygon points (C{LatLon}[])
1052 @kwarg closed: Optionally, consider the polygon closed,
1053 ignoring any duplicate or closing final
1054 B{C{points}} (C{bool}).
1056 @return: A L{Points2Tuple}C{(number, points)}, an C{int}
1057 and C{list} or C{tuple}.
1059 @raise PointsError: Insufficient number of B{C{points}}.
1061 @raise TypeError: Some B{C{points}} are not C{LatLon}.
1062 '''
1063 return _MODS.iters.points2(points, closed=closed, base=self)
1065 def PointsIter(self, points, loop=0, dedup=False, wrap=False):
1066 '''Return a C{PointsIter} iterator.
1068 @arg points: The path or polygon points (C{LatLon}[])
1069 @kwarg loop: Number of loop-back points (non-negative C{int}).
1070 @kwarg dedup: Skip duplicate points (C{bool}).
1071 @kwarg wrap: If C{True}, wrap or I{normalize} the
1072 enum-/iterated B{C{points}} (C{bool}).
1074 @return: A new C{PointsIter} iterator.
1076 @raise PointsError: Insufficient number of B{C{points}}.
1077 '''
1078 return PointsIter(points, base=self, loop=loop, dedup=dedup, wrap=wrap)
1080 def radii11(self, point2, point3, wrap=False):
1081 '''Return the radii of the C{Circum-}, C{In-}, I{Soddy} and C{Tangent}
1082 circles of a (planar) triangle formed by this and two other points.
1084 @arg point2: Second point (C{LatLon}).
1085 @arg point3: Third point (C{LatLon}).
1086 @kwarg wrap: If C{True}, wrap or I{normalize} B{C{point2}} and
1087 B{C{point3}} (C{bool}).
1089 @return: L{Radii11Tuple}C{(rA, rB, rC, cR, rIn, riS, roS, a, b, c, s)}.
1091 @raise IntersectionError: Near-coincident or -colinear points.
1093 @raise TypeError: Invalid B{C{point2}} or B{C{point3}}.
1095 @see: Function L{pygeodesy.radii11}, U{Incircle
1096 <https://MathWorld.Wolfram.com/Incircle.html>}, U{Soddy Circles
1097 <https://MathWorld.Wolfram.com/SoddyCircles.html>} and U{Tangent
1098 Circles<https://MathWorld.Wolfram.com/TangentCircles.html>}.
1099 '''
1100 with _toCartesian3(self, point2, point3, wrap) as cs:
1101 return _radii11ABC(*cs, useZ=True)[0]
1103 def _rhumb3(self, exact, radius): # != .sphericalBase._rhumbs3
1104 '''(INTERNAL) Get the C{rhumb} for this point's datum or for
1105 the B{C{radius}}' earth model iff non-C{None}.
1106 '''
1107 try:
1108 t = self._rhumb33[(exact, radius)]
1109 except KeyError:
1110 D = self.datum if radius is None else _spherical_datum(radius) # ellipsoidal OK
1111 r = D.ellipsoid.rhumb_(exact=exact) # or D.isSpherical)
1112 t = r, D, _MODS.karney.Caps
1113 d = self._rhumb33
1114 while d:
1115 d.popitem()
1116 d[(exact, radius)] = t # cache 3-tuple
1117 return t
1119 @Property_RO
1120 def _rhumb33(self):
1121 return {} # single-item cache
1123 def rhumbAzimuthTo(self, other, exact=False, radius=None, wrap=False):
1124 '''Return the azimuth (bearing) of a rhumb line (loxodrome)
1125 between this and an other (ellipsoidal) point.
1127 @arg other: The other point (C{LatLon}).
1128 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),
1129 see method L{Ellipsoid.rhumb_}.
1130 @kwarg radius: Optional earth radius (C{meter}) or earth model
1131 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or
1132 L{a_f2Tuple}), overriding this point's datum.
1133 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
1134 B{C{other}} point (C{bool}).
1136 @return: Rhumb azimuth (compass C{degrees360}).
1138 @raise TypeError: The B{C{other}} point is incompatible or
1139 B{C{radius}} is invalid.
1140 '''
1141 r, _, Cs = self._rhumb3(exact, radius)
1142 return r._Inverse(self, other, wrap, outmask=Cs.AZIMUTH).azi12
1144 def rhumbDestination(self, distance, azimuth, exact=False, radius=None, height=None):
1145 '''Return the destination point having travelled the given distance
1146 from this point along a rhumb line (loxodrome) at the given azimuth.
1148 @arg distance: Distance travelled (C{meter}, same units as this
1149 point's datum (ellipsoid) axes or B{C{radius}},
1150 may be negative.
1151 @arg azimuth: Azimuth (bearing) at this point (compass C{degrees}).
1152 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),
1153 see method L{Ellipsoid.rhumb_}.
1154 @kwarg radius: Optional earth radius (C{meter}) or earth model
1155 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or
1156 L{a_f2Tuple}), overriding this point's datum.
1157 @kwarg height: Optional height, overriding the default height
1158 (C{meter}).
1160 @return: The destination point (ellipsoidal C{LatLon}).
1162 @raise TypeError: Invalid B{C{radius}}.
1164 @raise ValueError: Invalid B{C{distance}}, B{C{azimuth}},
1165 B{C{radius}} or B{C{height}}.
1166 '''
1167 r, D, _ = self._rhumb3(exact, radius)
1168 d = r._Direct(self, azimuth, distance)
1169 h = self._heigHt(height)
1170 return self.classof(d.lat2, d.lon2, datum=D, height=h)
1172 def rhumbDistanceTo(self, other, exact=False, radius=None, wrap=False):
1173 '''Return the distance from this to an other point along
1174 a rhumb line (loxodrome).
1176 @arg other: The other point (C{LatLon}).
1177 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),
1178 see method L{Ellipsoid.rhumb_}.
1179 @kwarg radius: Optional earth radius (C{meter}) or earth model
1180 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or
1181 L{a_f2Tuple}), overriding this point's datum.
1182 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
1183 B{C{other}} point (C{bool}).
1185 @return: Distance (C{meter}, the same units as this point's
1186 datum (ellipsoid) axes or B{C{radius}}.
1188 @raise TypeError: The B{C{other}} point is incompatible or
1189 B{C{radius}} is invalid.
1191 @raise ValueError: Invalid B{C{radius}}.
1192 '''
1193 r, _, Cs = self._rhumb3(exact, radius)
1194 return r._Inverse(self, other, wrap, outmask=Cs.DISTANCE).s12
1196 def rhumbLine(self, azimuth_other, exact=False, radius=None, wrap=False,
1197 **name_caps):
1198 '''Get a rhumb line through this point at a given azimuth or
1199 through this and an other point.
1201 @arg azimuth_other: The azimuth of the rhumb line (compass
1202 C{degrees}) or the other point (C{LatLon}).
1203 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),
1204 see method L{Ellipsoid.rhumb_}.
1205 @kwarg radius: Optional earth radius (C{meter}) or earth model
1206 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or
1207 L{a_f2Tuple}), overriding this point's datum.
1208 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
1209 C{azimuth_B{other}} point (C{bool}).
1210 @kwarg name_caps: Optional C{B{name}=str} and C{caps}, see
1211 L{RhumbLine} C{B{caps}}.
1213 @return: A C{RhumbLine} instance.
1215 @raise TypeError: Invalid B{C{radius}} or BC{C{azimuth_other}}
1216 not a C{scalar} nor a C{LatLon}.
1218 @see: Modules L{rhumbaux} and L{rhumbx}.
1219 '''
1220 r, _, _ = self._rhumb3(exact, radius)
1221 a, kwds = azimuth_other, _xkwds(name_caps, name=self.name)
1222 if isscalar(a):
1223 r = r._DirectLine(self, a, **kwds)
1224 elif isinstance(a, LatLonBase):
1225 r = r._InverseLine(self, a, wrap, **kwds)
1226 else:
1227 raise _TypeError(azimuth_other=a)
1228 return r
1230 def rhumbMidpointTo(self, other, exact=False, radius=None,
1231 height=None, fraction=_0_5, wrap=False):
1232 '''Return the (loxodromic) midpoint on the rhumb line between
1233 this and an other point.
1235 @arg other: The other point (C{LatLon}).
1236 @kwarg exact: Exact C{Rhumb...} to use (C{bool} or C{Rhumb...}),
1237 see method L{Ellipsoid.rhumb_}.
1238 @kwarg radius: Optional earth radius (C{meter}) or earth model
1239 (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or
1240 L{a_f2Tuple}), overriding this point's datum.
1241 @kwarg height: Optional height, overriding the mean height
1242 (C{meter}).
1243 @kwarg fraction: Midpoint location from this point (C{scalar}),
1244 may be negative or greater than 1.0.
1245 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the
1246 B{C{other}} point (C{bool}).
1248 @return: The midpoint at the given B{C{fraction}} along the
1249 rhumb line (C{LatLon}).
1251 @raise TypeError: The B{C{other}} point is incompatible or
1252 B{C{radius}} is invalid.
1254 @raise ValueError: Invalid B{C{height}} or B{C{fraction}}.
1255 '''
1256 r, D, _ = self._rhumb3(exact, radius)
1257 f = Scalar(fraction=fraction)
1258 d = r._Inverse(self, other, wrap) # C.AZIMUTH_DISTANCE
1259 d = r._Direct( self, d.azi12, d.s12 * f)
1260 h = self._havg(other, f=f, h=height)
1261 return self.classof(d.lat2, d.lon2, datum=D, height=h)
1263 def thomasTo(self, other, wrap=False):
1264 '''Compute the distance between this and an other point using
1265 U{Thomas'<https://apps.DTIC.mil/dtic/tr/fulltext/u2/703541.pdf>}
1266 formula.
1268 @arg other: The other point (C{LatLon}).
1269 @kwarg wrap: If C{True}, wrap or I{normalize} and unroll
1270 the B{C{other}} point (C{bool}).
1272 @return: Distance (C{meter}, same units as the axes of
1273 this point's datum ellipsoid).
1275 @raise TypeError: The B{C{other}} point is not C{LatLon}.
1277 @see: Function L{pygeodesy.thomas} and methods L{cosineAndoyerLambertTo},
1278 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},
1279 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},
1280 L{flatPolarTo}, L{haversineTo} and L{vincentysTo}.
1281 '''
1282 return self._distanceTo_(thomas_, other, wrap=wrap)
1284 @deprecated_method
1285 def to2ab(self): # PYCHOK no cover
1286 '''DEPRECATED, use property L{philam}.'''
1287 return self.philam
1289 def toCartesian(self, height=None, Cartesian=None, **Cartesian_kwds):
1290 '''Convert this point to cartesian, I{geocentric} coordinates,
1291 also known as I{Earth-Centered, Earth-Fixed} (ECEF).
1293 @kwarg height: Optional height, overriding this point's height
1294 (C{meter}, conventionally).
1295 @kwarg Cartesian: Optional class to return the geocentric
1296 coordinates (C{Cartesian}) or C{None}.
1297 @kwarg Cartesian_kwds: Optional, additional B{C{Cartesian}}
1298 keyword arguments, ignored if
1299 C{B{Cartesian} is None}.
1301 @return: A B{C{Cartesian}} or if B{C{Cartesian}} is C{None},
1302 an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M,
1303 datum)} with C{C=0} and C{M} if available.
1305 @raise TypeError: Invalid B{C{Cartesian}} or B{C{Cartesian_kwds}}.
1306 '''
1307 r = self._ecef9 if height is None else self.toEcef(height=height)
1308 if Cartesian is not None: # class or .classof
1309 r = self._xnamed(Cartesian(r, **Cartesian_kwds))
1310 _xdatum(r.datum, self.datum)
1311 return r
1313 def _toCartesianEcef(self, height=None, i=None, up=2, **name_point):
1314 '''(INTERNAL) Convert to cartesian and check Ecef's before and after.
1315 '''
1316 p = self.others(up=up, **name_point)
1317 c = p.toCartesian(height=height)
1318 E = self.Ecef
1319 if E:
1320 for p in (p, c):
1321 e = getattr(p, LatLonBase.Ecef.name, None)
1322 if e not in (None, E): # PYCHOK no cover
1323 n, _ = name_point.popitem()
1324 if i is not None:
1325 Fmt.SQUARE(n, i)
1326 raise _ValueError(n, e, txt=_incompatible(E.__name__))
1327 return c
1329 def toEcef(self, height=None, M=False):
1330 '''Convert this point to I{geocentric} coordinates, also known as
1331 I{Earth-Centered, Earth-Fixed} (U{ECEF<https://WikiPedia.org/wiki/ECEF>}).
1333 @kwarg height: Optional height, overriding this point's height
1334 (C{meter}, conventionally).
1335 @kwarg M: Optionally, include the rotation L{EcefMatrix} (C{bool}).
1337 @return: An L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)}
1338 with C{C=0} and C{M} if available.
1340 @raise EcefError: A C{.datum} or an ECEF issue.
1341 '''
1342 return self._ecef9 if height in (None, self.height) else \
1343 self._Ecef_forward(self.lat, self.lon, height=height, M=M)
1345 @deprecated_method
1346 def to3llh(self, height=None): # PYCHOK no cover
1347 '''DEPRECATED, use property L{latlonheight} or C{latlon.to3Tuple(B{height})}.'''
1348 return self.latlonheight if height in (None, self.height) else \
1349 self.latlon.to3Tuple(height)
1351 def toLocal(self, Xyz=None, ltp=None, **Xyz_kwds):
1352 '''Convert this I{geodetic} point to I{local} C{X}, C{Y} and C{Z}.
1354 @kwarg Xyz: Optional class to return C{X}, C{Y} and C{Z}
1355 (L{XyzLocal}, L{Enu}, L{Ned}) or C{None}.
1356 @kwarg ltp: The I{local tangent plane} (LTP) to use,
1357 overriding this point's LTP (L{Ltp}).
1358 @kwarg Xyz_kwds: Optional, additional B{C{Xyz}} keyword
1359 arguments, ignored if C{B{Xyz} is None}.
1361 @return: An B{C{Xyz}} instance or if C{B{Xyz} is None},
1362 a L{Local9Tuple}C{(x, y, z, lat, lon, height,
1363 ltp, ecef, M)} with C{M=None}, always.
1365 @raise TypeError: Invalid B{C{ltp}}.
1366 '''
1367 p = _MODS.ltp._xLtp(ltp, self._ltp)
1368 return p._ecef2local(self._ecef9, Xyz, Xyz_kwds)
1370 def toLtp(self, Ecef=None):
1371 '''Return the I{local tangent plane} (LTP) for this point.
1373 @kwarg Ecef: Optional ECEF I{class} (L{EcefKarney}, ...
1374 L{EcefYou}), overriding this point's C{Ecef}.
1375 '''
1376 return self._ltp if Ecef in (None, self.Ecef) else _MODS.ltp.Ltp(
1377 self, ecef=Ecef(self.datum), name=self.name)
1379 def toNormal(self, deep=False, name=NN):
1380 '''Get this point I{normalized} to C{abs(lat) <= 90}
1381 and C{abs(lon) <= 180}.
1383 @kwarg deep: If C{True} make a deep, otherwise a
1384 shallow copy (C{bool}).
1385 @kwarg name: Optional name of the copy (C{str}).
1387 @return: A copy of this point, I{normalized} and
1388 optionally renamed (C{LatLon}).
1390 @see: Property L{isnormal}, method L{normal} and function
1391 L{pygeodesy.normal}.
1392 '''
1393 ll = self.copy(deep=deep)
1394 _ = ll.normal()
1395 if name:
1396 ll.rename(name)
1397 return ll
1399 def toNvector(self, h=None, Nvector=None, **Nvector_kwds):
1400 '''Convert this point to C{n-vector} (normal to the earth's surface)
1401 components, I{including height}.
1403 @kwarg h: Optional height, overriding this point's
1404 height (C{meter}).
1405 @kwarg Nvector: Optional class to return the C{n-vector}
1406 components (C{Nvector}) or C{None}.
1407 @kwarg Nvector_kwds_wrap: Optional, additional B{C{Nvector}}
1408 keyword arguments, ignored if C{B{Nvector}
1409 is None}.
1411 @return: A B{C{Nvector}} or a L{Vector4Tuple}C{(x, y, z, h)}
1412 if B{C{Nvector}} is C{None}.
1414 @raise TypeError: Invalid B{C{Nvector}} or B{C{Nvector_kwds}}.
1415 '''
1416 return self.toVector(Vector=Nvector, h=self.height if h is None else h,
1417 ll=self, **Nvector_kwds)
1419 def toStr(self, form=F_DMS, joined=_COMMASPACE_, m=_m_, **prec_sep_s_D_M_S): # PYCHOK expected
1420 '''Convert this point to a "lat, lon[, +/-height]" string, formatted
1421 in the given C{B{form}at}.
1423 @kwarg form: The lat-/longitude C{B{form}at} to use (C{str}), see
1424 functions L{pygeodesy.latDMS} or L{pygeodesy.lonDMS}.
1425 @kwarg joined: Separator to join the lat-, longitude and heigth
1426 strings (C{str} or C{None} or C{NN} for non-joined).
1427 @kwarg m: Optional unit of the height (C{str}), use C{None} to
1428 exclude height from the returned string.
1429 @kwarg prec_sep_s_D_M_S: Optional C{B{prec}ision}, C{B{sep}arator},
1430 B{C{s_D}}, B{C{s_M}}, B{C{s_S}} and B{C{s_DMS}} keyword
1431 arguments, see function L{pygeodesy.latDMS} or
1432 L{pygeodesy.lonDMS}.
1434 @return: This point in the specified C{B{form}at}, etc. (C{str} or
1435 a 2- or 3-tuple C{(lat_str, lon_str[, height_str])} if
1436 C{B{joined}=NN} or C{B{joined}=None}).
1438 @see: Function L{pygeodesy.latDMS} or L{pygeodesy.lonDMS} for more
1439 details about keyword arguments C{B{form}at}, C{B{prec}ision},
1440 C{B{sep}arator}, B{C{s_D}}, B{C{s_M}}, B{C{s_S}} and B{C{s_DMS}}.
1442 @example:
1444 >>> LatLon(51.4778, -0.0016).toStr() # 51°28′40″N, 000°00′06″W
1445 >>> LatLon(51.4778, -0.0016).toStr(F_D) # 51.4778°N, 000.0016°W
1446 >>> LatLon(51.4778, -0.0016, 42).toStr() # 51°28′40″N, 000°00′06″W, +42.00m
1447 '''
1448 t = (latDMS(self.lat, form=form, **prec_sep_s_D_M_S),
1449 lonDMS(self.lon, form=form, **prec_sep_s_D_M_S))
1450 if self.height and m is not None:
1451 t += (self.heightStr(m=m),)
1452 return joined.join(t) if joined else t
1454 def toVector(self, Vector=None, **Vector_kwds):
1455 '''Convert this point to C{n-vector} (normal to the earth's
1456 surface) components, I{ignoring height}.
1458 @kwarg Vector: Optional class to return the C{n-vector}
1459 components (L{Vector3d}) or C{None}.
1460 @kwarg Vector_kwds: Optional, additional B{C{Vector}}
1461 keyword arguments, ignored if
1462 C{B{Vector} is None}.
1464 @return: A B{C{Vector}} or a L{Vector3Tuple}C{(x, y, z)}
1465 if B{C{Vector}} is C{None}.
1467 @raise TypeError: Invalid B{C{Vector}} or B{C{kwds}}.
1469 @note: These are C{n-vector} x, y and z components,
1470 I{NOT} geocentric (ECEF) x, y and z coordinates!
1471 '''
1472 r = self._vector3tuple
1473 if Vector is not None:
1474 r = Vector(*r, **_xkwds(Vector_kwds, name=self.name))
1475 return r
1477 def toVector3d(self):
1478 '''Convert this point to C{n-vector} (normal to the earth's
1479 surface) components, I{ignoring height}.
1481 @return: Unit vector (L{Vector3d}).
1483 @note: These are C{n-vector} x, y and z components,
1484 I{NOT} geocentric (ECEF) x, y and z coordinates!
1485 '''
1486 return self._vector3d # XXX .unit()
1488 def toWm(self, **toWm_kwds):
1489 '''Convert this point to a WM coordinate.
1491 @kwarg toWm_kwds: Optional L{pygeodesy.toWm} keyword arguments.
1493 @return: The WM coordinate (L{Wm}).
1495 @see: Function L{pygeodesy.toWm}.
1496 '''
1497 return self._wm if not toWm_kwds else _MODS.webmercator.toWm(
1498 self, **_xkwds(toWm_kwds, name=self.name))
1500 @deprecated_method
1501 def to3xyz(self): # PYCHOK no cover
1502 '''DEPRECATED, use property L{xyz} or method L{toNvector}, L{toVector},
1503 L{toVector3d} or perhaps (geocentric) L{toEcef}.'''
1504 return self.xyz # self.toVector()
1506 @Property_RO
1507 def _vector3d(self):
1508 '''(INTERNAL) Cache for L{toVector3d}.
1509 '''
1510 return self.toVector(Vector=Vector3d) # XXX .unit()
1512 @Property_RO
1513 def _vector3tuple(self):
1514 '''(INTERNAL) Cache for L{toVector}.
1515 '''
1516 return philam2n_xyz(self.phi, self.lam, name=self.name)
1518 def vincentysTo(self, other, **radius_wrap):
1519 '''Compute the distance between this and an other point using
1520 U{Vincenty's<https://WikiPedia.org/wiki/Great-circle_distance>}
1521 spherical formula.
1523 @arg other: The other point (C{LatLon}).
1524 @kwarg radius_wrap: Optional keyword arguments for function
1525 L{pygeodesy.vincentys}, overriding the
1526 default mean C{radius} of this point's
1527 datum ellipsoid.
1529 @return: Distance (C{meter}, same units as B{C{radius}}).
1531 @raise TypeError: The B{C{other}} point is not C{LatLon}.
1533 @see: Function L{pygeodesy.vincentys} and methods L{cosineAndoyerLambertTo},
1534 L{cosineForsytheAndoyerLambertTo}, L{cosineLawTo}, C{distanceTo*},
1535 L{equirectangularTo}, L{euclideanTo}, L{flatLocalTo}/L{hubenyTo},
1536 L{flatPolarTo}, L{haversineTo} and L{thomasTo}.
1537 '''
1538 return self._distanceTo(vincentys, other, **_xkwds(radius_wrap, radius=None))
1540 @Property_RO
1541 def _wm(self):
1542 '''(INTERNAL) Get this point as webmercator (L{Wm}).
1543 '''
1544 return _MODS.webmercator.toWm(self)
1546 @Property_RO
1547 def xyz(self):
1548 '''Get the C{n-vector} X, Y and Z components (L{Vector3Tuple}C{(x, y, z)})
1550 @note: These are C{n-vector} x, y and z components, I{NOT}
1551 geocentric (ECEF) x, y and z coordinates!
1552 '''
1553 return self.toVector(Vector=Vector3Tuple)
1555 @Property_RO
1556 def xyzh(self):
1557 '''Get the C{n-vector} X, Y, Z and H components (L{Vector4Tuple}C{(x, y, z, h)})
1559 @note: These are C{n-vector} x, y and z components, I{NOT}
1560 geocentric (ECEF) x, y and z coordinates!
1561 '''
1562 return self.xyz.to4Tuple(self.height)
1565class _toCartesian3(object): # see also .geodesicw._wargs, .vector2d._numpy
1566 '''(INTERNAL) Wrapper to convert 2 other points.
1567 '''
1568 @contextmanager # <https://www.python.org/dev/peps/pep-0343/> Examples
1569 def __call__(self, p, p2, p3, wrap, **kwds):
1570 try:
1571 if wrap:
1572 p2, p3 = map1(_Wrap.point, p2, p3)
1573 kwds = _xkwds(kwds, wrap=wrap)
1574 yield (p. toCartesian().copy(name=_point_), # copy to rename
1575 p._toCartesianEcef(up=4, point2=p2),
1576 p._toCartesianEcef(up=4, point3=p3))
1577 except (AssertionError, TypeError, ValueError) as x:
1578 raise _xError(x, point=p, point2=p2, point3=p3, **kwds)
1580_toCartesian3 = _toCartesian3() # PYCHOK singleton
1583def _trilaterate5(p1, d1, p2, d2, p3, d3, area=True, eps=EPS1, # MCCABE 13
1584 radius=R_M, wrap=False):
1585 '''(INTERNAL) Trilaterate three points by area overlap or by
1586 perimeter intersection of three circles.
1588 @note: The B{C{radius}} is only needed for both the n-vectorial
1589 and C{sphericalTrigonometry.LatLon.distanceTo} methods and
1590 silently ignored by the C{ellipsoidalExact}, C{-GeodSolve},
1591 C{-Karney} and C{-Vincenty.LatLon.distanceTo} methods.
1592 '''
1593 p2, p3, w = _unrollon3(p1, p2, p3, wrap)
1595 r1 = Distance_(distance1=d1)
1596 r2 = Distance_(distance2=d2)
1597 r3 = Distance_(distance3=d3)
1598 m = 0 if area else (r1 + r2 + r3)
1599 pc = 0
1600 t = []
1601 for _ in range(3):
1602 try: # intersection of circle (p1, r1) and (p2, r2)
1603 c1, c2 = p1.intersections2(r1, p2, r2, wrap=w)
1605 if area: # check overlap
1606 if c1 is c2: # abutting
1607 c = c1
1608 else: # nearest point on radical
1609 c = p3.nearestOn(c1, c2, within=True, wrap=w)
1610 d = r3 - p3.distanceTo(c, radius=radius, wrap=w)
1611 if d > eps: # sufficient overlap
1612 t.append((d, c))
1613 m = max(m, d)
1615 else: # check intersection
1616 for c in ((c1,) if c1 is c2 else (c1, c2)):
1617 d = fabs(r3 - p3.distanceTo(c, radius=radius, wrap=w))
1618 if d < eps: # below margin
1619 t.append((d, c))
1620 m = min(m, d)
1622 except IntersectionError as x:
1623 if _concentric_ in str(x): # XXX ConcentricError?
1624 pc += 1
1626 p1, r1, p2, r2, p3, r3 = p2, r2, p3, r3, p1, r1 # rotate
1628 if t: # get min, max, points and count ...
1629 t = tuple(sorted(t))
1630 n = len(t), # as 1-tuple
1631 # ... or for a single trilaterated result,
1632 # min *is* max, min- *is* maxPoint and n=1, 2 or 3
1633 return Trilaterate5Tuple(t[0] + t[-1] + n) # *(t[0] + ...)
1635 elif area and pc == 3: # all pairwise concentric ...
1636 r, p = min((r1, p1), (r2, p2), (r3, p3))
1637 m = max(r1, r2, r3)
1638 # ... return "smallest" point twice, the smallest
1639 # and largest distance and n=0 for concentric
1640 return Trilaterate5Tuple(float(r), p, float(m), p, 0)
1642 n, f = (_overlap_, max) if area else (_intersection_, min)
1643 t = _COMMASPACE_(_no_(n), '%s %.3g' % (f.__name__, m))
1644 raise IntersectionError(area=area, eps=eps, wrap=wrap, txt=t)
1647__all__ += _ALL_DOCS(LatLonBase)
1649# **) MIT License
1650#
1651# Copyright (C) 2016-2023 -- mrJean1 at Gmail -- All Rights Reserved.
1652#
1653# Permission is hereby granted, free of charge, to any person obtaining a
1654# copy of this software and associated documentation files (the "Software"),
1655# to deal in the Software without restriction, including without limitation
1656# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1657# and/or sell copies of the Software, and to permit persons to whom the
1658# Software is furnished to do so, subject to the following conditions:
1659#
1660# The above copyright notice and this permission notice shall be included
1661# in all copies or substantial portions of the Software.
1662#
1663# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1664# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1665# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1666# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1667# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1668# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1669# OTHER DEALINGS IN THE SOFTWARE.