Package pygeodesy :: Module points
[frames] | no frames]

Module points

Handle 2-d NumPy or other arrays as LatLons or as pseudo-x/-ys.

NumPy arrays are assumed to contain rows of points with a lat-, a longitude -and possibly other- values in different columns. While iterating over the array rows, create an instance of a given LatLon class "on-the-fly" for each row with the row's lat- and longitude.

The original NumPy array is read-accessed only and never duplicated, except to create a subset of the original array.

For example, to process a NumPy array, wrap the array by instantiating class Numpy2LatLon and specifying the column index for the lat- and longitude in each row. Then, pass the Numpy2LatLon instance to any pygeodesy function or method accepting a points argument.

Tested with 64-bit Python 2.6.9 (and numpy 1.6.2), 2.7.13 (and numpy 1.13.1), 3.5.3 and 3.6.2 on macOS 10.12.6 Sierra, with 64-bit Intel-Python 3.5.3 (and numpy 1.11.3) on macOS 10.12.6 Sierra and with Pythonista 3.1 using 64-bit Python 2.7.12 and 3.5.1 (both with numpy 1.8.0) on iOS 10.3.3.


Version: 17.09.14

Classes
  LatLon2psxy
Wrapper for LatLon points as "on-the-fly" pseudo-xy coordinates.
  Numpy2LatLon
Wrapper for NumPy arrays as "on-the-fly" LatLon points.
Functions
 
bounds(points, radius=None, wrap=True, LatLon=None)
Determine the lower-left and upper-right corners of a polygon defined by a list, sequence, set or tuple of LatLon points.
 
isclockwise(points, radius=None, wrap=True)
Determine the direction of a polygon defined by an array, list, sequence, set or tuple of LatLon points.
 
isconvex(points, radius=None, wrap=True)
Determine whether a polygon defined by an array, list, sequence, set or tuple of LatLon points is convex.
Function Details

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

 

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

Parameters:
  • points - The points defining the polygon (LatLon[]).
  • radius - Optional, mean earth radius (meter).
  • wrap - Optionally, wrap90(lat) and wrap180(lon) (bool).
  • LatLon - Optional class to use (LatLon).
Returns:
4-Tuple (lolat, lolon, hilat, hilon) corners (degrees) or 2-tuple (loLatLon, hiLatLon) if (LatLon) given.
Raises:
  • TypeError - Some points are not LatLon.
  • ValueError - Too few 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

isclockwise(points, radius=None, wrap=True)

 

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

Parameters:
  • points - The points defining the polygon (LatLon[]).
  • radius - Optional, mean earth radius (meter).
  • wrap - Optionally, wrap90(lat) and wrap180(lon) (bool).
Returns:
True if clockwise, False otherwise.
Raises:
  • TypeError - Some points are not LatLon.
  • ValueError - Too few 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, radius=None, wrap=True)

 

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

Parameters:
  • points - The points defining the polygon (LatLon[]).
  • radius - Optional, mean earth radius (meter).
  • wrap - Optionally, wrap90(lat) and wrap180(lon) (bool).
Returns:
True if convex, False otherwise.
Raises:
  • CrossError - Colinear point.
  • TypeError - Some points are not LatLon.
  • ValueError - Too few 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