Package pygeodesy
[frames] | no frames]

Package pygeodesy

A pure Python implementation of geodesy tools for various ellipsoidal and spherical earth models using precision trigonometric, vector-based and approximate methods for geodetic (lat-/longitude) and geocentric cartesian (x/y/z) coordinates.

Transcribed from JavaScript originals by Chris Veness (C) 2005-2016 and published under the same MIT License**.

There are three modules for ellipsoidal earth models, ellipsoidalKarney, -Vincenty and -Nvector and two for spherical ones, sphericalTrigonometry and -Nvector. Each module provides a LatLon class with methods and functions to compute distance, initial and final bearing, intermediate and nearest points, area, perimeter, conversions and unrolling, among other things. For more information and further details see the documentation, the descriptions of Latitude/Longitude, Vincenty and Vector-based geodesy, the original JavaScript source or docs and GeographicLib Python.

Also included are modules for conversions to and from UTM (Universal Transverse Mercator) and Web Mercator (Pseudo-Mercator) coordinates, MGRS (NATO Military Grid Reference System) and OSGR (British Ordinance Survery Grid Reference) grid references and a module for encoding and decoding Geohashes.

Two other modules provide Lambert conformal conic projections and positions (from John P. Snyder, "Map Projections -- A Working Manual", 1987, pp 107-109) and several functions to simplify or linearize a path of LatLon points (or a NumPy array), including implementations of the Ramer-Douglas-Peucker, the Visvalingam-Whyatt and the Reumann-Witkam algorithms and modified versions of the former.

All Python source code has been statically checked with PyChecker, PyFlakes, PyCodeStyle (formerly Pep8) and McCabe using Python 2.7.15 and with Flake8 using Python 3.7.0, both in 64-bit on macOS 10.13.6 High Sierra.

The tests have been run in 64-bit with PyPy-Python 2.7.13, Python 2.7.15 (with geographiclib 1.49 and numpy 1.14.0), Intel-Python 3.5.3 (and numpy 1.11.3) and Python 3.7.0 (with geographiclib 1.49), all on macOS 10.13.6 High Sierra, with 64-bit Python 3.7.0 on Debian GNU/Linux 9 and with Pythonista 3.2 Python 2.7.12 and 3.6.1 (both with numpy 1.8.0) on iOS 11.4.1 (iPad and iPhone X).

Previously, the tests were run with 64-bit Python 2.6.9 (and numpy 1.6.2), 2.7.10 (and numpy 1.8.0rc1), 2.7.13, 2.7.14 (and numpy 1.13.1), 3.5.3, 3.6.2, 3.6.3, 3.6.4 and 3.6.5 on MacOS X 10.10 Yosemite, MacOS X 10.11 El Capitan, macOS 10.12 Sierra, macOS 10.13.4 and/or 10.13.5 High Sierra, with Pythonista 3.1 on iOS 10.3.3, 11.0.3, 11.1.2 and 11.3, with 32-bit Python 2.6.6 on Windows XP SP3, with 32-bit Python 2.7.14 on Windows 10 Pro.

In addition to the PyGeodesy package, the distribution files contain the tests, the test results and the complete documentation (generated by Epydoc using command line: epydoc --html --no-private --no-source --name=PyGeodesy --url=... -v pygeodesy).

To install PyGeodesy, type pip install PyGeodesy or easy_install PyGeodesy in a terminal or command window. Alternatively, download PyGeodesy- from PyPI or GitHub, unzip the downloaded file, cd to directory Pygeodesy- and type python setup.py install. To run all PyGeodesy tests, type python setup.py test before installation.

Installation of NumPy and GeographicLib is optional. However, the latter is required for module ellipsoidalKarney classes LatLon and Cartesian and the functions areaOf and perimeterOf.

Some function and method names differ from the JavaScript version. In such cases documentation tag JS name: shows the original JavaScript name.

__

**) Copyright (C) 2016-2018 -- mrJean1 at Gmail dot com

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.


Version: 18.09.09

Submodules

Classes
  CrossError
Error raised for zero or near-zero vectorial cross products, occurring for coincident or colinear points, paths or bearings.
  Geohash
Geohash class, sub-class of str.
  VincentyError
Error raised from Vincenty's direct and inverse methods for coincident points and lack of convergence.
  Conic
Lambert conformal conic projection (1- or 2-SP).
  Datum
Ellipsoid and transform parameters for an earth model.
  Ellipsoid
Ellipsoid with semi-major, semi-minor axis, inverse flattening and a number of other pre-computed, frequently used values.
  Fsum
Precision floating point summation similar to standard Python function math.fsum.
  LatLon2psxy
Wrapper for LatLon points as "on-the-fly" pseudo-xy coordinates.
  LatLon_
Low-overhead LatLon class for Numpy2LatLon or Tuple2LatLon'
  Lcc
Lambert conformal conic East-/Northing location.
  LimitError
Error raised for lat- and/or longitudinal deltas exceeding the limit in functions equirectangular and equirectangular_.
  Mgrs
Military Grid Reference System (MGRS/NATO) references, with method to convert to UTM coordinates.
  Numpy2LatLon
Wrapper for NumPy arrays as "on-the-fly" LatLon points.
  Osgr
Ordinance Survey Grid References (OSGR) coordinate.
  RangeError
Error raised for lat- or longitude values outside the clip, clipLat, clipLon or limit range in function clipDMS, parse3llh, parseDMS or parseDMS2.
  Transform
Helmert transformation.
  Tuple2LatLon
Wrapper for tuple sequences as "on-the-fly" LatLon points.
  UTMError
UTM parse or other error.
  Utm
Universal Transverse Mercator (UTM) coordinate.
  Wm
Web Mercator (WM) coordinate.
Functions
 
crosserrors(raiser=None)
Get/set raising of vectorial cross product errors.
 
acos1(x)
Return math.acos(max(-1, min(1, x))).
 
antipode(lat, lon)
Return the antipode, the point diametrically opposite to the given lat- and longitude.
 
areaOf(points, adjust=True, radius=6371008.77141, wrap=True)
Approximate the area of a polygon defined by an array, list, sequence, set or tuple of points.
 
bearingDMS(bearing, form='d', prec=None, sep='')
Convert bearing to a string.
 
bounds(points, wrap=True, LatLon=None)
Determine the lower-left and upper-right corners of a polygon/-line defined by a list, sequence, set or tuple of points.
 
cbrt(x)
Compute the cubic root x**(1/3).
 
cbrt2(x)
Compute the cubic root squared x**(2/3).
 
classname(inst, prefixed=None)
Return an instance' module and class name.
 
classnaming(prefixed=None)
Set the default class naming for [module.].class names.
 
clipDMS(deg, limit)
Clip a lat- or longitude to the given range.
 
compassAngle(lat0, lon0, lat1, lon1)
Return the angle from North for the direction vector (lon1 - lon0, lat1 - lat0) between two points.
 
compassDMS(bearing, form='d', prec=None, sep='')
Convert bearing to a string suffixed with compass point.
 
compassPoint(bearing, prec=3)
Convert bearing to a compass point.
 
degrees(x)
Convert angle x from radians to degrees.
 
degrees180(rad)
Convert and wrap radians to degrees (-180..+180].
 
degrees360(rad)
Convert and wrap radians to degrees (0..+360].
 
degrees90(rad)
Convert and wrap radians to degrees (-270..+90].
 
elevation2(lat, lon, timeout=2.0)
Get the geoid elevation at an NAD83 to NAVD88 location.
 
enStr2(easting, northing, prec, *extras)
Return easting, northing string representations.
 
equirectangular(lat1, lon1, lat2, lon2, radius=6371008.77141, **options)
Compute the distance between two points using the Equirectangular Approximation / Projection.
 
equirectangular_(lat1, lon1, lat2, lon2, adjust=True, limit=45, wrap=False)
Compute the distance between two points using the Equirectangular Approximation / Projection.
 
fStr(floats, prec=6, sep=', ', fmt='%.*f', ints=False)
Convert floats to string, optionally with trailing zero decimals stripped.
 
fStrzs(fstr)
Strip trailing zero decimals from a float string.
 
false2f(value, name='value', false=True)
Convert a false east-/northing to non-negative float.
 
favg(v1, v2, f=0.5)
Return the weighted average of two values.
 
fdot(a, *b)
Return the precision dot product sum(a[i] * b[i] for i=0..len(a)).
 
fdot3(a, b, c, start=0)
Return the precision dot product start + sum(a[i] * b[i] * c[i] for i=0..len(a)).
 
fhorner(x, *cs)
Evaluate the polynomial sum(cs[i] * x**i for i=0..len(cs)) using the Horner form.
 
fmean(xs)
Compute the accurate mean sum(xs[i] for i=0..len(xs)) / len(xs).
 
fpolynomial(x, *cs)
Evaluate the polynomial sum(cs[i] * x**i for i=0..len(cs)).
 
fpowers(x, n, alts=0)
Return a series of powers [x**i for i=1..n].
 
fsum(iterable)
Return an accurate floating point sum of values in the iterable.
 
fsum_(*args)
Precision floating point summation of the positional arguments.
 
ft2m(feet)
Convert International feet to meter (m).
 
