Proj

pyproj.Proj is functionally equivalent to the proj command line tool in PROJ.

The PROJ docs say:

The `proj` program is limited to converting between geographic and
projection coordinates within one datum.

pyproj.Proj

class pyproj.proj.Proj(projparams: Any = None, preserve_units: bool = True, **kwargs)[source]

Bases: pyproj._proj._Proj

Performs cartographic transformations (converts from longitude,latitude to native map projection x,y coordinates and vice versa) using PROJ (https://proj.org).

A Proj class instance is initialized with proj map projection control parameter key/value pairs. The key/value pairs can either be passed in a dictionary, or as keyword arguments, or as a PROJ string (compatible with the proj command). See https://proj.org/operations/projections/index.html for examples of key/value pairs defining different map projections.

Calling a Proj class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y native map projection coordinates (in meters). If optional keyword ‘inverse’ is True (default is False), the inverse transformation from x/y to lon/lat is performed. If optional keyword ‘errcheck’ is True (default is False) an exception is raised if the transformation is invalid. If errcheck=False and the transformation is invalid, no exception is raised and ‘inf’ is returned. If the optional keyword ‘preserve_units’ is True, the units in map projection coordinates are not forced to be meters.

Works with numpy and regular python array objects, python sequences and scalars.

srs

The string form of the user input used to create the Proj.

Type

str

crs

The CRS object associated with the Proj.

Type

pyproj.crs.CRS

__call__(*args, **kw) → Tuple[Any, Any][source]

Calling a Proj class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y native map projection coordinates (in meters). If optional keyword ‘inverse’ is True (default is False), the inverse transformation from x/y to lon/lat is performed. If optional keyword ‘errcheck’ is True (default is False) an exception is raised if the transformation is invalid. If errcheck=False and the transformation is invalid, no exception is raised and ‘inf’ is returned.

Inputs should be doubles (they will be cast to doubles if they are not, causing a slight performance hit).

Works with numpy and regular python array objects, python sequences and scalars, but is fastest for array objects.

__init__(projparams: Any = None, preserve_units: bool = True, **kwargs) → None[source]

initialize a Proj class instance.

See the PROJ documentation (https://proj.org) for more information about projection parameters.

Parameters
  • projparams (int, str, dict, pyproj.CRS) – A PROJ or WKT string, PROJ dict, EPSG integer, or a pyproj.CRS instance.

  • preserve_units (bool) – If false, will ensure +units=m.

  • **kwargs – PROJ projection parameters.

Example usage:

>>> from pyproj import Proj
>>> p = Proj(proj='utm',zone=10,ellps='WGS84', preserve_units=False)
>>> x,y = p(-120.108, 34.36116666)
>>> 'x=%9.3f y=%11.3f' % (x,y)
'x=765975.641 y=3805993.134'
>>> 'lon=%8.3f lat=%5.3f' % p(x,y,inverse=True)
'lon=-120.108 lat=34.361'
>>> # do 3 cities at a time in a tuple (Fresno, LA, SF)
>>> lons = (-119.72,-118.40,-122.38)
>>> lats = (36.77, 33.93, 37.62 )
>>> x,y = p(lons, lats)
>>> 'x: %9.3f %9.3f %9.3f' % x
'x: 792763.863 925321.537 554714.301'
>>> 'y: %9.3f %9.3f %9.3f' % y
'y: 4074377.617 3763936.941 4163835.303'
>>> lons, lats = p(x, y, inverse=True) # inverse transform
>>> 'lons: %8.3f %8.3f %8.3f' % lons
'lons: -119.720 -118.400 -122.380'
>>> 'lats: %8.3f %8.3f %8.3f' % lats
'lats:   36.770   33.930   37.620'
>>> p2 = Proj('+proj=utm +zone=10 +ellps=WGS84', preserve_units=False)
>>> x,y = p2(-120.108, 34.36116666)
>>> 'x=%9.3f y=%11.3f' % (x,y)
'x=765975.641 y=3805993.134'
>>> p = Proj("epsg:32667", preserve_units=False)
>>> 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045)
'x=-1783506.250 y= 6193827.033 (meters)'
>>> p = Proj("epsg:32667")
>>> 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045)
'x=-5851386.754 y=20320914.191 (feet)'
>>> # test data with radian inputs
>>> p1 = Proj("epsg:4214")
>>> x1, y1 = p1(116.366, 39.867)
>>> '{:.3f} {:.3f}'.format(x1, y1)
'116.366 39.867'
>>> x2, y2 = p1(x1, y1, inverse=True)
>>> '{:.3f} {:.3f}'.format(x2, y2)
'116.366 39.867'
definition_string() → str[source]

Returns formal definition string for projection

>>> Proj("epsg:4326").definition_string()
'proj=longlat datum=WGS84 no_defs ellps=WGS84 towgs84=0,0,0'
get_factors(longitude: Any, latitude: Any, radians: bool = False, errcheck: bool = False) → importlib._bootstrap.Factors[source]

New in version 2.6.0.

Calculate various cartographic properties, such as scale factors, angular distortion and meridian convergence. Depending on the underlying projection values will be calculated either numerically (default) or analytically.

The function also calculates the partial derivatives of the given coordinate.

Parameters
  • longitude (scalar or array (numpy or python)) – Input longitude coordinate(s).

  • latitude (scalar or array (numpy or python)) – Input latitude coordinate(s).

  • radians (boolean, optional) – If True, will expect input data to be in radians. Default is False (degrees).

  • errcheck (boolean, optional (default False)) – If True an exception is raised if the errors are found in the process. By default errcheck=False and inf is returned.

Returns

Return type

Factors

has_inverse

Returns true if this projection has an inverse

is_exact_same(self, other)

Compares Proj objects to see if they are exactly the same.

to_latlong() → pyproj.proj.Proj[source]

return a new Proj instance which is the geographic (lat/lon) coordinate version of the current projection

to_latlong_def() → Optional[str][source]

return the definition string of the geographic (lat/lon) coordinate version of the current projection

pyproj.proj.Factors

class pyproj.proj.Factors

New in version 2.6.0.

These are the scaling and angular distortion factors.

See PJ_FACTORS documentation # noqa

Parameters
  • meridional_scale (List[float]) – Meridional scale at coordinate.

  • parallel_scale (List[float]) – Parallel scale at coordinate.

  • areal_scale (List[float]) – Areal scale factor at coordinate.

  • angular_distortion (List[float]) – Angular distortion at coordinate.

  • meridian_parallel_angle (List[float]) – Meridian/parallel angle at coordinate.

  • meridian_convergence (List[float]) – Meridian convergence at coordinate. Sometimes also described as grid declination.

  • tissot_semimajor (List[float]) – Maximum scale factor.

  • tissot_semiminor (List[float]) – Minimum scale factor.

  • dx_dlam (List[float]) – Partial derivative of coordinate.

  • dx_dphi (List[float]) – Partial derivative of coordinate.

  • dy_dlam (List[float]) – Partial derivative of coordinate.

  • dy_dphi (List[float]) – Partial derivative of coordinate.

property angular_distortion

Alias for field number 3

property areal_scale

Alias for field number 2

property dx_dlam

Alias for field number 8

property dx_dphi

Alias for field number 9

property dy_dlam

Alias for field number 10

property dy_dphi

Alias for field number 11

property meridian_convergence

Alias for field number 5

property meridian_parallel_angle

Alias for field number 4

property meridional_scale

Alias for field number 0

property parallel_scale

Alias for field number 1

property tissot_semimajor

Alias for field number 6

property tissot_semiminor

Alias for field number 7