Coverage for pygeodesy/formy.py : 98%

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 -*-
@newfield example: Example, Examples ''' _limiterrors, map1, _xinstanceof Points2Tuple, Vector3Tuple degrees90, degrees180, degrees360, \ isNumpy2, isTuple2, sincos2, unroll180, unrollPI, \ wrap90, wrap180, wrapPI, wrapPI_2
# all public contants, classes and functions
'''Insufficient number of points. '''
# scale factor cos(mean of lats) for delta lon
# scale factor cos(mean of phis) for delta lam
'''Return the antipode, the point diametrically opposite to a given point in C{degrees}.
@arg lat: Latitude (C{degrees}). @arg lon: Longitude (C{degrees}).
@return: A L{LatLon2Tuple}C{(lat, lon)}.
@see: U{Geosphere<https://CRAN.R-Project.org/web/packages/geosphere/geosphere.pdf>}. '''
'''Return the antipode, the point diametrically opposite to a given point in C{radians}.
@arg phi: Latitude (C{radians}). @arg lam: Longitude (C{radians}).
@return: A L{PhiLam2Tuple}C{(phi, lam)}.
@see: U{Geosphere<https://CRAN.R-Project.org/web/packages/geosphere/geosphere.pdf>}. '''
'''Compute the initial or final bearing (forward or reverse azimuth) between a (spherical) start and end point.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg options: Optional keyword arguments for function L{bearing_}.
@return: Initial or final bearing (compass C{degrees360}) or zero if start and end point coincide. '''
'''Compute the initial or final bearing (forward or reverse azimuth) between a (spherical) start and end point.
@arg phi1: Start latitude (C{radians}). @arg lam1: Start longitude (C{radians}). @arg phi2: End latitude (C{radians}). @arg lam2: End longitude (C{radians}). @kwarg final: Return final bearing if C{True}, initial otherwise (C{bool}). @kwarg wrap: Wrap and L{unrollPI} longitudes (C{bool}).
@return: Initial or final bearing (compass C{radiansPI2}) or zero if start and end point coincide. ''' else:
# see <https://MathForum.org/library/drmath/view/55417.html>
'''Return the angle from North for the direction vector M{(lon2 - lon1, lat2 - lat1)} between two points.
Suitable only for short, non-near-polar vectors up to a few hundred Km or Miles. Use function L{bearing} for longer vectors.
@arg lat1: From latitude (C{degrees}). @arg lon1: From longitude (C{degrees}). @arg lat2: To latitude (C{degrees}). @arg lon2: To longitude (C{degrees}). @kwarg adjust: Adjust the longitudinal delta by the cosine of the mean latitude (C{bool}). @kwarg wrap: Wrap and L{unroll180} longitudes (C{bool}).
@return: Compass angle from North (C{degrees360}).
@note: Courtesy Martin Schultz.
@see: U{Local, flat earth approximation <https://www.EdWilliams.org/avform.htm#flat>}. '''
'''Compute the distance between two points using the U{spherical Law of Cosines <https://www.Movable-Type.co.UK/scripts/latlong.html#cosine-law>} fromula.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg radius: Mean earth radius (C{meter}). @kwarg wrap: Wrap and L{unroll180} longitudes (C{bool}).
@return: Distance (C{meter}, same units as B{C{radius}}).
@raise TypeError: Invalid B{C{datum}}.
@see: Functions L{cosineLaw_}, L{equirectangular}, L{euclidean}, L{flatLocal}, L{flatPolar}, L{haversine}, L{vincentys} and method L{Ellipsoid.distance2}.
@note: See note at function L{vincentys_}. '''
'''Compute the I{angular} distance between two points using the U{spherical Law of Cosines <https://www.Movable-Type.co.UK/scripts/latlong.html#cosine-law>} fromula.
@arg phi2: End latitude (C{radians}). @arg phi1: Start latitude (C{radians}). @arg lam21: Longitudinal delta, M{end-start} (C{radians}).
@return: Angular distance (C{radians}).
@see: Functions L{cosineLaw}, L{equirectangular_}, L{euclidean_}, L{flatLocal_}, L{flatPolar_}, L{haversine_} and L{vincentys_}.
@note: See note at function L{vincentys_}. '''
'''Compute the distance between two points using the U{Equirectangular Approximation / Projection <https://www.Movable-Type.co.UK/scripts/latlong.html#equirectangular>}.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg radius: Mean earth radius (C{meter}). @kwarg options: Optional keyword arguments for function L{equirectangular_}.
@return: Distance (C{meter}, same units as B{C{radius}}).
@see: Function L{equirectangular_} for more details, the available B{C{options}}, errors, restrictions and other, approximate or accurate distance functions. '''
adjust=True, limit=45, wrap=False): '''Compute the distance between two points using the U{Equirectangular Approximation / Projection <https://www.Movable-Type.co.UK/scripts/latlong.html#equirectangular>}.
This approximation is valid for short distance of several hundred Km or Miles, see the B{C{limit}} keyword argument and the L{LimitError}.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg adjust: Adjust the wrapped, unrolled longitudinal delta by the cosine of the mean latitude (C{bool}). @kwarg limit: Optional limit for lat- and longitudinal deltas (C{degrees}) or C{None} or C{0} for unlimited. @kwarg wrap: Wrap and L{unroll180} longitudes (C{bool}).
@return: A L{Distance4Tuple}C{(distance2, delta_lat, delta_lon, unroll_lon2)}.
@raise LimitError: If the lat- and/or longitudinal delta exceeds the B{C{-limit..+limit}} range and L{limiterrors} set to C{True}.
@see: U{Local, flat earth approximation <https://www.EdWilliams.org/avform.htm#flat>}, functions L{equirectangular}, L{cosineLaw}, L{euclidean}, L{flatLocal}, L{flatPolar}, L{haversine}, L{vincentys} and methods L{Ellipsoid.distance2}, C{LatLon.distanceTo*} and C{LatLon.equirectangularTo}. '''
and max(abs(d_lat), abs(d_lon)) > limit > 0: t = fstr((lat1, lon1, lat2, lon2), prec=4) raise LimitError('%s(%s, limit=%s) delta exceeds limit' % ('equirectangular_', t, fstr(limit, prec=2)))
'''Approximate the C{Euclidian} distance between two (spherical) points.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg radius: Mean earth radius (C{meter}). @kwarg adjust: Adjust the longitudinal delta by the cosine of the mean latitude (C{bool}). @kwarg wrap: Wrap and L{unroll180} longitudes (C{bool}).
@return: Distance (C{meter}, same units as B{C{radius}}).
@see: U{Distance between two (spherical) points <https://www.EdWilliams.org/avform.htm#Dist>}, functions L{euclidean_}, L{cosineLaw}, L{equirectangular}, L{flatLocal}, L{flatPolar}, L{haversine}, L{vincentys} and methods L{Ellipsoid.distance2}, C{LatLon.distanceTo*} and C{LatLon.equirectangularTo}. '''
'''Approximate the I{angular} C{Euclidean} distance between two (spherical) points.
@arg phi2: End latitude (C{radians}). @arg phi1: Start latitude (C{radians}). @arg lam21: Longitudinal delta, M{end-start} (C{radians}). @kwarg adjust: Adjust the longitudinal delta by the cosine of the mean latitude (C{bool}).
@return: Angular distance (C{radians}).
@see: Functions L{euclidean}, L{cosineLaw_}, L{equirectangular_}, L{flatLocal_}, L{flatPolar_}, L{haversine_} and L{vincentys_}. '''
'''Compute the distance between two (ellipsoidal) points using the U{ellipsoidal Earth to plane projection <https://WikiPedia.org/wiki/Geographical_distance#Ellipsoidal_Earth_projected_to_a_plane>} fromula.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg datum: Optional, (ellipsoidal) datum to use (L{Datum}). @kwarg wrap: Wrap and L{unroll180} longitudes (C{bool}).
@return: Distance (C{meter}, same units as the B{C{datum}}'s ellipsoid axes).
@raise TypeError: Invalid B{C{datum}}.
@note: The meridional and prime_vertical radii of curvature are taken and scaled at the mean latitude.
@see: Functions L{flatLocal_}, L{cosineLaw}, L{flatPolar}, L{equirectangular}, L{euclidean}, L{haversine}, L{vincentys}, method L{Ellipsoid.distance2} and U{local, flat earth approximation <https://www.edwilliams.org/avform.htm#flat>}. '''
'''Compute the distance between two (ellipsoidal) points using the U{ellipsoidal Earth to plane projection <https://WikiPedia.org/wiki/Geographical_distance#Ellipsoidal_Earth_projected_to_a_plane>} fromula.
@arg phi2: End latitude (C{radians}). @arg phi1: Start latitude (C{radians}). @arg lam21: Longitudinal delta, M{end-start} (C{radians}). @kwarg datum: Optional, (ellipsoidal) datum to use (L{Datum}).
@return: Distance (C{meter}, same units as the B{C{datum}}'s ellipsoid axes).
@raise TypeError: Invalid B{C{datum}}.
@note: The meridional and prime_vertical radii of curvature are taken and scaled at the mean latitude.
@see: Functions L{flatLocal}, L{cosineLaw_}, L{flatPolar_}, L{equirectangular_}, L{euclidean_}, L{haversine_} and L{vincentys_} and U{local, flat earth approximation <https://www.edwilliams.org/avform.htm#flat>}. '''
'''Compute the distance between two (spherical) points using the U{polar coordinate flat-Earth <https://WikiPedia.org/wiki/Geographical_distance#Polar_coordinate_flat-Earth_formula>} formula.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg radius: Mean earth radius (C{meter}). @kwarg wrap: Wrap and L{unroll180} longitudes (C{bool}).
@return: Distance (C{meter}, same units as B{C{radius}}).
@see: Functions L{flatPolar_}, L{cosineLaw}, L{flatLocal}, L{equirectangular}, L{euclidean}, L{haversine} and L{vincentys}. '''
'''Compute the I{angular} distance between two (spherical) points using the U{polar coordinate flat-Earth <https://WikiPedia.org/wiki/Geographical_distance#Polar_coordinate_flat-Earth_formula>} formula.
@arg phi2: End latitude (C{radians}). @arg phi1: Start latitude (C{radians}). @arg lam21: Longitudinal delta, M{end-start} (C{radians}).
@return: Angular distance (C{radians}).
@see: Functions L{flatPolar}, L{cosineLaw_}, L{equirectangular_}, L{euclidean_}, L{flatLocal_}, L{haversine_} and L{vincentys_}. '''
'''Compute the distance between two (spherical) points using the U{Haversine<https://www.Movable-Type.co.UK/scripts/latlong.html>} formula.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg radius: Mean earth radius (C{meter}). @kwarg wrap: Wrap and L{unroll180} longitudes (C{bool}).
@return: Distance (C{meter}, same units as B{C{radius}}).
@see: U{Distance between two (spherical) points <https://www.EdWilliams.org/avform.htm#Dist>}, functions L{cosineLaw}, L{equirectangular}, L{euclidean}, L{flatLocal}, L{flatPolar}, L{vincentys} and methods L{Ellipsoid.distance2}, C{LatLon.distanceTo*} and C{LatLon.equirectangularTo}.
@note: See note at function L{vincentys_}. '''
'''Compute the I{angular} distance between two (spherical) points using the U{Haversine<https://www.Movable-Type.co.UK/scripts/latlong.html>} formula.
@arg phi2: End latitude (C{radians}). @arg phi1: Start latitude (C{radians}). @arg lam21: Longitudinal delta, M{end-start} (C{radians}).
@return: Angular distance (C{radians}).
@see: Functions L{haversine}, L{cosineLaw_}, L{equirectangular_}, L{euclidean_}, L{flatLocal_}, L{flatPolar_} and L{vincentys_}.
@note: See note at function L{vincentys_}. '''
except ValueError: r = 0 if h < 0.5 else PI
'''Determine the height above the (spherical) earth after traveling along a straight line at a given tilt.
@arg angle: Tilt angle above horizontal (C{degrees}). @arg distance: Distance along the line (C{meter} or same units as B{C{radius}}). @kwarg radius: Optional mean earth radius (C{meter}).
@return: Height (C{meter}, same units as B{C{distance}} and B{C{radius}}).
@raise ValueError: Invalid B{C{angle}}, B{C{distance}} or B{C{radius}}.
@see: U{MultiDop geog_lib.GeogBeamHt<https://GitHub.com/NASA/MultiDop>} (U{Shapiro et al. 2009, JTECH <https://Journals.AMetSoc.org/doi/abs/10.1175/2009JTECHA1256.1>} and U{Potvin et al. 2012, JTECH <https://Journals.AMetSoc.org/doi/abs/10.1175/JTECH-D-11-00019.1>}). ''' d, r = r, d
raise ValueError('%s%r' % (heightOf.__name__, (angle, distance, radius)))
'''Determine the distance to the horizon from a given altitude above the (spherical) earth.
@arg height: Altitude (C{meter} or same units as B{C{radius}}). @kwarg radius: Optional mean earth radius (C{meter}). @kwarg refraction: Consider atmospheric refraction (C{bool}).
@return: Distance (C{meter}, same units as B{C{height}} and B{C{radius}}).
@raise ValueError: Invalid B{C{height}} or B{C{radius}}.
@see: U{Distance to horizon<https://www.EdWilliams.org/avform.htm#Horizon>}. ''' raise ValueError('%s%r' % (horizon.__name__, (r, r)))
else:
'''Check whether two points are antipodal, on diametrically opposite sides of the earth.
@arg lat1: Latitude of one point (C{degrees}). @arg lon1: Longitude of one point (C{degrees}). @arg lat2: Latitude of the other point (C{degrees}). @arg lon2: Longitude of the other point (C{degrees}). @kwarg eps: Tolerance for near-equality (C{degrees}).
@return: C{True} if points are antipodal within the B{C{eps}} tolerance, C{False} otherwise.
@see: U{Geosphere<https://CRAN.R-Project.org/web/packages/geosphere/geosphere.pdf>}. ''' abs(abs(wrap180(lon1) - wrap180(lon2)) % 360 - 180) < eps
'''Check whether two points are antipodal, on diametrically opposite sides of the earth.
@arg phi1: Latitude of one point (C{radians}). @arg lam1: Longitude of one point (C{radians}). @arg phi2: Latitude of the other point (C{radians}). @arg lam2: Longitude of the other point (C{radians}). @kwarg eps: Tolerance for near-equality (C{radians}).
@return: C{True} if points are antipodal within the B{C{eps}} tolerance, C{False} otherwise.
@see: U{Geosphere<https://CRAN.R-Project.org/web/packages/geosphere/geosphere.pdf>}. ''' abs(abs(wrapPI(lam1) - wrapPI(lam2)) % PI2 - PI) < eps
'''Convert lat-, longitude to C{n-vector} (normal to the earth's surface) X, Y and Z components.
@arg lat: Latitude (C{degrees}). @arg lon: Longitude (C{degrees}).
@return: A L{Vector3Tuple}C{(x, y, z)}.
@see: Function L{philam2n_xyz}.
@note: These are C{n-vector} x, y and z components, I{NOT} geocentric ECEF x, y and z coordinates! '''
'''Convert C{n-vector} components to lat- and longitude in C{degrees}.
@arg x: X component (C{scalar}). @arg y: Y component (C{scalar}). @arg z: Z component (C{scalar}).
@return: A L{LatLon2Tuple}C{(lat, lon)}.
@see: Function L{n_xyz2philam}. '''
'''Convert C{n-vector} components to lat- and longitude in C{radians}.
@arg x: X component (C{scalar}). @arg y: Y component (C{scalar}). @arg z: Z component (C{scalar}).
@return: A L{PhiLam2Tuple}C{(phi, lam)}.
@see: Function L{n_xyz2latlon}. '''
'''Convert lat-, longitude to C{n-vector} (normal to the earth's surface) X, Y and Z components.
@arg phi: Latitude (C{radians}). @arg lam: Longitude (C{radians}).
@return: A L{Vector3Tuple}C{(x, y, z)}.
@see: Function L{latlon2n_xyz}.
@note: These are C{n-vector} x, y and z components, I{NOT} geocentric ECEF x, y and z coordinates! ''' # Kenneth Gade eqn 3, but using right-handed # vector x -> 0°E,0°N, y -> 90°E,0°N, z -> 90°N
'''Check a path or polygon represented by points.
@arg points: The path or polygon points (C{LatLon}[]) @kwarg closed: Optionally, consider the polygon closed, ignoring any duplicate or closing final B{C{points}} (C{bool}). @kwarg base: Optionally, check all B{C{points}} against this base class, if C{None} don't check. @kwarg Error: Exception to raise (C{ValueError}).
@return: A L{Points2Tuple}C{(number, points)} with the number of points and the points C{list} or C{tuple}.
@raise PointsError: Insufficient number of B{C{points}}.
@raise TypeError: Some B{C{points}} are not B{C{base}} compatible. '''
# remove duplicate or closing final points # XXX following line is unneeded if points # are always indexed as ... i in range(n)
raise Error('too few %s: %s' % ('points', n))
'''Compute the distance between two (spherical) points using U{Vincenty's<https://WikiPedia.org/wiki/Great-circle_distance>} spherical formula.
@arg lat1: Start latitude (C{degrees}). @arg lon1: Start longitude (C{degrees}). @arg lat2: End latitude (C{degrees}). @arg lon2: End longitude (C{degrees}). @kwarg radius: Mean earth radius (C{meter}). @kwarg wrap: Wrap and L{unroll180} longitudes (C{bool}).
@return: Distance (C{meter}, same units as B{C{radius}}).
@see: Functions L{vincentys_}, L{cosineLaw}, L{equirectangular}, L{euclidean}, L{flatLocal}, L{flatPolar}, L{haversine} and methods L{Ellipsoid.distance2}, C{LatLon.distanceTo*} and C{LatLon.equirectangularTo}.
@note: See note at function L{vincentys_}. '''
'''Compute the I{angular} distance between two (spherical) points using U{Vincenty's<https://WikiPedia.org/wiki/Great-circle_distance>} spherical formula.
@arg phi2: End latitude (C{radians}). @arg phi1: Start latitude (C{radians}). @arg lam21: Longitudinal delta, M{end-start} (C{radians}).
@return: Angular distance (C{radians}).
@see: Functions L{vincentys}, L{cosineLaw_}, L{equirectangular_}, L{euclidean_}, L{flatLocal_}, L{flatPolar_} and L{haversine_}.
@note: Functions L{vincentys_}, L{haversine_} and L{cosineLaw_} produce equivalent results, but L{vincentys_} is suitable for antipodal points but slightly more expensive (M{3 cos, 3 sin, 1 hypot, 1 atan2, 6 mul, 2 add}) than L{haversine_} (M{2 cos, 2 sin, 2 sqrt, 1 atan2, 5 mul, 1 add}) and L{cosineLaw_} (M{3 cos, 3 sin, 1 acos, 3 mul, 1 add}). '''
# **) 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. |