Python interface to PROJ library for cartographic projections and coordinate transformations
npx @tessl/cli install tessl/pypi-pyproj@3.7.0PyProj is a Python interface to PROJ, providing 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.
pip install pyprojimport pyprojCommon imports for working with coordinate systems and transformations:
from pyproj import CRS, Transformer, Proj, Geod
from pyproj import transform, itransform
from pyproj import get_authorities, get_codes, get_units_map
from pyproj import show_versionsfrom pyproj import CRS, Transformer
import pyproj
# Create coordinate reference systems
wgs84 = CRS('EPSG:4326') # WGS84 Geographic
utm_zone_33n = CRS('EPSG:32633') # UTM Zone 33N
# Create transformer for coordinate conversion
transformer = Transformer.from_crs(wgs84, utm_zone_33n, always_xy=True)
# Transform coordinates (longitude, latitude to easting, northing)
lon, lat = 10.0, 60.0
x, y = transformer.transform(lon, lat)
print(f"UTM coordinates: {x:.2f}, {y:.2f}")
# Transform multiple points
points = [(10.0, 60.0), (11.0, 61.0), (12.0, 62.0)]
transformed = list(transformer.itransform(points))
# Get projection information
print(f"Source CRS: {transformer.source_crs}")
print(f"Target CRS: {transformer.target_crs}")PyProj is built around several key components that work together to provide comprehensive geospatial coordinate operations:
This architecture enables PyProj to serve as the foundational coordinate transformation library for the Python geospatial ecosystem, supporting libraries like GeoPandas, Cartopy, and GDAL/OGR.
Complete CRS management including creation from various formats, validation, comparison, and conversion between different CRS representations.
class CRS:
def __init__(self, projparams: Any | None = None, **kwargs) -> None: ...
@classmethod
def from_epsg(cls, code: str | int) -> "CRS": ...
@classmethod
def from_wkt(cls, in_wkt_string: str) -> "CRS": ...
def to_string(self) -> str: ...
def equals(self, other: Any, ignore_axis_order: bool = False) -> bool: ...High-performance coordinate transformations between CRS with support for transformation pipelines, accuracy estimation, and batch processing.
class Transformer:
@classmethod
def from_crs(cls, crs_from: Any, crs_to: Any, **kwargs) -> "Transformer": ...
def transform(self, xx, yy, zz=None, tt=None, **kwargs) -> tuple: ...
def itransform(self, points, **kwargs) -> Iterator: ...
def transform_bounds(self, left, bottom, right, top, **kwargs) -> tuple: ...Geodesic computations for great circle calculations including forward/inverse calculations, intermediate points, and area/perimeter measurements.
class Geod:
def __init__(self, initstring: str | None = None, **kwargs) -> None: ...
def fwd(self, lons, lats, az, dist, **kwargs) -> tuple: ...
def inv(self, lons1, lats1, lons2, lats2, **kwargs) -> tuple: ...
def polygon_area_perimeter(self, lons, lats, **kwargs) -> tuple: ...Legacy projection interface maintaining compatibility with PROJ.4 workflows and providing direct projection operations.
class Proj:
def __init__(self, projparams: Any | None = None, preserve_units: bool = True, **kwargs) -> None: ...
def __call__(self, lon, lat, **kwargs) -> tuple: ...
def get_factors(self, longitude, latitude, **kwargs) -> "Factors": ...Access to PROJ database for querying coordinate reference systems, transformations, and spatial reference metadata.
def get_authorities() -> list[str]: ...
def get_codes(auth_name: str, pj_type: PJType | str, allow_deprecated: bool = False) -> list[str]: ...
def query_crs_info(
auth_name: str | None = None,
pj_types: PJType | list[PJType] | None = None,
area_of_interest: AreaOfInterest | None = None,
contains: bool = False,
allow_deprecated: bool = False
) -> list[CRSInfo]: ...
def get_units_map(auth_name: str | None = None, category: str | None = None, allow_deprecated: bool = False) -> dict[str, Unit]: ...Utility functions for version information, data management, and package configuration.
def show_versions() -> None: ...
def get_data_dir() -> str: ...
def set_network_enabled(enabled: bool) -> None: ...
# Global transformation functions
def transform(transformer, xx, yy, zz=None, tt=None, **kwargs) -> tuple: ...
def itransform(transformer, points, **kwargs) -> Iterator: ...# Enumerations
class WktVersion(Enum):
WKT2_2015 = "WKT2_2015"
WKT2_2015_SIMPLIFIED = "WKT2_2015_SIMPLIFIED"
WKT2_2019 = "WKT2_2019"
WKT2_2019_SIMPLIFIED = "WKT2_2019_SIMPLIFIED"
WKT1_GDAL = "WKT1_GDAL"
WKT1_ESRI = "WKT1_ESRI"
class ProjVersion(Enum):
PROJ_4 = 4
PROJ_5 = 5
class TransformDirection(Enum):
FORWARD = "FORWARD"
INVERSE = "INVERSE"
IDENT = "IDENT"
# Data structures
class AreaOfInterest:
west_lon_degree: float
south_lat_degree: float
east_lon_degree: float
north_lat_degree: float
class AreaOfUse:
west: float
south: float
east: float
north: float
name: str | None
class CRSInfo:
auth_name: str
code: str
name: str
type: str
deprecated: bool
area_of_use: AreaOfUse | None
projection_method_name: str | None
class Unit:
auth_name: str
code: str
name: str
category: str
conv_factor: float
proj_short_name: str | None
deprecated: bool
# Enumerations
class PJType(Enum):
"""Types of objects in PROJ database."""
CRS = "CRS"
PROJECTED_CRS = "PROJECTED_CRS"
GEOGRAPHIC_2D_CRS = "GEOGRAPHIC_2D_CRS"
GEOGRAPHIC_3D_CRS = "GEOGRAPHIC_3D_CRS"
VERTICAL_CRS = "VERTICAL_CRS"
COMPOUND_CRS = "COMPOUND_CRS"
GEOCENTRIC_CRS = "GEOCENTRIC_CRS"
ELLIPSOID = "ELLIPSOID"
DATUM = "DATUM"
PRIME_MERIDIAN = "PRIME_MERIDIAN"
# Exceptions
class ProjError(RuntimeError): ...
class CRSError(ProjError): ...
class GeodError(RuntimeError): ...
class DataDirError(RuntimeError): ...