geoidHeight2(lat, lon, model=0, timeout=2.0)
Get the NAVD88 geoid height at an NAD83 location.
 
halfs(str2)
Split a string in 2 halfs.
 
haversine(lat1, lon1, lat2, lon2, radius=6371008.77141, wrap=False)
Compute the distance between two points using the Haversine formula.
 
haversine_(a2, a1, b21)
Compute the angular distance between two points using the Haversine formula.
 
heightOf(angle, distance, radius=6371008.77141)
Determine the height above the (spherical) earth after traveling along a straight line at a given tilt.
 
horizon(height, radius=6371008.77141, refraction=False)
Determine the distance to the horizon from a given altitude above the (spherical) earth.
 
hypot(x, y)
Return the Euclidean distance, sqrt(x*x + y*y).
 
hypot1(x)
Compute the norm sqrt(1 + x**2).
 
hypot3(x, y, z)
Compute the norm sqrt(x**2 + y**2 + z**2).
 
inStr(inst, *args, **kwds)
Return the string representation of an instance.
 
isNumpy2(obj)
Check for an Numpy2LatLon points wrapper.
 
isPoints2(obj)
Check for an LatLon2psxy points wrapper.
 
isTuple2(obj)
Check for an Tuple2LatLon points wrapper.
 
isantipode(lat1, lon1, lat2, lon2, eps=2.22044604925e-16)
Check whether two points are anitpodal, on diametrically opposite sides of the earth.
 
isclockwise(points, adjust=False, wrap=True)
Determine the direction of a polygon defined by an array, list, sequence, set or tuple of points.
 
isconvex(points, adjust=False, wrap=True)
Determine whether a polygon defined by an array, list, sequence, set or tuple of points is convex.
 
isenclosedby(latlon, points, wrap=False)
Determine whether a point is enclosed by a polygon defined by an array, list, sequence, set or tuple of points.
 
isfinite(obj)
Check for Inf and NaN values.
 
isint(obj, both=False)
Check for integer type or integer value.
 
isscalar(obj)
Check for scalar types.
 
issequence(obj, *excluded)
Check for sequence types.
 
iterNumpy2(obj)
Iterate over Numpy2 wrappers or other sequences exceeding the threshold.
 
iterNumpy2over(n=None)
Get or set the iterNumpy2 threshold.
 
latDMS(deg, form='dms', prec=2, sep='')
Convert latitude to a string suffixed with N or S.
 
len2(seq)
Make built-in function len work for generators, iterators, etc.
 
limiterrors(raiser=None)
Get/set the raising of limit errors.
 
lonDMS(deg, form='dms', prec=2, sep='')
Convert longitude to a string suffixed with E or W.
 
m2NM(meter)
Convert meter to nautical miles (NM).
 
m2SM(meter)
Convert meter to statute miles (SM).
 
m2degrees(meter, radius=6371008.77141)
Convert distance to angle along equator.
 
m2ft(meter)
Convert meter to International feet (ft).
 
m2km(meter)
Convert meter to kilo meter (km).
 
map1(func, *args)
Apply each argument to a single-argument function and return a tuple of results.
 
map2(func, *args)
Apply arguments to a function and return a tuple of results.
 
normDMS(strDMS, norm='')
Normalize all degree ˚, minute ' and second " symbols in a string to the default symbols °, ′ and ″.
 
parse3llh(strll, height=0, sep=',', clipLat=90, clipLon=180)
Parse a string representing lat-, longitude and height point.
 
parseDMS(strDMS, suffix='NSEW', sep='', clip=0)
Parse a string representing deg°min′sec″ to degrees.
 
parseDMS2(strLat, strLon, sep='', clipLat=90, clipLon=180)
Parse lat- and longitude representions.
 
parseMGRS(strMGRS, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran..., Mgrs=<class 'pygeodesy.mgrs.Mgrs'>, name='')
Parse a string representing a MGRS grid reference, consisting of zoneBand, grid, easting and northing.
 
parseOSGR(strOSGR, Osgr=<class 'pygeodesy.osgr.Osgr'>, name='')
Parse an OSGR coordinate string to an Osgr instance.
 
parseUTM(strUTM, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran..., Utm=<class 'pygeodesy.utm.Utm'>, name='')
Parse a string representing a UTM coordinate, consisting of zone, hemisphere, easting and northing.
 
parseWM(strWM, radius=6378137.0, Wm=<class 'pygeodesy.webmercator.Wm'>, name='')
Parse a string representing a WM coordinate, consisting of easting, northing and an optional radius.
 
perimeterOf(points, closed=False, adjust=True, radius=6371008.77141, wrap=True)
Approximate the perimeter of a polygon/-line defined by an array, list, sequence, set or tuple of points.
 
polygon(points, closed=True, base=None)
Check a polygon given as an array, list, sequence, set or tuple of points.
 
precision(form, prec=None)
Set the default precison for a given F_ form.
 
property_RO(method)
Decorator for Read_Only property.
 
radians(x)
Convert angle x from degrees to radians.
 
radiansPI(deg)
Convert and wrap degrees to radians (-PI..+PI].
 
radiansPI2(deg)
Convert and wrap degrees to radians (0..+2PI].
 
radiansPI_2(deg)
Convert and wrap degrees to radians (-3PI/2..+PI/2].
 
rangerrors(raiser=None)
Gert/set raising of range errors.
 
scalar(value, low=2.22044604925e-16, high=1.0, name='scalar')
Validate a scalar.
 
simplify1(points, distance, radius=6371008.77141, indices=False, **options)
Basic simplification of a path of LatLon points.
 
simplify2(points, pipe, radius=6371008.77141, shortest=False, indices=False, **options)
Reumann-Witkam simplification of a path of LatLon points.
 
simplifyRDP(points, distance, radius=6371008.77141, shortest=False, indices=False, **options)
Ramer-Douglas-Peucker (RDP) simplification of a path of LatLon points.
 
simplifyRDPm(points, distance, radius=6371008.77141, shortest=False, indices=False, **options)
Modified Ramer-Douglas-Peucker (RDP) simplification of a path of LatLon points.
 
simplifyRW(points, pipe, radius=6371008.77141, shortest=False, indices=False, **options)
Reumann-Witkam simplification of a path of LatLon points.
 
simplifyVW(points, area, radius=6371008.77141, attr=None, indices=False, **options)
Visvalingam-Whyatt (VW) simplification of a path of LatLon points.
 
simplifyVWm(points, area, radius=6371008.77141, attr=None, indices=False, **options)
Modified Visvalingam-Whyatt (VW) simplification of a path of LatLon points.
 
sqrt3(x)
Compute the square root cubed sqrt(x)**3 or sqrt(x**3).
 
tanPI_2_2(rad)
Compute the tangent of half angle, 90 degrees rotated.
 
tan_2(rad)
Compute the tangent of half angle.
 
toDMS(deg, form='dms', prec=2, sep='', ddd=2, neg='-', pos='')
Convert signed degrees to string, without suffix.
 
