Topics

Understanding `+wktext` more


David Hoese
 

I posted this originally on github, but have moved it here at Sean's request. Additional details of this question/issue are discussed in the `pyproj` repository [here](https://github.com/pyproj4/pyproj/issues/357).
 
I discovered that `nsper` and `ob_tran` projections required the `+wktext` parameter to be accepted by rasterio's `CRS` objects. It wasn't a big deal to add this until recently where I started using pyproj's `CRS` objects as my library's container for CRS information. Using pyproj 2.0+ and its `CRS` objects, the `+wktext` of my PROJ dictionary is being ignored/removed. This means that doing `rasterio.crs.CRS.from_dict(CRS.to_dict())` fails because rasterio needs the `+wktext` parameter.
 
I'm not sure if this should be considered a bug in pyproj or in rasterio or not a bug at all. I found the related issues in this repository that mentioned `+wktext` but I had trouble understanding what it was for and why it was needed. Any help and information would be appreciated.
 
## Examples
 

from pyproj import CRS                                                                                                                                                            
from rasterio.crs import CRS as rioCRS                                                                                                                                            
 
proj_dict = {'proj': 'ob_tran', 'o_proj': 'eqc', 'o_lat_p': 30.0, 'o_lon_p': 10.0, 'lon_0': -10.0, 'a': 6371000.0, 'b': 6371000.0, 'wktext': True}
 
CRS.from_dict(proj_dict).to_dict()                                                                                                                                                
# {'proj': 'ob_tran', 'o_proj': 'eqc', 'o_lat_p': 30.0, 'o_lon_p': 10.0, 'lon_0': -10.0, 'a': 6371000.0, 'b': 6371000.0, 'type': 'crs'}
 
rioCRS.from_dict(proj_dict)                                                                                                                                                       
# CRS.from_wkt('PROJCS["unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",6371000,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["custom_proj4"],EXTENSION["PROJ4","+proj=ob_tran +o_proj=eqc +o_lat_p=30.0 +o_lon_p=10.0 +lon_0=-10.0 +a=6371000.0 +b=6371000.0 +wktext=True"]]')
 
rioCRS.from_dict(CRS.from_dict(proj_dict).to_dict()) 
# CRSError: The PROJ4 dict could not be understood. OGR Error code 5
 


Sean Gillies
 

Hi,

On Mon, Jul 1, 2019 at 9:54 AM David Hoese <dhoese@...> wrote:
I posted this originally on github, but have moved it here at Sean's request. Additional details of this question/issue are discussed in the `pyproj` repository [here](https://github.com/pyproj4/pyproj/issues/357).
 
I discovered that `nsper` and `ob_tran` projections required the `+wktext` parameter to be accepted by rasterio's `CRS` objects. It wasn't a big deal to add this until recently where I started using pyproj's `CRS` objects as my library's container for CRS information. Using pyproj 2.0+ and its `CRS` objects, the `+wktext` of my PROJ dictionary is being ignored/removed. This means that doing `rasterio.crs.CRS.from_dict(CRS.to_dict())` fails because rasterio needs the `+wktext` parameter.
 
I'm not sure if this should be considered a bug in pyproj or in rasterio or not a bug at all. I found the related issues in this repository that mentioned `+wktext` but I had trouble understanding what it was for and why it was needed. Any help and information would be appreciated.
 
## Examples
 
from pyproj import CRS                                                                                                                                                            
from rasterio.crs import CRS as rioCRS                                                                                                                                            
 
proj_dict = {'proj': 'ob_tran', 'o_proj': 'eqc', 'o_lat_p': 30.0, 'o_lon_p': 10.0, 'lon_0': -10.0, 'a': 6371000.0, 'b': 6371000.0, 'wktext': True}
 
CRS.from_dict(proj_dict).to_dict()                                                                                                                                                
# {'proj': 'ob_tran', 'o_proj': 'eqc', 'o_lat_p': 30.0, 'o_lon_p': 10.0, 'lon_0': -10.0, 'a': 6371000.0, 'b': 6371000.0, 'type': 'crs'}
 
rioCRS.from_dict(proj_dict)                                                                                                                                                       
# CRS.from_wkt('PROJCS["unnamed",GEOGCS["unnamed ellipse",DATUM["unknown",SPHEROID["unnamed",6371000,0]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]],PROJECTION["custom_proj4"],EXTENSION["PROJ4","+proj=ob_tran +o_proj=eqc +o_lat_p=30.0 +o_lon_p=10.0 +lon_0=-10.0 +a=6371000.0 +b=6371000.0 +wktext=True"]]')
 
rioCRS.from_dict(CRS.from_dict(proj_dict).to_dict()) 
# CRSError: The PROJ4 dict could not be understood. OGR Error code 5
The latest version of pyproj uses PROJ version 6, which is based on WKT (version 2) and not on the old PROJ.4 key/value representation of projections. I think +wktext may be gone from PROJ 6 as its no longer needed to carry extra WKT information into the PROJ.4 realm. If you really want to use the pyproj.CRS class like this, you'll need to seek help from that project.

Furthermore dicts are no longer the highest fidelity interface between pyproj and rasterio. To make a rasterio CRS object from a pyproj CRS object, export WKT (version 1) from the latter [1] and send that to rasterio.crs.CRS.from_wkt(). I haven't tested this, but am confident that it's the best approach.


--
Sean Gillies