Package pyproj

Package pyproj

source code

Cython wrapper to provide python interfaces to PROJ.4 (https://github.com/OSGeo/proj.4/wiki) functions.

Performs cartographic transformations and geodetic computations.

The Proj class can convert from geographic (longitude,latitude) to native map projection (x,y) coordinates and vice versa, or from one map projection coordinate system directly to another. The module variable pj_list is a dictionary containing all the available projections and their descriptions.

The Geod class can perform forward and inverse geodetic, or Great Circle, computations. The forward computation involves determining latitude, longitude and back azimuth of a terminus point given the latitude and longitude of an initial point, plus azimuth and distance. The inverse computation involves determining the forward and back azimuths and distance given the latitudes and longitudes of an initial and terminus point.

Input coordinates can be given as python arrays, lists/tuples, scalars or numpy/Numeric/numarray arrays. Optimized for objects that support the Python buffer protocol (regular python and numpy array objects).

Download: http://python.org/pypi/pyproj

Requirements: Python 2.6, 2.7, 3.2 or higher version.

Example scripts are in 'test' subdirectory of source distribution. The 'test()' function will run the examples in the docstrings.

Contact: Jeffrey Whitaker <jeffrey.s.whitaker@noaa.gov

copyright (c) 2006 by Jeffrey Whitaker.

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both the copyright notice and this permission notice appear in supporting documentation. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


Version: 1.9.6

Classes
  Geod
performs forward and inverse geodetic, or Great Circle, computations.
  Proj
performs cartographic transformations (converts from longitude,latitude to native map projection x,y coordinates and vice versa) using proj (https://github.com/OSGeo/proj.4/wiki).
Functions
 
itransform(p1, p2, points, radians=False, switch=False)
points2 = transform(p1, p2, points1, radians=False) Iterator/generator version of the function pyproj.transform.
source code
 
test(**kwargs)
run the examples in the docstrings using the doctest module
source code
 
transform(p1, p2, x, y, z=None, radians=False)
x2, y2, z2 = transform(p1, p2, x1, y1, z1, radians=False)
source code
Variables
  __package__ = 'pyproj'
  geodesic_version_str = '1.46.1'
  pj_ellps = {'APL4.9': {'a': 6378137.0, 'description': 'Appl. P...
  pj_list = {'aea': 'Albers Equal Area', 'aeqd': 'Azimuthal Equi...
  proj_version_str = '4.9.3'
  pyproj_datadir = '/home/snowal/scripts/pyproj/lib/pyproj/data'
  string_types = (<type 'basestring'>)
Function Details

itransform(p1, p2, points, radians=False, switch=False)

source code 

points2 = transform(p1, p2, points1, radians=False) Iterator/generator version of the function pyproj.transform. Transform points between two coordinate systems defined by the Proj instances p1 and p2. This function can be used as an alternative to pyproj.transform when there is a need to transform a big number of coordinates lazily, for example when reading and processing from a file. Points1 is an iterable/generator of coordinates x1,y1(,z1) or lon1,lat1(,z1) in the coordinate system defined by p1. Points2 is an iterator that returns tuples of x2,y2(,z2) or lon2,lat2(,z2) coordinates in the coordinate system defined by p2. z are provided optionally.

Points1 can be:

  • a tuple/list of tuples/lists i.e. for 2d points: [(xi,yi),(xj,yj),....(xn,yn)]
  • a Nx3 or Nx2 2d numpy array where N is the point number
  • a generator of coordinates (xi,yi) for 2d points or (xi,yi,zi) for 3d

If optional keyword 'switch' is True (default is False) then x, y or lon,lat coordinates of points are switched to y, x or lat, lon. If optional keyword 'radians' is True (default is False) and p1 is defined in geographic coordinate (pj.is_latlong() is True), x1,y1 is interpreted as radians instead of the default degrees. Similarly, if p2 is defined in geographic coordinates and radians=True, x2, y2 are returned in radians instead of degrees. if p1.is_latlong() and p2.is_latlong() both are False, the radians keyword has no effect. Example usage: >>> # projection 1: WGS84 >>> # (defined by epsg code 4326) >>> p1 = Proj(init='epsg:4326') >>> # projection 2: GGRS87 / Greek Grid >>> p2 = Proj(init='epsg:2100') >>> # Three points with coordinates lon, lat in p1 >>> points = [(22.95, 40.63), (22.81, 40.53), (23.51, 40.86)] >>> # transform this point to projection 2 coordinates. >>> for pt in itransform(p1,p2,points): '%6.3f %7.3f' % pt '411050.470 4497928.574' '399060.236 4486978.710' '458553.243 4523045.485'

transform(p1, p2, x, y, z=None, radians=False)

source code 

x2, y2, z2 = transform(p1, p2, x1, y1, z1, radians=False)

Transform points between two coordinate systems defined by the Proj instances p1 and p2.

The points x1,y1,z1 in the coordinate system defined by p1 are transformed to x2,y2,z2 in the coordinate system defined by p2.

z1 is optional, if it is not set it is assumed to be zero (and only x2 and y2 are returned).

In addition to converting between cartographic and geographic projection coordinates, this function can take care of datum shifts (which cannot be done using the __call__ method of the Proj instances). It also allows for one of the coordinate systems to be geographic (proj = 'latlong').

If optional keyword 'radians' is True (default is False) and p1 is defined in geographic coordinate (pj.is_latlong() is True), x1,y1 is interpreted as radians instead of the default degrees. Similarly, if p2 is defined in geographic coordinates and radians=True, x2, y2 are returned in radians instead of degrees. if p1.is_latlong() and p2.is_latlong() both are False, the radians keyword has no effect.

x,y and z can be numpy or regular python arrays, python lists/tuples or scalars. Arrays are fastest. For projections in geocentric coordinates, values of x and y are given in meters. z is always meters.

Example usage:

>>> # projection 1: UTM zone 15, grs80 ellipse, NAD83 datum
>>> # (defined by epsg code 26915)
>>> p1 = Proj(init='epsg:26915')
>>> # projection 2: UTM zone 15, clrk66 ellipse, NAD27 datum
>>> p2 = Proj(init='epsg:26715')
>>> # find x,y of Jefferson City, MO.
>>> x1, y1 = p1(-92.199881,38.56694)
>>> # transform this point to projection 2 coordinates.
>>> x2, y2 = transform(p1,p2,x1,y1)
>>> '%9.3f %11.3f' % (x1,y1)
'569704.566 4269024.671'
>>> '%9.3f %11.3f' % (x2,y2)
'569722.342 4268814.027'
>>> '%8.3f %5.3f' % p2(x2,y2,inverse=True)
' -92.200 38.567'
>>> # process 3 points at a time in a tuple
>>> lats = (38.83,39.32,38.75) # Columbia, KC and StL Missouri
>>> lons = (-92.22,-94.72,-90.37)
>>> x1, y1 = p1(lons,lats)
>>> x2, y2 = transform(p1,p2,x1,y1)
>>> xy = x1+y1
>>> '%9.3f %9.3f %9.3f %11.3f %11.3f %11.3f' % xy
'567703.344 351730.944 728553.093 4298200.739 4353698.725 4292319.005'
>>> xy = x2+y2
>>> '%9.3f %9.3f %9.3f %11.3f %11.3f %11.3f' % xy
'567721.149 351747.558 728569.133 4297989.112 4353489.644 4292106.305'
>>> lons, lats = p2(x2,y2,inverse=True)
>>> xy = lons+lats
>>> '%8.3f %8.3f %8.3f %5.3f %5.3f %5.3f' % xy
' -92.220  -94.720  -90.370 38.830 39.320 38.750'
>>> # test datum shifting, installation of extra datum grid files.
>>> p1 = Proj(proj='latlong',datum='WGS84')
>>> x1 = -111.5; y1 = 45.25919444444
>>> p2 = Proj(proj="utm",zone=10,datum='NAD27')
>>> x2, y2 = transform(p1, p2, x1, y1)
>>> "%s  %s" % (str(x2)[:9],str(y2)[:9])
'1402285.9  5076292.4'

Variables Details

pj_ellps

Value:
{'APL4.9': {'a': 6378137.0,
            'description': 'Appl. Physics. 1965',
            'rf': 298.25},
 'CPM': {'a': 6375738.7,
         'description': 'Comm. des Poids et Mesures 1799',
         'rf': 334.29},
 'GRS67': {'a': 6378160.0,
           'description': 'GRS 67(IUGG 1967)',
...

pj_list

Value:
{'aea': 'Albers Equal Area',
 'aeqd': 'Azimuthal Equidistant',
 'airy': 'Airy',
 'aitoff': 'Aitoff',
 'alsk': 'Mod. Stererographics of Alaska',
 'apian': 'Apian Globular I',
 'august': 'August Epicycloidal',
 'bacon': 'Bacon Globular',
...