0

I try to project a raster into another projection and I cannot manage to use the rasterio.crs module

I can obtain the CRS of a file using the following code :

import rasterio as rio

with rio.open('a_file.tif') as f: # not relevant that I give you the file
    print(f.crs)
crs
>>> CRS.from_epsg(4326)

If instead I want to create a CRS from scratch with :

rio.crs.CRS.from_string('EPSG:4326')

I get the following error :

CPLE_OpenFailedError: Unable to open EPSG support file gcs.csv. Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.

So I checked the GDAL_DATAenv variable :

import os 

os.environ['GDAL_DATA']
>>> '/usr/share/gdal'

but no trace of a gcs.csv file.

Note

  • I work in a shared environment and I cannot afford to just rebuild everything from scratch.
  • The gdal CLI is also installed in this environment and looking at the documentation I think they are not compatible.
  • I tried to start my file by
import os 

if 'GDAL_DATA' in list(os.environ.keys()): del os.environ['GDAL_DATA']
if 'PROJ_LIB' in list(os.environ.keys()): del os.environ['PROJ_LIB']

but it doesn't change anything

Questions

How can I use the rasterio.crs module?
Where should be pointing the GDAL_DATA?
Is it a real error or just hiding something else?

config

Python==3.6.9
rasterio==1.1.8
pyproj==2.6.1
GDAL==3.0.4
1
  • Can you please provide the version of the tools you use, especially Python, PROJ, GDAL and rasterio? Jan 8 '21 at 22:07
4

This is a known issue of rasterio (in conda for example)

Answers are given in

and many more.

Try setting the GDAL_DATA environment to a path which contains a gcs.csv file (use search to find a path)

os.environ['GDAL_DATA'] = '.../site-packages/rasterio/gdal_data'

Or

os.environ['GDAL_DATA'] = '..../site-packages/fiona/gdal_data'
1
  • sorry for the duplicate and thank you for taking the time to anwser Jan 7 '21 at 16:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.