Get PROJ.4 representation of CRS object


Sean Gillies
 

Hi,

Rasterio's CRS.to_dict and .to_prog4 *do* return PROJ4 mappings and strings but we reduce to +init=epsg:xxxx when allowed. In the new world where there is no longer an epsg file to init from, it makes more sense to return the expanded PROJ4 form, I agree. We could do this for 1.2.0 at the risk of breaking programs with code like

epsg_code = crs.to_dict()["init"].split(":")[-1]

Nobody should need to do that as we have a .to_epsg method, but one of the laws of library development is that there will be some users critically dependent on any public property of the library, no matter if it was exposed by accident or by intent :)


On Sat, Dec 26, 2020 at 10:29 AM Denis Rykov <rykovd@...> wrote:
Thanks! This is exactly what I was looking for.

BTW GDAL has an appropriate method to export CRS to proj4:

>>> srs.ExportToProj4()
'+proj=utm +zone=5 +datum=WGS84 +units=m +no_defs '

In my opinion it would be nice to have it in rasterio.CRS as well.

On Sun, Dec 27, 2020 at 12:19 AM Alan Snow <alansnow21@...> wrote:
pyproj.CRS has a to_proj4 method that should be able to do that: https://pyproj4.github.io/pyproj/stable/examples.html,_._,_

--
Sean Gillies


Denis Rykov
 

Thanks! This is exactly what I was looking for.

BTW GDAL has an appropriate method to export CRS to proj4:

>>> srs.ExportToProj4()
'+proj=utm +zone=5 +datum=WGS84 +units=m +no_defs '

In my opinion it would be nice to have it in rasterio.CRS as well.

On Sun, Dec 27, 2020 at 12:19 AM Alan Snow <alansnow21@...> wrote:
pyproj.CRS has a to_proj4 method that should be able to do that: https://pyproj4.github.io/pyproj/stable/examples.html


Alan Snow
 

pyproj.CRS has a to_proj4 method that should be able to do that: https://pyproj4.github.io/pyproj/stable/examples.html


Denis Rykov
 

Hi folks! Is there a way to get a PROJ.4 representation of CRS object?

I've tried to use to_proj4() method:

from rasterio.crs import CRS
wkt = 'PROJCS["WGS 84 / UTM zone 5N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-153],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","32605"]]'
crs = CRS.from_wkt(wkt)
crs.to_proj4()

It returns: "+init=epsg:32605" but what I want to get is "+proj=utm +zone=5 +datum=WGS84 +units=m +no_defs". Is it possible?