Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_wkt fails with WKT1_GDAL for EPSG:4979 #757

Closed
glostis opened this issue Dec 10, 2020 · 2 comments
Closed

to_wkt fails with WKT1_GDAL for EPSG:4979 #757

glostis opened this issue Dec 10, 2020 · 2 comments
Labels

Comments

@glostis
Copy link
Contributor

glostis commented Dec 10, 2020

Hi,

I'm using your excellent CRS compatibility guide to convert pyproj.CRS objects into rasterio.crs.CRS objects in order to properly encode the CRS of some images which happen to be DEMs - I therefore want the vertical component of the CRS to be correct.

Specifically, I need to write a GeoTIFF with CRS EPSG:4979, and another one with CRS EPSG:4326+5773 (thanks @snowman2 for the great info you gave me in #630 about CompoundCRS by the way!).

I have rasterio 1.1.8 (rasterio.__gdal_version__ 2.4.4) and pyproj 2.6.1.post1 both installed from their respective PyPI wheels.

The following snippet:

import rasterio
import rasterio.crs
from pyproj.crs import CRS
from pyproj.enums import WktVersion

rasterio.crs.CRS.from_wkt(CRS("EPSG:4326+5773").to_wkt(WktVersion.WKT1_GDAL))
rasterio.crs.CRS.from_wkt(CRS("EPSG:4979").to_wkt(WktVersion.WKT1_GDAL))

works for EPSG:4326+5773, but fails for EPSG:4979 with the following traceback:

Traceback (most recent call last):
  File "t.py", line 7, in <module>
    rasterio.crs.CRS.from_wkt(CRS("EPSG:4979").to_wkt(WktVersion.WKT1_GDAL))
  File "/home/glostis/.venv/multidem/lib/python3.8/site-packages/rasterio/crs.py", line 462, in from_wkt
    obj._crs = _CRS.from_wkt(wkt, morph_from_esri_dialect=morph_from_esri_dialect)
  File "rasterio/_crs.pyx", line 383, in rasterio._crs._CRS.from_wkt
ValueError: A string is expected

If I remove the WktVersion.WKT1_GDAL from the above snippet, the conversion to a rasterio.crs.CRS works in both cases - or at least the code doesn't crash.

Can I safely remove WktVersion.WKT1_GDAL and still expect my conversion to be correct? Do you know why the conversion for EPSG:4979 fails in the first case? Is it because it's a 3D CRS?

Thanks!

@snowman2
Copy link
Member

Do you know why the conversion for EPSG:4979 fails in the first case? Is it because it's a 3D CRS?

When using the projinfo command I see this output:

$ projinfo EPSG:4979 -o WKT1:GDAL
WKT1:GDAL string:
Error when exporting to WKT1:GDAL: WKT1 does not support Geographic 3D CRS.

Can I safely remove WktVersion.WKT1_GDAL and still expect my conversion to be correct?

The only way to for it to be safe would be to use GDAL 3+ with PROJ 6+. Otherwise, you will need to proceed with caution and I would recommend doing more validation to be sure everything worked as expected.

@glostis
Copy link
Contributor Author

glostis commented Dec 14, 2020

I see, thank you for the explanation!

@glostis glostis closed this as completed Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants