Interconverting between pyproj and rasterio CRS objects


Nick Weir
 

Hi there!

Now that geopandas is using pyproj CRS objects as the default for tracking CRSs in GeoDataFrames, I'm finding myself needing to figure out a way to frequently check identity and interconvert back and forth between pyproj.crs.CRS objects and rasterio.crs.CRS objects. However, I'm having a hard time figuring out the "ideal" way to do this. It's great that the following works:
import rasterio
import pyproj
pp_crs = pyproj.crs.CRS.from_epsg(4326)
rio_crs = rasterio.crs.CRS.from_epsg(4326)
assert pp_crs == rio_crs

I'm trying to figure out the best way to pass around CRSs within a python library (ideally in a single object type) and encountering issues. I don't want to wed myself to using EPSG codes to interconvert between objects, because I want to be able to accommodate CRSs/SRSs without codes. However, I'm finding problems using something else (like a WKT string) to convert between rasterio.crs.CRSs and pyproj.crs.CRSs. For example:
import rasterio
import pyproj
pp_crs = pyproj.crs.CRS.from_epsg(4326)
rio_crs = rasterio.crs.CRS.from_epsg(4326)
pp_to_rio_crs = rasterio.crs.CRS.from_wkt(pp_crs.to_wkt())
assert rio_crs == pp_to_rio_crs
Fails. Any thoughts? I could definitely be missing something here. Thanks! -N

Join main@rasterio.groups.io to automatically receive all group messages.