UCRS a single wrapper class that accepts any CRS input and lazily converts to an instance of any library you need (e.g. cartopy, osgeo).
Project description
UCRS - Unified CRS
Stop juggling CRS formats. Start using UCRS.
Working with geospatial data in Python means dealing with different CRS representations:
- pyproj →
pyproj.CRS - cartopy →
cartopy.crs.CRSandcartopy.crs.Projection - GDAL/osgeo →
osgeo.osr.SpatialReference
Converting between these is well-documented but tedious. UCRS provides a single class that accepts any CRS input and seamlessly converts to whatever you need.
Features
- Universal Input: Accepts EPSG codes, WKT, PROJ strings, WKT files, or library-specific CRS objects
- Lazy Conversion: Only imports and converts when you access a specific property
- Cached Results: Conversions are cached - repeated access returns the same object
- Type Safe: Full type annotations for IDE support
- Inheritance: UCRS is a
pyproj.CRS, so it works anywhere pyproj does
Quick Start
from ucrs import UCRS
# Create from any CRS representation
crs = UCRS(4326) # EPSG code
crs = UCRS("EPSG:4326") # EPSG string
crs = UCRS("+proj=longlat +datum=WGS84") # PROJ string
crs = UCRS(wkt_string) # WKT
crs = UCRS(pyproj.CRS.from_epsg(4326)) # pyproj.CRS
crs = UCRS(cartopy.crs.PlateCarree()) # cartopy CRS
crs = UCRS(srs) # osgeo.osr.SpatialReference
crs = UCRS.from_file("path/to/crs.wkt") # WKT from file
# Use as pyproj.CRS (UCRS inherits from it)
crs.to_epsg() # Returns 4326
crs.is_geographic # Returns True
crs.to_wkt() # WKT string
# Convert to other libraries (lazy, cached)
crs.cartopy # Returns cartopy CRS (requires cartopy)
crs.osgeo # Returns SpatialReference (requires GDAL)
Example Use Cases
Working with matplotlib and cartopy:
import matplotlib.pyplot as plt
from ucrs import UCRS
# Create from EPSG code
crs = UCRS(3857) # Web Mercator
# Use in cartopy plot
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=crs.cartopy)
ax.coastlines()
Converting between GDAL and pyproj:
from osgeo import gdal
from ucrs import UCRS
# Get CRS from GDAL dataset
dataset = gdal.Open("myfile.tif")
gdal_srs = dataset.GetSpatialRef()
# Convert to UCRS
crs = UCRS(gdal_srs)
# Now use pyproj methods
print(f"EPSG: {crs.to_epsg()}")
print(f"Is projected: {crs.is_projected}")
Transforming coordinates:
from pyproj import Transformer
from ucrs import UCRS
wgs84 = UCRS(4326)
web_mercator = UCRS(3857)
# Since UCRS inherits from pyproj.CRS, use it directly
transformer = Transformer.from_crs(wgs84, web_mercator)
x, y = transformer.transform(40.7128, -74.0060) # NYC coordinates
Loading CRS from WKT files:
from pathlib import Path
from ucrs import UCRS
# Many GIS workflows store CRS definitions in .wkt or .prj files
crs = UCRS.from_file("projection.prj") # Shapefile projection file
crs = UCRS.from_file(Path("data/crs.wkt")) # Also accepts Path objects
# Use immediately with any library
print(f"EPSG: {crs.to_epsg()}")
ax.set_projection(crs.cartopy)
dataset.SetProjection(crs.osgeo.ExportToWkt())
How It Works
UCRS inherits from pyproj.CRS, making it a drop-in replacement that works anywhere a pyproj CRS is expected. All conversions follow this pattern:
- Input (any format) →
pyproj.CRS(during initialization) pyproj.CRS→ Output format (via lazy, cached properties)
Since UCRS inherits from pyproj.CRS, you can use all pyproj methods directly. Conversions to cartopy and osgeo are performed lazily when their properties are first accessed, then cached for subsequent use.
Requirements
- Python 3.10+
- pyproj (required)
- cartopy (optional)
- GDAL (optional)
Installation
# Minimal installation (pyproj only)
pip install ucrs
# With cartopy support
pip install ucrs[cartopy]
# With GDAL support
pip install ucrs[gdal]
# With all optional dependencies
pip install ucrs[complete]
License
MIT License - see LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ucrs-0.5.0.tar.gz.
File metadata
- Download URL: ucrs-0.5.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.1 CPython/3.14.3 Linux/6.19.8-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e86f264fe334ff1a659dfe90d53752265ca800dbe77b78f7ca3a514b6452c964
|
|
| MD5 |
477fe0a3c9b2cc381a85c15fc675392d
|
|
| BLAKE2b-256 |
b77d3c0fdce7abe55c06016df2403cd48d582ab594780823a26abc03ad80eeca
|
File details
Details for the file ucrs-0.5.0-py3-none-any.whl.
File metadata
- Download URL: ucrs-0.5.0-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.1 CPython/3.14.3 Linux/6.19.8-arch1-1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dd664c24f0602649338a3438f12dbaba75e76846bb67ff951d94529275e0d8d
|
|
| MD5 |
e5b27fb10688dc851d844d8571fecfae
|
|
| BLAKE2b-256 |
e0c250fe53f4c8e985c28815e3e4119775f4e3c46a958292e20382eef783576a
|