toLcc(latlon, conic=Conic(name='WRF_Lb', lat0=40, lon0=-97, par1=33, par2=45, E0=0..., height=None, Lcc=<class 'pygeodesy.lcc.Lcc'>, name='')
Convert an (ellipsoidal) geodetic point to a Lambert location.
 
toMgrs(utm, Mgrs=<class 'pygeodesy.mgrs.Mgrs'>, name='')
Convert a UTM coordinate to an MGRS grid reference.
 
toOsgr(latlon, lon=None, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran..., Osgr=<class 'pygeodesy.osgr.Osgr'>, name='')
Convert a lat-/longitude point to an OSGR coordinate.
 
toUtm(latlon, lon=None, datum=None, Utm=<class 'pygeodesy.utm.Utm'>, name='', cmoff=True)
Convert a lat-/longitude point to a UTM coordinate.
 
toWm(latlon, lon=None, radius=6378137.0, Wm=<class 'pygeodesy.webmercator.Wm'>, name='')
Convert a lat-/longitude point to a WM coordinate.
 
unStr(name, *args, **kwds)
Return the string representation of an invokation.
 
unroll180(lon1, lon2, wrap=True)
Unroll longitudinal delta and wrap longitude in degrees.
 
unrollPI(rad1, rad2, wrap=True)
Unroll longitudinal delta and wrap longitude in radians.
 
utmZoneBand2(lat, lon)
Return the UTM zone number and UTM Band letter for a location.
 
wrap180(deg)
Wrap degrees to (-180..+180].
 
wrap360(deg)
Wrap degrees to (0..+360].
 
wrap90(deg)
Wrap degrees to (-270..+90].
 
wrapPI(rad)
Wrap radians to (-PI..+PI].
 
wrapPI2(rad)
Wrap radians to (0..+2PI].
 
wrapPI_2(rad)
Wrap radians to (-3PI/2..+PI/2].
Variables
  version = '18.9.9'
Normalized PyGeodesy version (string).
  Conics = Conics.Be08Lb: Conic(name='Be08Lb', lat0=50.797815, l...
Registered conics (enum).
  Datums = Datums.BD72: Datum(name='BD72', ellipsoid=Ellipsoids....
Registered datums (enum).
  EPS = 2.22044604925e-16
System's epsilon (float)
  EPS1 = 1.0
1 - EPS (float), about 0.9999999999999998
  EPS2 = 1.49011611938e-08
sqrt(EPS) (float)
  Ellipsoids = Ellipsoids.Airy1830: Ellipsoid(name='Airy1830', a...
Registered ellipsoids (enum).
  F_D = 'd'
Format degrees as deg° (string).
  F_DEG = 'deg'
Format degrees as [D]DD without symbol (string).
  F_DM = 'dm'
Format degrees as deg°min′ (string).
  F_DMS = 'dms'
Format degrees as deg°min′sec″ (string).
  F_MIN = 'min'
Format degrees as [D]DDMM without symbols (string).
  F_RAD = 'rad'
Convert degrees to radians and format as RR (string).
  F_SEC = 'sec'
Format degrees as [D]DDMMSS without symbols (string).
  PI = 3.14159265359
Constant math.pi (float)
  PI2 = 6.28318530718
Two PI, math.pi * 2 (float)
  PI_2 = 1.57079632679
Half PI, math.pi / 2 (float)
  R_FM = 6371000.0
Former FAI Sphere earth radius (meter).
  R_KM = 6371.00877142
Mean, spherical earth radius (kilo meter).
  R_M = 6371008.77141
Mean, spherical earth radius (meter).
  R_MA = 6378137.0
Equatorial earth radius (meter) WGS84, EPSG:3785.
  R_MB = 6356752.0
Polar earth radius (meter) WGS84, EPSG:3785.
  R_NM = 3440.06953447
Mean, spherical earth radius (nautical miles).
  R_SM = 3958.75339537
Mean, spherical earth radius (statute miles).
  R_VM = 6366707.01949
Aviation/Navigation earth radius (meter).
  S_DEG = '\xc2\xb0'
Degrees symbol ° (string).
  S_MIN = '\xe2\x80\xb2'
Minutes symbol ′ (string).
  S_RAD = ''
Radians symbol (string).
  S_SEC = '\xe2\x80\xb3'
Seconds symbol ″ (string).
  S_SEP = ''
Separator between deg°, min′ and sec″ (string).
  Transforms = Transforms.BD72: Transform(name='BD72', tx=106.86...
Registered transforms (enum).
Function Details

crosserrors(raiser=None)

 

Get/set raising of vectorial cross product errors.

Parameters:
  • raiser - Use True to raise or False to ignore CrossError exceptions.
Returns:
Previous setting (bool).

antipode(lat, lon)

 

Return the antipode, the point diametrically opposite to the given lat- and longitude.

Parameters:
  • lat - Latitude (degrees).
  • lon - Longitude (degrees).
Returns:
2-Tuple (lat, lon) of the antipodal point (degrees, degrees180).

See Also: Geosphere.

areaOf(points, adjust=True, radius=6371008.77141, wrap=True)

 

Approximate the area of a polygon defined by an array, list, sequence, set or tuple of points.

Parameters:
  • points - The points defining the polygon (LatLon[]).
  • adjust - Adjust the wrapped, unrolled longitudinal delta by the cosine of the mean latitude (bool).
  • radius - Optional, mean earth radius (meter).
  • wrap - Wrap lat-, wrap and unroll longitudes (bool).
Returns:
Approximate area (meter, same units as radius, squared).
Raises:
  • TypeError - Some points are not LatLon.
  • ValueError - Insufficient number of points.

Note: This is an area approximation with limited accuracy, ill-suited for regions exceeding several hundred Km or Miles or with near-polar latitudes.

See Also: sphericalNvector.areaOf, sphericalTrigonometry.areaOf and ellipsoidalKarney.areaOf.

bearingDMS(bearing, form='d', prec=None, sep='')

 

Convert bearing to a string.

Parameters:
  • bearing - Bearing from North (compass degrees).
  • form - Optional format, F_D, F_DM, F_DMS, F_DEG, F_MIN, F_SEC or F_RAD for deg°, deg°min′, deg°min′sec″, [D]DD, [D]DDMM, [D]DDMMSS or radians (string).
  • prec - Optional number of decimal digits (0..9 or None for default). Trailing zero decimals are stripped for prec values of 1 and above, but kept for negative prec values.
  • sep - Optional separator (string).
Returns:
Compass degrees per the specified form (string).

JS name: toBrng.

bounds(points, wrap=True, LatLon=None)

 

Determine the lower-left and upper-right corners of a polygon/-line defined by a list, sequence, set or tuple of points.

Parameters:
  • points - The points defining the polygon (LatLon[]).
  • wrap - Wrap lat- and longitudes (bool).
  • LatLon - Optional class to use to return bounds (LatLon).
Returns:
2-tuple (loLatLon, hiLatLon) of LatLons for the lower-left respectively upper-right corners or 4-Tuple (loLat, loLon, hiLat, hiLon) of bounds (degrees) if LatLon is None.
Raises:
  • TypeError - Some points are not LatLon.
  • ValueError - Insufficient number of points.

Example:

>>> b = LatLon(45,1), LatLon(45,2), LatLon(46,2), LatLon(46,1)
>>> bounds(b)  # False
>>> 45.0, 1.0, 46.0, 2.0

cbrt(x)

 

Compute the cubic root x**(1/3).

Parameters:
  • x - Value (scalar).
Returns:
Cubic root (float).

cbrt2(x)

 

Compute the cubic root squared x**(2/3).

Parameters:
  • x - Value (scalar).
Returns:
Cubic root squared (float).

See Also: Function sqrt3.

classname(inst, prefixed=None)

 

Return an instance' module and class name.

Parameters:
  • inst - The object (any type).
  • prefixed - Prefix the module name (bool), see function classnaming.
Returns:
The inst's [module.]class name (string).

classnaming(prefixed=None)

 

Set the default class naming for [module.].class names.

Parameters:
  • prefixed - Include the module name (bool).
Returns:
Previous class naming setting (bool).

clipDMS(deg, limit)

 

Clip a lat- or longitude to the given range.

Parameters:
  • deg - Unclipped lat- or longitude (degrees).
  • limit - Valid -limit..+limit range (degrees).
Returns:
Clipped value (degrees).
Raises:

compassAngle(lat0, lon0, lat1, lon1)

 

Return the angle from North for the direction vector (lon1 - lon0, lat1 - lat0) between two points.

Suitable only for short, non-near-polar vectors up to a few hundred Km or Miles. Use LatLon methods initialBearingTo or forward azimuth for larger distances.

Parameters:
  • lat0 - From latitude (degrees).
  • lon0 - From longitude (degrees).
  • lat1 - To latitude (degrees).
  • lon1 - To longitude (degrees).
Returns:
Angle from North (degrees360).

Note: Courtesy Martin Schultz.

See Also: Local, Flat Earth.

compassDMS(bearing, form='d', prec=None, sep='')

 

Convert bearing to a string suffixed with compass point.

Parameters:
  • bearing - Bearing from North (compass degrees).
  • form - Optional format, F_D, F_DM, F_DMS, F_DEG, F_MIN, F_SEC or F_RAD for deg°, deg°min′, deg°min′sec″, [D]DD, [D]DDMM, [D]DDMMSS or radians (string).
  • prec - Optional number of decimal digits (0..9 or None for default). Trailing zero decimals are stripped for prec values of 1 and above, but kept for negative prec values.
  • sep - Optional separator (string).
Returns:
Compass degrees and point in the specified form (string).

compassPoint(bearing, prec=3)

 

Convert bearing to a compass point.

Parameters:
  • bearing - Bearing from North (compass degrees).
  • prec - Optional precision (1 for cardinal or basic winds, 2 for intercardinal or ordinal or principal winds, 3 for secondary-intercardinal or half-winds or 4 for quarter-winds).
Returns:
Compass point (1-, 2-, 3- or 4-letter string).
Raises:
  • ValueError - Invalid prec.

See Also: Compass rose

Example:

>>> p = compassPoint(24)     # 'NNE'
>>> p = compassPoint(24, 1)  # 'N'
>>> p = compassPoint(24, 2)  # 'NE'
>>> p = compassPoint(18, 3)  # 'NNE'
>>> p = compassPoint(12, 4)  # 'NbE'
>>> p = compassPoint(30, 4)  # 'NEbN'

degrees180(rad)

 

Convert and wrap radians to degrees (-180..+180].

Parameters:
  • rad - Angle (radians).
Returns:
Angle in degrees, wrapped (degrees180).

degrees360(rad)

 

Convert and wrap radians to degrees (0..+360].

Parameters:
  • rad - Angle (radians).
Returns:
Angle in degrees, wrapped (degrees360).

degrees90(rad)

 

Convert and wrap radians to degrees (-270..+90].

Parameters:
  • rad - Angle (radians).
Returns:
Angle in degrees, wrapped (degrees90).

elevation2(lat, lon, timeout=2.0)

 

Get the geoid elevation at an NAD83 to NAVD88 location.

Parameters:
  • lat - Latitude (degrees).
  • lon - Longitude (degrees).
  • timeout - Optional, query timeout (seconds).
Returns:
2-Tuple (elevation, data_source) in (meter, string) or (None, <error>).

Note: The returned elevation is None if lat or lon is invalid or outside the Conterminous US (CONUS), if the query timed out or if conversion failed. The <error> is the HTTP-, IO-, SSL-, Type-, URL- or ValueError as string.

See Also: USGS National Map, the FAQ and USGS10mElev.py.

enStr2(easting, northing, prec, *extras)

 

Return easting, northing string representations.

Parameters:
  • easting - Easting from false easting (meter).
  • northing - Northing from from false northing (meter).
  • prec - Precision in number of digits (int).
  • extras - Optional leading items (strings).
Returns:
extras + 2-Tuple (eastingStr, northingStr).
Raises:
  • ValueError - Invalid prec.

equirectangular(lat1, lon1, lat2, lon2, radius=6371008.77141, **options)

 

Compute the distance between two points using the Equirectangular Approximation / Projection.

See function equirectangular_ for more details, the available options and errors raised.

Parameters:
  • lat1 - Start latitude (degrees).
  • lon1 - Start longitude (degrees).
  • lat2 - End latitude (degrees).
  • lon2 - End longitude (degrees).
  • radius - Optional, mean earth radius (meter).
  • options - Optional keyword arguments for function equirectangular_.
Returns:
Distance (meter, same units as radius).

See Also: Local, Flat Earth, method Ellipsoid.distance2 or function haversine for more accurate and/or larger distances.

equirectangular_(lat1, lon1, lat2, lon2, adjust=True, limit=45, wrap=False)

 

Compute the distance between two points using the Equirectangular Approximation / Projection.

This approximation is valid for smaller distance of several hundred Km or Miles, see the limit keyword argument and the LimitError.

Parameters:
  • lat1 - Start latitude (degrees).
  • lon1 - Start longitude (degrees).
  • lat2 - End latitude (degrees).
  • lon2 - End longitude (degrees).
  • adjust - Adjust the wrapped, unrolled longitudinal delta by the cosine of the mean latitude (bool).
  • limit - Optional limit for the lat- and longitudinal deltas (degrees) or None or 0 for unlimited.
  • wrap - Wrap and unroll180 longitudes and longitudinal delta (bool).
Returns:
4-Tuple (distance2, delta_lat, delta_lon, lon2_unroll) with the distance in degrees squared, the latitudinal delta lat2-lat1, the wrapped, unrolled, and adjusted longitudinal delta lon2-lon1 and the unrollment for lon2. To convert distance2 to meter, use radians(sqrt(distance2)) * radius where radius is the mean earth radius in the desired units, for example R_M meter.
Raises:
  • LimitError - If the lat- and/or longitudinal delta exceeds the -limit..+limit range and limiterrors set to True.

See Also: Local, Flat Earth, method Ellipsoid.distance2, function equirectangular for distance only and function haversine for accurate and/or larger distances.

fStr(floats, prec=6, sep=', ', fmt='%.*f', ints=False)

 

Convert floats to string, optionally with trailing zero decimals stripped.

Parameters:
  • floats - List, sequence, tuple, etc. (scalars).
  • prec - Optional precision, number of decimal digits (0..9). Trailing zero decimals are stripped for prec values of 1 and above, but kept for negative prec values.
  • sep - Optional, separator to join (string).
  • fmt - Optional, float format (string).
  • ints - Optionally, remove decimal dot (bool).
Returns:
The floats as 'f, f, ... f' (string).

fStrzs(fstr)

 

Strip trailing zero decimals from a float string.

Parameters:
  • fstr - Float (string).
Returns:
Float (string).

false2f(value, name='value', false=True)

 

Convert a false east-/northing to non-negative float.

Parameters:
  • value - Value to convert (scalar).
  • name - Optional name of the value (string).
  • false - Optionally, value includes false origin (bool).
Returns:
The value (float).
Raises:
  • ValueError - Invalid or negative value.

favg(v1, v2, f=0.5)

 

Return the weighted average of two values.

Parameters:
  • v1 - One value (scalar).
  • v2 - Other value (scalar).
  • f - Optional fraction (scalar).
Returns:
v1 + f * (v2 - v1) (float).

fdot(a, *b)

 

Return the precision dot product sum(a[i] * b[i] for i=0..len(a)).

Parameters:
  • a - List, sequence, tuple, etc. (scalars).
  • b - All positional arguments (scalars).
Returns:
Dot product (float).
Raises:
  • ValueError - Unequal len(a) and len(b).

fdot3(a, b, c, start=0)

 

Return the precision dot product start + sum(a[i] * b[i] * c[i] for i=0..len(a)).

Parameters:
  • a - List, sequence, tuple, etc. (scalars).
  • b - List, sequence, tuple, etc. (scalars).
  • c - List, sequence, tuple, etc. (scalars).
  • start - Optional bias (scalar).
Returns:
Dot product (float).
Raises:
  • ValueError - Unequal len(a), len(b) and/or len(c).

fhorner(x, *cs)

 

Evaluate the polynomial sum(cs[i] * x**i for i=0..len(cs)) using the Horner form.

Parameters:
  • x - Polynomial argument (scalar).
  • cs - Polynomial coeffients (scalars).
Returns:
Horner value (float).
Raises:
  • TypeError - Argument x not scalar.
  • ValueError - No cs coefficients.

fmean(xs)

 

Compute the accurate mean sum(xs[i] for i=0..len(xs)) / len(xs).

Parameters:
  • xs - Values (scalars).
Returns:
Mean value (float).
Raises:
  • ValueError - No xs values.

fpolynomial(x, *cs)

 

Evaluate the polynomial sum(cs[i] * x**i for i=0..len(cs)).

Parameters:
  • x - Polynomial argument (scalar).
  • cs - Polynomial coeffients (scalars).
Returns:
Polynomial value (float).
Raises:
  • TypeError - Argument x not scalar.
  • ValueError - No cs coefficients.

fpowers(x, n, alts=0)

 

Return a series of powers [x**i for i=1..n].

Parameters:
  • x - Value (scalar).
  • n - Highest exponent (int).
  • alts - Only alternating powers, starting with this exponent (int).
Returns:
Powers of x (list of floats).
Raises:
  • TypeError - Argument x not scalar or n not int.
  • ValueError - Argument n not positive.

fsum(iterable)

 

Return an accurate floating point sum of values in the iterable. Assumes IEEE-754 floating point arithmetic.

fsum_(*args)

 

Precision floating point summation of the positional arguments.

Parameters:
  • args - Values to be added (scalars).
Returns:
Precision fsum (float).
Raises:
  • OverflowError - Partial 2sum overflow.
  • ValueError - Invalid or infinite args value.

ft2m(feet)

 

Convert International feet to meter (m).

Parameters:
  • feet - Value in feet (scalar).
Returns:
Value in m (float).

geoidHeight2(lat, lon, model=0, timeout=2.0)

 

Get the NAVD88 geoid height at an NAD83 location.

Parameters:
  • lat - Latitude (degrees).
  • lon - Longitude (degrees).
  • model - Optional, geoid model ID (int).
  • timeout - Optional, query timeout (seconds).
Returns:
2-Tuple (height, model_name) in (meter, string) or (None, <error>).

Note: The returned height is CNone if lat or lon is invalid or outside the Conterminous US (CONUS), if the model was invalid, if the query timed out or if conversion failed. The <error> is the HTTP-, IO-, SSL-, Type-, URL- or ValueError as string.

See Also: NOAA National Geodetic Survery and Geoid

halfs(str2)

 

Split a string in 2 halfs.

Parameters:
  • str2 - String to split (string).
Returns:
2-Tuple (1st, 2nd) half (strings).
Raises:
  • ValueError - Zero or odd len(str2).

haversine(lat1, lon1, lat2, lon2, radius=6371008.77141, wrap=False)

 

Compute the distance between two points using the Haversine formula.

Parameters:
  • lat1 - Start latitude (degrees).
  • lon1 - Start longitude (degrees).
  • lat2 - End latitude (degrees).
  • lon2 - End longitude (degrees).
  • radius - Optional, mean earth radius (meter).
  • wrap - Wrap and unrollPI longitudes (bool).
Returns:
Distance (meter, same units as radius).

See Also: Distance between two (spherical) points and function equirectangular or method Ellipsoid.distance2 for distance approximations.

haversine_(a2, a1, b21)

 

Compute the angular distance between two points using the Haversine formula.

Parameters:
  • a2 - End latitude (radians).
  • a1 - Start latitude (radians).
  • b21 - Longitudinal delta, end-start (radians).
Returns:
Angular distance (radians).

See Also: Function haversine.

heightOf(angle, distance, radius=6371008.77141)

 

Determine the height above the (spherical) earth after traveling along a straight line at a given tilt.

Parameters:
  • angle - Tilt angle above horizontal (degrees).
  • distance - Distance along the line (meter or same units as radius).
  • radius - Optional mean earth radius (meter).
Returns:
Height (meter, same units as distance and radius).
Raises:
  • ValueError - Invalid angle, distance or radius.

horizon(height, radius=6371008.77141, refraction=False)

 

Determine the distance to the horizon from a given altitude above the (spherical) earth.

Parameters:
  • height - Altitude (meter or same units as radius).
  • radius - Optional mean earth radius (meter).
  • refraction - Consider atmospheric refraction (bool).
Returns:
Distance (meter, same units as height and radius).
Raises:
  • ValueError - Invalid height or radius.

See Also: Distance to horizon.

hypot1(x)

 

Compute the norm sqrt(1 + x**2).

Parameters:
  • x - Argument (scalar).
Returns:
Norm (float).

hypot3(x, y, z)

 

Compute the norm sqrt(x**2 + y**2 + z**2).

Parameters:
  • x - X argument (scalar).
  • y - Y argument (scalar).
  • z - Z argument (scalar).
Returns:
Norm (float).

inStr(inst, *args, **kwds)

 

Return the string representation of an instance.

Parameters:
  • inst - The instance (any type).
  • args - Optional positional arguments (tuple).
  • kwds - Optional keyword arguments (dict).
Returns:
The inst's representation (string).

isNumpy2(obj)

 

Check for an Numpy2LatLon points wrapper.

Parameters:
  • obj - The object (any).
Returns:
True if obj is an Numpy2LatLon instance, False otherwise (bool).

isPoints2(obj)

 

Check for an LatLon2psxy points wrapper.

Parameters:
  • obj - The object (any).
Returns:
True if obj is an LatLon2psxy instance, False otherwise (bool).

isTuple2(obj)

 

Check for an Tuple2LatLon points wrapper.

Parameters:
  • obj - The object (any).
Returns:
True if obj is an Tuple2LatLon instance, False otherwise (bool).

isantipode(lat1, lon1, lat2, lon2, eps=2.22044604925e-16)

 

Check whether two points are anitpodal, on diametrically opposite sides of the earth.

Parameters:
  • lat1 - Latitude of one point (degrees).
  • lon1 - Longitude of one point (degrees).
  • lat2 - Latitude of the other point (degrees).
  • lon2 - Longitude of the other point (degrees).
  • eps - Tolerance for near-equality (degrees).
Returns:
True if points are antipodal within the given tolerance, False otherwise.

See Also: Geosphere.

isclockwise(points, adjust=False, wrap=True)

 

Determine the direction of a polygon defined by an array, list, sequence, set or tuple of points.

Parameters:
  • points - The points defining the polygon (LatLon[]).
  • adjust - Adjust the wrapped, unrolled longitudinal delta by the cosine of the mean latitude (bool).
  • wrap - Wrap lat-, wrap and unroll longitudes (bool).
Returns:
True if clockwise, False otherwise.
Raises:
  • TypeError - Some points are not LatLon.
  • ValueError - Insufficient number of points or zero area polygon.

Example:

>>> f = LatLon(45,1), LatLon(45,2), LatLon(46,2), LatLon(46,1)
>>> isclockwise(f)  # False
>>> t = LatLon(45,1), LatLon(46,1), LatLon(46,2)
>>> isclockwise(t)  # True

isconvex(points, adjust=False, wrap=True)

 

Determine whether a polygon defined by an array, list, sequence, set or tuple of points is convex.

Parameters:
  • points - The points defining the polygon (LatLon[]).
  • adjust - Adjust the wrapped, unrolled longitudinal delta by the cosine of the mean latitude (bool).
  • wrap - Wrap lat-, wrap and unroll longitudes (bool).
Returns:
True if convex, False otherwise.
Raises:
  • CrossError - Colinear point.
  • TypeError - Some points are not LatLon.
  • ValueError - Insufficient number of points.

Example:

>>> t = LatLon(45,1), LatLon(46,1), LatLon(46,2)
>>> isconvex(t)  # True
>>> f = LatLon(45,1), LatLon(46,2), LatLon(45,2), LatLon(46,1)
>>> isconvex(f)  # False

isenclosedby(latlon, points, wrap=False)

 

Determine whether a point is enclosed by a polygon defined by an array, list, sequence, set or tuple of points.

Parameters:
  • latlon - The point (LatLon or 2-tuple (lat, lon)).
  • points - The points defining the polygon (LatLon[]).
  • wrap - Wrap lat-, wrap and unroll longitudes (bool).
Returns:
True if latlon is inside the polygon, False otherwise.
Raises:
  • TypeError - Some points are not LatLon.
  • ValueError - Insufficient number of points or invalid latlon.

isfinite(obj)

 

Check for Inf and NaN values.

Parameters:
  • obj - Value (scalar).
Returns:
False if Inf or NaN, True otherwise (bool).
Raises:
  • TypeError - If obj value is not scalar.

isint(obj, both=False)

 

Check for integer type or integer value.

Parameters:
  • obj - The object (any).
  • both - Optionally, check both type and value (bool).
Returns:
True if obj is integer (bool).

isscalar(obj)

 

Check for scalar types.

Parameters:
  • obj - The object (any).
Returns:
True if obj is scalar (bool).

issequence(obj, *excluded)

 

Check for sequence types.

Parameters:
  • obj - The object (any).
  • excluded - Optional, exclusions (types).
Returns:
True if obj is a sequence (bool).

Note: Excluding tuple implies namedtuple.

iterNumpy2(obj)

 

Iterate over Numpy2 wrappers or other sequences exceeding the threshold.

Parameters:
  • obj - Points array, list, sequence, set, etc. (any).
Returns:
True, do iterate (bool).

iterNumpy2over(n=None)

 

Get or set the iterNumpy2 threshold.

Parameters:
  • n - Optional, new threshold (integer).
Returns:
Previous threshold (integer).
Raises:
  • ValueError - Invalid n.

latDMS(deg, form='dms', prec=2, sep='')

 

Convert latitude to a string suffixed with N or S.

Parameters:
  • deg - Latitude to be formatted (degrees).
  • form - Optional format, F_D, F_DM, F_DMS, F_DEG, F_MIN, F_SEC or F_RAD for deg°, deg°min′, deg°min′sec″, DD, DDMM, DDMMSS or radians (string).
  • prec - Optional number of decimal digits (0..9 or None for default). Trailing zero decimals are stripped for prec values of 1 and above, but kept for negative prec values.
  • sep - Optional separator (string).
Returns:
Degrees in the specified form (string).

JS name: toLat.

len2(seq)

 

Make built-in function len work for generators, iterators, etc. since those can only be started once.

Parameters:
  • seq - Generator, iterator, list, range, tuple, etc.
Returns:
2-Tuple (number, list) of items (int, list).

limiterrors(raiser=None)

 

Get/set the raising of limit errors.

Parameters:
  • raiser - Choose True to raise or False to not raise LimitError exceptions. Use None to leave the setting unchanged.
Returns:
Previous setting (bool).

lonDMS(deg, form='dms', prec=2, sep='')

 

Convert longitude to a string suffixed with E or W.

Parameters:
  • deg - Longitude to be formatted (degrees).
  • form - Optional format, F_D, F_DM, F_DMS, F_DEG, F_MIN, F_SEC or F_RAD for deg°, deg°min′, deg°min′sec″, DDD, DDDMM, DDDMMSS or radians (string).
  • prec - Optional number of decimal digits (0..9 or None for default). Trailing zero decimals are stripped for prec values of 1 and above, but kept for negative prec values.
  • sep - Optional separator (string).
Returns:
Degrees in the specified form (string).

JS name: toLon.

m2NM(meter)

 

Convert meter to nautical miles (NM).

Parameters:
  • meter - Value in meter (scalar).
Returns:
Value in NM (float).

m2SM(meter)

 

Convert meter to statute miles (SM).

Parameters:
  • meter - Value in meter (scalar).
Returns:
Value in SM (float).

m2degrees(meter, radius=6371008.77141)

 

Convert distance to angle along equator.

Parameters:
  • meter - Value in meter (scalar).
Returns:
Value in degrees (float).
Raises:
  • ValueError - Invalid radius.

m2ft(meter)

 

Convert meter to International feet (ft).

Parameters:
  • meter - Value in meter (scalar).
Returns:
Value in ft (float).

m2km(meter)

 

Convert meter to kilo meter (km).

Parameters:
  • meter - Value in meter (scalar).
Returns:
Value in km (float).

map1(func, *args)

 

Apply each argument to a single-argument function and return a tuple of results.

Parameters:
  • func - Function to apply (callable).
  • args - Arguments to apply (any positional).
Returns:
Function results (tuple).

map2(func, *args)

 

Apply arguments to a function and return a tuple of results.

Unlike Python 2's built-in map, Python 3+ map returns a map object, an iterator-like object which generates the results only once. Converting the map object to a tuple maintains Python 2 behavior.

Parameters:
  • func - Function to apply (callable).
  • args - Arguments to apply (list, tuple, ...).
Returns:
N-Tuple of function results (tuple).

normDMS(strDMS, norm='')

 

Normalize all degree ˚, minute ' and second " symbols in a string to the default symbols °, ′ and ″.

Parameters:
  • strDMS - DMS (string).
  • norm - Optional replacement symbol, default symbol otherwise (string).
Returns:
Normalized DMS (string).

parse3llh(strll, height=0, sep=',', clipLat=90, clipLon=180)

 

Parse a string representing lat-, longitude and height point.

The lat- and longitude value must be separated by a separator character. If height is present it must follow, separated by another separator.

The lat- and longitude values may be swapped, provided at least one ends with the proper compass point.

Parameters:
  • strll - Latitude, longitude[, height] (string).
  • height - Optional, default for missing height (meter).
  • sep - Optional separator (string).
  • clipLat - Keep latitude in -clipLat..+clipLat (degrees).
  • clipLon - Keep longitude in -clipLon..+clipLon range (degrees).
Returns:
3-Tuple (lat, lon, height) as (scalars).
Raises:
  • RangeError - Lat- or longitude value of strll outside valid range and rangerrrors set to True.
  • ValueError - Invalid strll.

See Also: Functions parseDMS and parseDMS2 for more details on the forms and symbols accepted.

Example:

>>> parse3llh('000°00′05.31″W, 51° 28′ 40.12″ N')
(51.4778°N, 000.0015°W, 0)

parseDMS(strDMS, suffix='NSEW', sep='', clip=0)

 

Parse a string representing deg°min′sec″ to degrees.

This is very flexible on formats, allowing signed decimal degrees, degrees and minutes or degrees minutes and seconds optionally suffixed by compass direction NSEW.

A variety of symbols, separators and suffixes are accepted, for example 3° 37′ 09″W. Minutes and seconds may be omitted.

Parameters:
  • strDMS - Degrees in any of several forms (string or scalar).
  • suffix - Optional, valid compass directions (NSEW).
  • sep - Optional separator between deg°, min′ and sec″ ('').
  • clip - Optionally, limit value to -clip..+clip (degrees).
Returns:
Degrees (float).
Raises:
  • RangeError - Value of strDMS outside the valid range and rangerrrors set to True.
  • ValueError - Invalid strDMS.

See Also: Function parse3llh to parse a string with lat-, longitude and height values.

parseDMS2(strLat, strLon, sep='', clipLat=90, clipLon=180)

 

Parse lat- and longitude representions.

Parameters:
  • strLat - Latitude in any of several forms (string or scalar).
  • strLon - Longitude in any of several forms (string or scalar).
  • sep - Optional separator between deg°, min′ and sec″ ('').
  • clipLat - Keep latitude in -clipLat..+clipLat range (degrees).
  • clipLon - Keep longitude in -clipLon..+clipLon range (degrees).
Returns:
2-Tuple (lat, lon) in (degrees, degrees).
Raises:
  • RangeError - Value of strLat or strLon outside the valid range and rangerrrors set to True.
  • ValueError - Invalid strLat or strLon.

See Also: Function parse3llh to parse a string with lat-, longitude and height values and function parseDMS to parse individual lat- or longitudes.

parseMGRS(strMGRS, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran..., Mgrs=<class 'pygeodesy.mgrs.Mgrs'>, name='')

 

Parse a string representing a MGRS grid reference, consisting of zoneBand, grid, easting and northing.

Parameters:
  • strMGRS - MGRS grid reference (string).
  • datum - Optional datum to use (Datum).
  • Mgrs - Optional Mgrs (sub-)class to use for the MGRS grid reference (Mgrs) or None.
  • name - Optional Mgrs name (string).
Returns:
The MGRS grid reference (Mgrs) or 4-tuple (zone, ENdigraph, easting, northing) if Mgrs is None.
Raises:
  • ValueError - Invalid strMGRS.

Example:

>>> m = parseMGRS('31U DQ 48251 11932')
>>> str(m)  # 31U DQ 48251 11932
>>> m = parseMGRS('31UDQ4825111932')
>>> repr(m)  # [Z:31U, G:DQ, E:48251, N:11932]

parseOSGR(strOSGR, Osgr=<class 'pygeodesy.osgr.Osgr'>, name='')

 

Parse an OSGR coordinate string to an Osgr instance.

Accepts standard OS Grid References like 'SU 387 148', with or without whitespace separators, from 2- up to 10-digit references (1 m × 1 m square), or fully numeric, comma-separated references in metres, for example '438700,114800'.

Parameters:
  • strOSGR - An OSGR coordinate (string).
  • Osgr - Optional Osgr class to use for the OSGR coordinate (Osgr) or None.
  • name - Optional Osgr name (string).
Returns:
The OSGR coordinate (Osgr) or the 2-tuple (easting, northing) if Osgr is None.
Raises:
  • ValueError - Invalid strOSGR.

Example:

>>> g = parseOSGR('TG 51409 13177')
>>> str(g)  # TG 51409 13177
>>> g = parseOSGR('TG5140913177')
>>> str(g)  # TG 51409 13177
>>> g = parseOSGR('TG51409 13177')
>>> str(g)  # TG 51409 13177
>>> g = parseOSGR('651409,313177')
>>> str(g)  # TG 51409 13177
>>> g.toStr(prec=0)  # 651409,313177

parseUTM(strUTM, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran..., Utm=<class 'pygeodesy.utm.Utm'>, name='')

 

Parse a string representing a UTM coordinate, consisting of zone, hemisphere, easting and northing.

Parameters:
  • strUTM - A UTM coordinate (string).
  • datum - Optional datum to use (Datum).
  • Utm - Optional Utm class to use for the UTM coordinate (Utm) or None.
  • name - Optional Utm name (string).
Returns:
The UTM coordinate (Utm) or 4-tuple (zone, hemisphere, easting, northing) if Utm is None.
Raises:

Example:

>>> u = parseUTM('31 N 448251 5411932')
>>> u.toStr2()  # [Z:31, H:N, E:448251, N:5411932]
>>> u = parseUTM('31 N 448251.8 5411932.7')
>>> u.toStr()  # 31 N 448252 5411933

parseWM(strWM, radius=6378137.0, Wm=<class 'pygeodesy.webmercator.Wm'>, name='')

 

Parse a string representing a WM coordinate, consisting of easting, northing and an optional radius.

Parameters:
  • strWM - A WM coordinate (string).
  • radius - Optional earth radius (meter).
  • Wm - Optional Wm class to use (Wm) or None.
  • name - Optional name (string).
Returns:
The WM coordinate (Wm) or 3-tuple (easting, northing, radius) if Wm is None.
Raises:
  • ValueError - Invalid strWM.

Example:

>>> u = parseWM('448251 5411932')
>>> u.toStr2()  # [E:448251, N:5411932]

perimeterOf(points, closed=False, adjust=True, radius=6371008.77141, wrap=True)

 

Approximate the perimeter of a polygon/-line defined by an array, list, sequence, set or tuple of points.

Parameters:
  • points - The points defining the polygon/-line (LatLon[]).
  • closed - Optionally, close the polygon/-line (bool).
  • adjust - Adjust the wrapped, unrolled longitudinal delta by the cosine of the mean latitude (bool).
  • radius - Optional, mean earth radius (meter).
  • wrap - Wrap lat-, wrap and unroll longitudes (bool).
Returns:
Approximate perimeter (meter, same units as radius).
Raises:
  • TypeError - Some points are not LatLon.
  • ValueError - Insufficient number of points.

Note: This perimeter is based on the equirectangular_ distance approximation and is ill-suited for regions exceeding several hundred Km or Miles or with near-polar latitudes.

See Also: sphericalTrigonometry.perimeterOf and ellipsoidalKarney.perimeterOf.

polygon(points, closed=True, base=None)

 

Check a polygon given as an array, list, sequence, set or tuple of points.

Parameters:
  • points - The points of the polygon (LatLon[])
  • closed - Optionally, treat polygon as closed and remove any duplicate or closing final points (bool).
  • base - Optional points base class (None).
Returns:
2-Tuple (number, sequence) of points (int, sequence).
Raises:
  • TypeError - Some points are not LatLon.
  • ValueError - Insufficient number of points.

precision(form, prec=None)

 

Set the default precison for a given F_ form.

Parameters:
  • form - F_D, F_DM, F_DMS, F_DEG, F_MIN, F_SEC or F_RAD (string).
  • prec - Optional number of decimal digits (0..9 or None for default). Trailing zero decimals are stripped for prec values of 1 and above, but kept for negative prec values.
Returns:
Previous precision (int).
Raises:
  • ValueError - If form or prec or beyond valid range.

property_RO(method)

 

Decorator for Read_Only property.

Parameters:
  • method - The callable to be decorated as property.getter.

Note: Like standard Python property without a property.setter with a more descriptive error message when set.

radiansPI(deg)

 

Convert and wrap degrees to radians (-PI..+PI].

Parameters:
  • deg - Angle (degrees).
Returns:
Radians, wrapped (radiansPI)

radiansPI2(deg)

 

Convert and wrap degrees to radians (0..+2PI].

Parameters:
  • deg - Angle (degrees).
Returns:
Radians, wrapped (radiansPI2)

radiansPI_2(deg)

 

Convert and wrap degrees to radians (-3PI/2..+PI/2].

Parameters:
  • deg - Angle (degrees).
Returns:
Radians, wrapped (radiansPI_2)

rangerrors(raiser=None)

 

Gert/set raising of range errors.

Parameters:
  • raiser - Choose True to raise or False to ignore RangeError exceptions. Use None to leave the setting unchanged.
Returns:
Previous setting (bool).

Note: Out-of-range lat- and longitude values are always clipped to the nearest range limit.

scalar(value, low=2.22044604925e-16, high=1.0, name='scalar')

 

Validate a scalar.

Parameters:
  • value - The value (scalar).
  • low - Optional lower bound (scalar).
  • high - Optional upper bound (scalar).
  • name - Optional name of value (string).
Returns:
New value (type(low)).
Raises:
  • TypeError - The value is not scalar.
  • ValueError - The value is out of bounds.

simplify1(points, distance, radius=6371008.77141, indices=False, **options)

 

Basic simplification of a path of LatLon points.

Eliminates any points closer together than the given distance tolerance.

Parameters:
  • points - Path points (LatLons).
  • distance - Tolerance (meter, same units as radius).
  • radius - Optional, mean earth radius (meter).
  • indices - Optionally return the simplified point indices instead of the simplified points (bool).
  • options - Optional keyword arguments passed thru to function equirectangular_.
Returns:
Simplified points (list of LatLons).
Raises:
  • LimitError - Lat- and/or longitudinal delta exceeds limit, see function equirectangular_.
  • ValueError - Radius or distance tolerance too small.

simplify2(points, pipe, radius=6371008.77141, shortest=False, indices=False, **options)

 

Reumann-Witkam simplification of a path of LatLon points.

Eliminates any points too close together or within the given pipe tolerance along an edge.

Parameters:
  • points - Path points (LatLons).
  • pipe - Half pipe width (meter, same units as radius).
  • radius - Optional, mean earth radius (meter).
  • shortest - Optional, shortest or perpendicular distance (bool).
  • indices - Optionally return the simplified point indices instead of the simplified points (bool).
  • options - Optional keyword arguments passed thru to function equirectangular_.
Returns:
Simplified points (list of LatLons).
Raises:
  • LimitError - Lat- and/or longitudinal delta exceeds limit, see function equirectangular_.
  • ValueError - Radius or pipe tolerance too small.

simplifyRDP(points, distance, radius=6371008.77141, shortest=False, indices=False, **options)

 

Ramer-Douglas-Peucker (RDP) simplification of a path of LatLon points.

Eliminates any points too close together or closer to an edge than the given distance tolerance.

This RDP method exhaustively searches for the point with the largest distance, resulting in worst-case complexity O(n**2) where n is the number of points.

Parameters:
  • points - Path points (LatLons).
  • distance - Tolerance (meter, same units as radius).
  • radius - Optional, mean earth radius (meter).
  • shortest - Optional, shortest or perpendicular distance (bool).
  • indices - Optionally return the simplified point indices instead of the simplified points (bool).
  • options - Optional keyword arguments passed thru to function equirectangular_.
Returns:
Simplified points (list of LatLons).
Raises:
  • LimitError - Lat- and/or longitudinal delta exceeds limit, see function equirectangular_.
  • ValueError - Radius or distance tolerance too small.

simplifyRDPm(points, distance, radius=6371008.77141, shortest=False, indices=False, **options)

 

Modified Ramer-Douglas-Peucker (RDP) simplification of a path of LatLon points.

Eliminates any points too close together or closer to an edge than the given distance tolerance.

This RDP method stops at the first point farther than the given distance tolerance, significantly reducing the run time (but producing results different from the original RDP method).

Parameters:
  • points - Path points (LatLons).
  • distance - Tolerance (meter, same units as radius).
  • radius - Optional, mean earth radius (meter).
  • shortest - Optional, shortest or perpendicular distance (bool).
  • indices - Optionally return the simplified point indices instead of the simplified points (bool).
  • options - Optional keyword arguments passed thru to function equirectangular_.
Returns:
Simplified points (list of LatLons).
Raises:
  • LimitError - Lat- and/or longitudinal delta exceeds limit, see function equirectangular_.
  • ValueError - Radius or distance tolerance too small.

simplifyRW(points, pipe, radius=6371008.77141, shortest=False, indices=False, **options)

 

Reumann-Witkam simplification of a path of LatLon points.

Eliminates any points too close together or within the given pipe tolerance along an edge.

Parameters:
  • points - Path points (LatLons).
  • pipe - Half pipe width (meter, same units as radius).
  • radius - Optional, mean earth radius (meter).
  • shortest - Optional, shortest or perpendicular distance (bool).
  • indices - Optionally return the simplified point indices instead of the simplified points (bool).
  • options - Optional keyword arguments passed thru to function equirectangular_.
Returns:
Simplified points (list of LatLons).
Raises:
  • LimitError - Lat- and/or longitudinal delta exceeds limit, see function equirectangular_.
  • ValueError - Radius or pipe tolerance too small.

simplifyVW(points, area, radius=6371008.77141, attr=None, indices=False, **options)

 

Visvalingam-Whyatt (VW) simplification of a path of LatLon points.

Eliminates any points too close together or with a triangular area not exceeding the given area tolerance (squared).

This VW method exhaustively searches for the single point with the smallest triangular area, resulting in worst-case complexity O(n**2) where n is the number of points.

Parameters:
  • points - Path points (LatLons).
  • area - Tolerance (meter, same units as radius).
  • radius - Optional, mean earth radius (meter).
  • attr - Optional, points attribute save area value (string).
  • indices - Optionally return the simplified point indices instead of the simplified points (bool).
  • options - Optional keyword arguments passed thru to function equirectangular_.
Returns:
Simplified points (list of LatLons).
Raises:
  • AttributeError - If attr is specified for Numpy2 points.
  • LimitError - Lat- and/or longitudinal delta exceeds limit, see function equirectangular_.
  • ValueError - Radius or area tolerance too small.

simplifyVWm(points, area, radius=6371008.77141, attr=None, indices=False, **options)

 

Modified Visvalingam-Whyatt (VW) simplification of a path of LatLon points.

Eliminates any points too close together or with a triangular area not exceeding the given area tolerance (squared).

This VW method removes all points with a triangular area below the tolerance per iteration, significantly reducing the run time (but producing results different from the original VW method).

Parameters:
  • points - Path points (LatLons).
  • area - Tolerance (meter, same units as radius).
  • radius - Optional, mean earth radius (meter).
  • attr - Optional attribute to save the area value (string).
  • indices - Optionally return the simplified point indices instead of the simplified points (bool).
  • options - Optional keyword arguments passed thru to function equirectangular_.
Returns:
Simplified points (list of LatLons).
Raises:
  • AttributeError - If attr is specified for Numpy2 points.
  • LimitError - Lat- and/or longitudinal delta exceeds limit, see function equirectangular_.
  • ValueError - Radius or area tolerance too small.

sqrt3(x)

 

Compute the square root cubed sqrt(x)**3 or sqrt(x**3).

Parameters:
  • x - Value (scalar).
Returns:
Cubid square root (float).
Raises:
  • ValueError - Negative x.

See Also: Function cbrt2.

tanPI_2_2(rad)

 

Compute the tangent of half angle, 90 degrees rotated.

Parameters:
  • rad - Angle (radians).
Returns:
tan((rad + PI/2) / 2) (float).

tan_2(rad)

 

Compute the tangent of half angle.

Parameters:
  • rad - Angle (radians).
Returns:
tan(rad / 2) (float).

toDMS(deg, form='dms', prec=2, sep='', ddd=2, neg='-', pos='')

 

Convert signed degrees to string, without suffix.

Parameters:
  • deg - Degrees to be formatted (scalar).
  • form - Optional format, F_D, F_DM, F_DMS, F_DEG, F_MIN, F_SEC or F_RAD for deg°, deg°min′, deg°min′sec″, [D]DD, [D]DDMM, [D]DDMMSS or radians (string).
  • prec - Optional number of decimal digits (0..9 or None for default). Trailing zero decimals are stripped for prec values of 1 and above, but kept for negative prec values.
  • sep - Optional separator (string).
  • ddd - Optional number of digits for deg° (2 or 3).
  • neg - Optional sign for negative degrees ('-').
  • pos - Optional sign for positive degrees ('').
Returns:
Degrees in the specified form (string).

toLcc(latlon, conic=Conic(name='WRF_Lb', lat0=40, lon0=-97, par1=33, par2=45, E0=0..., height=None, Lcc=<class 'pygeodesy.lcc.Lcc'>, name='')

 

Convert an (ellipsoidal) geodetic point to a Lambert location.

Parameters:
  • latlon - Ellipsoidal point (LatLon).
  • conic - Optional Lambert projection to use (Conic).
  • height - Optional height for the point, overriding the default height (meter).
  • Lcc - Optional Lcc (sub-)class to use for the Lambert location (Lcc).
  • name - Optional Lcc name (string).
Returns:
The Lambert location (Lcc) or 3-tuple (easting, northing, height) if Lcc is None.
Raises:
  • TypeError - If latlon is not ellipsoidal.

toMgrs(utm, Mgrs=<class 'pygeodesy.mgrs.Mgrs'>, name='')

 

Convert a UTM coordinate to an MGRS grid reference.

Parameters:
  • utm - A UTM coordinate (Utm).
  • Mgrs - Optional Mgrs class to use for the MGRS grid reference (Mgrs).
  • name - Optional Mgrs name (string).
Returns:
The MGRS grid reference (Mgrs).
Raises:
  • TypeError - If utm is not Utm.
  • ValueError - Invalid utm.

Example:

>>> u = Utm(31, 'N', 448251, 5411932)
>>> m = u.toMgrs()  # 31U DQ 48251 11932

toOsgr(latlon, lon=None, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Tran..., Osgr=<class 'pygeodesy.osgr.Osgr'>, name='')

 

Convert a lat-/longitude point to an OSGR coordinate.

Parameters:
  • latlon - Latitude (degrees) or an (ellipsoidal) geodetic LatLon point.
  • lon - Optional longitude in degrees (scalar or None).
  • datum - Optional datum to convert (Datum).
  • Osgr - Optional Osgr (sub-)class to use for the OSGR coordinate (Osgr).
  • name - Optional Osgr name (string).
Returns:
The OSGR coordinate (Osgr) or 2-tuple (easting, northing) if Osgr is None.
Raises:
  • TypeError - If latlon is not ellipsoidal or if datum conversion failed.
  • ValueError - Invalid latlon or lon.

Example:

>>> p = LatLon(52.65798, 1.71605)
>>> r = toOsgr(p)  # TG 51409 13177
>>> # for conversion of (historical) OSGB36 lat-/longitude:
>>> r = toOsgr(52.65757, 1.71791, datum=Datums.OSGB36)

toUtm(latlon, lon=None, datum=None, Utm=<class 'pygeodesy.utm.Utm'>, name='', cmoff=True)

 

Convert a lat-/longitude point to a UTM coordinate.

Parameters:
  • latlon - Latitude (degrees) or an (ellipsoidal) geodetic LatLon point.
  • lon - Optional longitude (degrees or None).
  • datum - Optional datum for this UTM coordinate, overriding latlon's datum (Datum).
  • Utm - Optional Utm class to usefor the UTM coordinate (Utm) or None.
  • name - Optional Utm name (string).
  • cmoff - Offset longitude from zone's central meridian, apply false easting and false northing (bool).
Returns:
The UTM coordinate (Utm) or a 6-tuple (zone, easting, northing, band, convergence, scale) if Utm is None or cmoff is False.
Raises:
  • TypeError - If latlon is not ellipsoidal.
  • RangeError - If lat is outside the valid UTM bands or if lat or lon outside the valid range and rangerrrors set to True.
  • ValueError - If lon value is missing or if latlon is not scalar.

Note: Implements Karney’s method, using 8-th order Krüger series, giving results accurate to 5 nm (or better) for distances up to 3900 km from the central meridian.

Example:

>>> p = LatLon(48.8582, 2.2945)  # 31 N 448251.8 5411932.7
>>> u = toUtm(p)  # 31 N 448252 5411933
>>> p = LatLon(13.4125, 103.8667) # 48 N 377302.4 1483034.8
>>> u = toUtm(p)  # 48 N 377302 1483035

toWm(latlon, lon=None, radius=6378137.0, Wm=<class 'pygeodesy.webmercator.Wm'>, name='')

 

Convert a lat-/longitude point to a WM coordinate.

Parameters:
  • latlon - Latitude (degrees) or an (ellipsoidal or spherical) geodetic LatLon point.
  • lon - Optional longitude (degrees or None).
  • radius - Optional earth radius (meter).
  • Wm - Optional Wm class for the WM coordinate (Wm) or None.
  • name - Optional name (string).
Returns:
The WM coordinate (Wm) or 3-tuple (easting, northing, radius) id Wm is None.
Raises:
  • ValueError - If lon value is missing, if latlon is not scalar, if latlon is beyond the valid WM range and rangerrors is set to True or if radius is invalid.

Example:

>>> p = LatLon(48.8582, 2.2945)  # 448251.8 5411932.7
>>> w = toWm(p)  # 448252 5411933
>>> p = LatLon(13.4125, 103.8667)  # 377302.4 1483034.8
>>> w = toWm(p)  # 377302 1483035

unStr(name, *args, **kwds)

 

Return the string representation of an invokation.

Parameters:
  • name - Function, method or class name (string).
  • args - Optional positional arguments (tuple).
  • kwds - Optional keyword arguments (dict).
Returns:
Representation (string).

unroll180(lon1, lon2, wrap=True)

 

Unroll longitudinal delta and wrap longitude in degrees.

Parameters:
  • lon1 - Start longitude (degrees).
  • lon2 - End longitude (degrees).
  • wrap - Wrap and unroll to the (-180..+180] range (bool).
Returns:
2-Tuple (delta lon2-lon1, lon2) unrolled (degrees, degrees).

See Also: Capability LONG_UNROLL in GeographicLib.

unrollPI(rad1, rad2, wrap=True)

 

Unroll longitudinal delta and wrap longitude in radians.

Parameters:
  • rad1 - Start longitude (radians).
  • rad2 - End longitude (radians).
  • wrap - Wrap and unroll to the (-PI..+PI] range (bool).
Returns:
2-Tuple (delta rad2-rad1, rad2) unrolled (radians, radians).

See Also: Capability LONG_UNROLL in GeographicLib.

utmZoneBand2(lat, lon)

 

Return the UTM zone number and UTM Band letter for a location.

Parameters:
  • lat - Latitude (degrees) or string.
  • lon - Longitude (degrees) or string.
Returns:
2-Tuple (zone, Band) as (int, string).
Raises:
  • RangeError - If lat is outside the valid UTM bands or if lat or lon outside the valid range and rangerrrors set to True.
  • ValueError - Invalid lat or lon.

wrap180(deg)

 

Wrap degrees to (-180..+180].

Parameters:
  • deg - Angle (degrees).
Returns:
Degrees, wrapped (degrees180).

wrap360(deg)

 

Wrap degrees to (0..+360].

Parameters:
  • deg - Angle (degrees).
Returns:
Degrees, wrapped (degrees360).

wrap90(deg)

 

Wrap degrees to (-270..+90].

Parameters:
  • deg - Angle (degrees).
Returns:
Degrees, wrapped (degrees90).

wrapPI(rad)

 

Wrap radians to (-PI..+PI].

Parameters:
  • rad - Angle (radians).
Returns:
Radians, wrapped (radiansPI).

wrapPI2(rad)

 

Wrap radians to (0..+2PI].

Parameters:
  • rad - Angle (radians).
Returns:
Radians, wrapped (radiansPI2).

wrapPI_2(rad)

 

Wrap radians to (-3PI/2..+PI/2].

Parameters:
  • rad - Angle (radians).
Returns:
Radians, wrapped (radiansPI_2).

Variables Details

Conics

Registered conics (enum).
Value:
Conics.Be08Lb: Conic(name='Be08Lb', lat0=50.797815, lon0=4.35921583, p\
ar1=49.833333, par2=51.166667, E0=649328, N0=665262, k0=1, SP=2, datum\
=(name='GRS80', ellipsoid=Ellipsoids.GRS80, transform=Transforms.WGS84\
),
Conics.Be72Lb: Conic(name='Be72Lb', lat0=90, lon0=4.3674867, par1=49.8\
333339, par2=51.1666672, E0=150000.013, N0=5400088.438, k0=1, SP=2, da\
tum=(name='NAD83', ellipsoid=Ellipsoids.GRS80, transform=Transforms.NA\
D83),
...

Datums

Registered datums (enum).
Value:
Datums.BD72: Datum(name='BD72', ellipsoid=Ellipsoids.Intl1924, transfo\
rm=Transforms.BD72),
Datums.DHDN: Datum(name='DHDN', ellipsoid=Ellipsoids.Bessel1841, trans\
form=Transforms.DHDN),
Datums.ED50: Datum(name='ED50', ellipsoid=Ellipsoids.Intl1924, transfo\
rm=Transforms.ED50),
Datums.GRS80: Datum(name='GRS80', ellipsoid=Ellipsoids.GRS80, transfor\
m=Transforms.WGS84),
...

Ellipsoids

Registered ellipsoids (enum).
Value:
Ellipsoids.Airy1830: Ellipsoid(name='Airy1830', a=6377563.396, b=63562\
56.909, f_=299.3249646, f=0.003340851, e=0.081673374, e2=0.00667054, e\
22=0.006715335, n=0.00167322, R1=6370461.233666666, R2=6370459.6545894\
42, R3=6370453.309866445, Rr=6366914.608805893, Rs=6366901.239881964),
Ellipsoids.AiryModified: Ellipsoid(name='AiryModified', a=6377340.189,\
 b=6356034.448, f_=299.3249646, f=0.003340851, e=0.081673374, e2=0.006\
67054, e22=0.006715335, n=0.00167322, R1=6370238.275333334, R2=6370236\
.696361165, R3=6370230.351810658, Rr=6366691.774649803, Rs=6366678.406\
...

Transforms

Registered transforms (enum).
Value:
Transforms.BD72: Transform(name='BD72', tx=106.86863, ty=-52.29778, tz\
=103.72389, rx=-0, ry=-0, rz=-0.00001, s=1.2727, s1=1, sx=-0.33657, sy\
=-0.45696, sz=-1.84218),
Transforms.Bessel1841: Transform(name='Bessel1841', tx=-582, ty=-105, \
tz=-414, rx=-0.00001, ry=-0, rz=0.00001, s=-8.3, s1=0.99999, sx=-1.04,\
 sy=-0.35, sz=3.08),
Transforms.Clarke1866: Transform(name='Clarke1866', tx=8, ty=-160, tz=\
-176, rx=0, ry=0, rz=0, s=0, s1=1, sx=0, sy=0, sz=0),
...