I try to open a jp2 image with the Python's Rasterio package. The code is below. The problem is that the coordinate reference system is not recognised and when I want to see the meta attribute of the opened band I see that the crs is None.

import rasterio
b6_path = 'D:\\IKI\\1np\\myimage_band06.jp2'
b6 = rasterio.open(b6_path, driver='JP2OpenJPEG')

# {'driver': 'JP2OpenJPEG',
# 'dtype': 'uint16',
# 'nodata': None,
# 'width': 5490,
# 'height': 5490,
# 'count': 1,
# 'crs': None,
# 'transform': Affine(20.0, 0.0, 699960.0,
#        0.0, -20.0, 4900020.0)}

As I know what the coordinate system is, I tried to set it manually like this:

import rasterio.crs
crs = rasterio.crs.CRS({"init": "epsg:32634"})
b6.crs = crs

But when I call the CRS() function I get this error message:

CRSError: The EPSG code is unknown. Unable to open EPSG support file gcs.csv.  Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.

I checked the GDAL_DATA variable by this command in the Anaconda prompt:

echo %GDAL_DATA%

the path to which the variable points to is: C:\Users\me\Miniconda3\Library\share\gdal

This folder contain a file named gcs.csv where the coordinate systems info should be so I do not know what is the problem? I found this discussion:


but it is too complicated for a beginner like me. Also, there seems to be no solution clearly stated there.

I am using Windows 10, Python 3.7, Miniconda 3, rasterio 1.0.28, and gdal 2.4.2

  • Does the gcs.csv have the 32634 COORD_REF_SYS_CODE defined? – nmtoken Sep 24 '19 at 10:37
  • @nmtoken No, there is no projection with this code defined in the file. This is strange because this is the code of WGS84/UTM zone 34N which is a common projection. Where to find the correct .csv file/s? – ABC Sep 24 '19 at 11:51
  • In fact, gcs.csv contain the geographic coordinate systems. The pcs.csv file has the projected coordinate systems including UTM. I don't know why the error message mentions gcs.csv. – ABC Sep 24 '19 at 13:05
  • Have you activated your conda environment before you run the script? It's activation of the environment that is required to set GDAL_DATA correctly (see github.com/conda-forge/libgdal-feedstock/blob/…). – sgillies Sep 25 '19 at 13:58
  • Not related, but important: your rasterio usage above is incorrect. Always use CRS.from_epsg(32634) instead. – sgillies Sep 25 '19 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.