Coverage for pygeodesy/sphericalBase.py : 93%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
C{LatLonSphericalBase}.
Pure Python implementation of geodetic (lat-/longitude) functions, transcribed in part from JavaScript originals by I{(C) Chris Veness 2011-2016} and published under the same MIT Licence**, see U{Latitude/Longitude<https://www.Movable-Type.co.UK/scripts/latlong.html>}.
@newfield example: Example, Examples '''
degrees360, property_RO, sincos2d, \ tanPI_2_2, _TypeError, wrapPI
# XXX the following classes are listed only to get # Epydoc to include class and method documentation
'''(INTERNAL) Base class for spherical C{Cartesian}s. '''
'''(INTERNAL) Base class for spherical C{LatLon}s. '''
'''Create a spherical C{LatLon} point frome the given lat-, longitude and height on the given datum.
@param lat: Latitude (C{degrees} or DMS C{[N|S]}). @param lon: Longitude (C{degrees} or DMS C{str[E|W]}). @keyword height: Optional elevation (C{meter}, the same units as the datum's half-axes). @keyword datum: Optional, shperical datum to use (L{Datum}). @keyword name: Optional name (string).
@raise TypeError: B{C{datum}} is not a L{datum} or not spherical.
@example:
>>> p = LatLon(51.4778, -0.0016) # height=0, datum=Datums.WGS84 '''
'''Return the initial and final bearing (forward and reverse azimuth) from this to an other point.
@param other: The other point (C{LatLon}). @keyword wrap: Wrap and unroll longitudes (C{bool}). @keyword raiser: Optionally, raise L{CrossError} (C{bool}).
@return: A L{Bearing2Tuple}C{(initial, final)}.
@raise TypeError: The I{other} point is not spherical.
@see: Methods C{initialBearingTo} and C{finalBearingTo}. ''' # .initialBearingTo is inside .-Nvector and .-Trigonometry self.finalBearingTo( other, wrap=wrap, raiser=raiser))
def datum(self): '''Get this point's datum (L{Datum}). '''
def datum(self, datum): '''Set this point's datum I{without conversion}.
@param datum: New datum (L{Datum}).
@raise TypeError: If B{C{datum}} is not a L{Datum} or not spherical. ''' raise _IsNotError('spherical', datum=datum)
'''Return the final bearing (reverse azimuth) from this to an other point.
@param other: The other point (spherical C{LatLon}). @keyword wrap: Wrap and unroll longitudes (C{bool}). @keyword raiser: Optionally, raise L{CrossError} (C{bool}).
@return: Final bearing (compass C{degrees360}).
@raise TypeError: The I{other} point is not spherical.
@example:
>>> p = LatLon(52.205, 0.119) >>> q = LatLon(48.857, 2.351) >>> b = p.finalBearingTo(q) # 157.9 '''
# final bearing is the reverse of the other, initial one; # .initialBearingTo is inside .-Nvector and .-Trigonometry
def isEllipsoidal(self): '''Check whether this C{LatLon} is ellipsoidal (C{bool}). '''
def isSpherical(self): '''Check whether this C{LatLon} is spherical (C{bool}). '''
'''Return the maximum latitude reached when travelling on a great circle on given bearing from this point based on Clairaut's formula.
The maximum latitude is independent of longitude and the same for all points on a given latitude.
Negate the result for the minimum latitude (on the Southern hemisphere).
@param bearing: Initial bearing (compass C{degrees360}).
@return: Maximum latitude (C{degrees90}).
@JSname: I{maxLatitude}. '''
'''Return the minimum latitude reached when travelling on a great circle on given bearing from this point.
@param bearing: Initial bearing (compass C{degrees360}).
@return: Minimum latitude (C{degrees90}).
@see: Method L{maxLat} for more details.
@JSname: I{minLatitude}. ''' return -self.maxLat(bearing)
'''Parse a string representing lat-/longitude point and return a C{LatLon}.
The lat- and longitude must be separated by a sep[arator] character. If height is present it must follow and be separated by another sep[arator]. Lat- and longitude may be swapped, provided at least one ends with the proper compass direction.
For more details, see functions L{parse3llh} and L{parseDMS} in module L{dms}.
@param strll: Lat, lon [, height] (C{str}). @keyword height: Optional , default height (C{meter}). @keyword sep: Optional separator (C{str}).
@return: The point (spherical C{LatLon}).
@raise ValueError: Invalid I{strll}. ''' return self.classof(*parse3llh(strll, height=height, sep=sep))
'''(INTERNAL) Rhumb_ helper function.
@param other: The other point (spherical C{LatLon}). '''
# if |db| > 180 take shorter rhumb # line across the anti-meridian
'''Return the initial bearing (forward azimuth) from this to an other point along a rhumb (loxodrome) line.
@param other: The other point (spherical C{LatLon}).
@return: Initial bearing (compass C{degrees360}).
@raise TypeError: The I{other} point is not spherical.
@example:
>>> p = LatLon(51.127, 1.338) >>> q = LatLon(50.964, 1.853) >>> b = p.rhumbBearingTo(q) # 116.7 '''
'''Return the destination point having travelled along a rhumb (loxodrome) line from this point the given distance on the given bearing.
@param distance: Distance travelled (C{meter}, same units as I{radius}). @param bearing: Bearing from this point (compass C{degrees360}). @keyword radius: Optional, mean earth radius (C{meter}). @keyword height: Optional height, overriding the default height (C{meter}, same unit as I{radius}).
@return: The destination point (spherical C{LatLon}).
@example:
>>> p = LatLon(51.127, 1.338) >>> q = p.rhumbDestination(40300, 116.7) # 50.9642°N, 001.8530°E
@JSname: I{rhumbDestinationPoint} '''
# normalize latitude if past pole a2 = PI - a2 a2 = -PI - a2
# E-W course becomes ill-conditioned with 0/0
'''Return the distance from this to an other point along a rhumb (loxodrome) line.
@param other: The other point (spherical C{LatLon}). @keyword radius: Optional, mean earth radius (C{meter}).
@return: Distance (C{meter}, the same units as I{radius}).
@raise TypeError: The I{other} point is not spherical.
@example:
>>> p = LatLon(51.127, 1.338) >>> q = LatLon(50.964, 1.853) >>> d = p.rhumbDistanceTo(q) # 403100 ''' # see <https://www.EdWilliams.org/avform.htm#Rhumb>
# on Mercator projection, longitude distances shrink # by latitude; the 'stretch factor' q becomes ill- # conditioned along E-W line (0/0); use an empirical # tolerance to avoid it else: a, _ = self.to2ab() q = cos(a)
'''Return the (loxodromic) midpoint between this and an other point.
@param other: The other point (spherical LatLon). @keyword height: Optional height, overriding the mean height (C{meter}).
@return: The midpoint (spherical C{LatLon}).
@raise TypeError: The I{other} point is not spherical.
@example:
>>> p = LatLon(51.127, 1.338) >>> q = LatLon(50.964, 1.853) >>> m = p.rhumb_midpointTo(q) >>> m.toStr() # '51.0455°N, 001.5957°E' '''
# see <https://MathForum.org/library/drmath/view/51822.html> b1 += PI2 # crossing anti-meridian
-b2 * log(f1), (b2 - b1) * log(f3)) / f
'''Convert this C{LatLon} point to a I{WM} coordinate.
@keyword radius: Optional earth radius (C{meter}).
@return: The WM coordinate (L{Wm}).
@see: Function L{toWm} in module L{webmercator} for details. '''
# **) MIT License # # Copyright (C) 2016-2020 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |