pyproj
pyproj is a Python interface to PROJ, a powerful C library for cartographic projections and coordinate transformations. It enables precise coordinate reference system (CRS) operations, geodesic computations, and transformation between different spatial reference systems with high accuracy and comprehensive EPSG support. The library is actively maintained with frequent releases, currently at version 3.7.2.
Warnings
- breaking Minimum Python version required for pyproj has increased significantly in recent 3.x releases. For pyproj 3.7.2, Python 3.11 or newer is required.
- breaking Minimum PROJ C library version required for pyproj has increased. For pyproj 3.7.2, PROJ 9.4 or newer is required.
- deprecated The `pyproj.Proj` class is considered a legacy interface. Its `init` keyword for initialization is deprecated.
- gotcha pyproj 3.x wheels no longer include transformation grids by default. These grids are crucial for certain high-accuracy datum transformations (e.g., NAD27 to NAD83).
- gotcha When performing transformations, the axis order (e.g., longitude/latitude vs. latitude/longitude, or easting/northing vs. northing/easting) can be a source of confusion. By default, PROJ might use different axis orders based on CRS definition.
- breaking The default value for `return_back_azimuth` in `fwd_intermediate` and `inv_intermediate` methods of `pyproj.Geod` changed from `False` to `True` to match `fwd` and `inv` methods.
Install
-
pip install pyproj -
conda install -c conda-forge pyproj
Imports
- CRS
from pyproj import CRS
- Transformer
from pyproj import Transformer
- Proj
from pyproj import Proj
- Geod
from pyproj import Geod
Quickstart
from pyproj import CRS, Transformer
# Define source and target Coordinate Reference Systems (CRSs)
wgs84 = CRS('EPSG:4326') # WGS84 Geographic CRS (longitude, latitude)
utm_zone_33n = CRS('EPSG:32633') # UTM Zone 33N Projected CRS (easting, northing)
# Create a transformer, ensuring consistent axis order (x, y / lon, lat)
transformer = Transformer.from_crs(wgs84, utm_zone_33n, always_xy=True)
# Define a point in WGS84 (longitude, latitude)
lon, lat = 10.0, 60.0
# Transform the point
x, y = transformer.transform(lon, lat)
print(f"Original WGS84 (lon, lat): ({lon}, {lat})")
print(f"Transformed UTM Zone 33N (easting, northing): ({x:.2f}, {y:.2f})")
# Transform multiple points
points_wgs84 = [(10.0, 60.0), (11.0, 61.0), (12.0, 62.0)]
transformed_points_utm = list(transformer.itransform(points_wgs84))
print(f"Transformed multiple points: {transformed_points_utm}")