2

This question might be repeat but I did not get answer. I have write flowing code in python ide .

out_srs = osr.SpatialReference()

   **self.out_srs.ImportFromEPSG(4326)** 

It run fine but when i run it from application it cause an error as follows

Note - Error in line enclosed in 2 stars -----

"Unable to load EPSG support gcs.csv file check setting GDAL_DATA environment variable which point to gdal library contains EPSG.csv file"

I have done it but i still get this error. but this code run separately but not in application. This code is from gdal2tile module of gdal. i am using python 2.7.6 and gdal 1.10.0 I am unable to sort out what is the problem and where it is. Please suggest how to solve this.

user2353848
  • 157
  • 3
  • 9

3 Answers3

5

GDAL needs an environment variable named GDAL_DATA that points to a directory with various data files, including gcs.csv. Learn more about it here.

To check if GDAL_DATA is set, and contains gcs.csv, and if this is readable, use the following snippets to check the application. This should be near the code that raises the error.

import os
import stat
gdal_data = os.environ['GDAL_DATA']
print('is dir: ' + str(os.path.isdir(gdal_data)))
gcs_csv = os.path.join(gdal_data, 'gcs.csv')
print('is file: ' + str(os.path.isfile(gcs_csv)))
st = os.stat(gcs_csv)
print('is readable: ' + str(bool(st.st_mode & stat.S_IRGRP)))

Anaconda / Miniconda users

The correct way to use either Anaconda or Miniconda is to activate an environment where GDAL is installed. For example, activate the base environment for Anaconda from Windows cmd.exe:

call %LOCALAPPDATA%\Continuum\anaconda3\Scripts\activate.bat base

Activating an environment triggers environment variables such as GDAL_DATA (and others) to be set, and often changes the command prompt prefix showing the environment name. These environment variables are unset/restored when the environment is deactivated.

conda deactivate
Mike T
  • 41,085
  • 18
  • 152
  • 203
  • After running this from appliction it return following output GDAL_DATA:C:\Program Files\GDAL\gdal-data; – user2353848 Sep 29 '14 at 05:11
  • How about the updated checks? You don't need to show the output, just if they all say `True` or not. – Mike T Sep 29 '14 at 05:26
  • out put of above code is follows is dir false is file false C:\\Program Files\\GDAL\\gdal-data;\\gcs.csv the smicolon in path is the problem why this come i dont understand – user2353848 Sep 29 '14 at 06:07
  • In IDLE, where you don't see the original error, do you see all `True` for the checks to see gcs.csv? – Mike T Sep 29 '14 at 07:25
  • one false and rest r true – user2353848 Sep 29 '14 at 11:39
  • Setting GDAL_DATA to the correct path does not work for me (Python 3.4 within Anaconda) although os.path.isfile(os.environ['GDAL_DATA']) and bool(os.stat(os.environ['GDAL_DATA']).st_mode & stat.S_IRGRP) both return True. Can somebody help? – MoTSCHIGGE Jul 30 '15 at 17:22
1

I was able to solve this issue by taking the following steps to set the GDAL_DATA variable in windows.

  1. Find the folder where gdal data is stored

    \Anaconda2\envs\gdaltest\Library\share\gdal
    
  2. open windows command prompt and run following command with the location of your gdal data folder.

    set GDAL_DATA=....\....\Library\share\gdal
    
Adrian W
  • 4,563
  • 11
  • 38
  • 52
0

Happened to me on MacOS Catalina (10.15.5) while playing with PyQGIS (QGIS 3.12). Just searched on Mac finder for gcs.csv which returned multiple results:

/usr/local/Cellar/gdal/2.4.2_4/share/gdal/gcs.csv

/Library/Frameworks/UnixImageIO.framework/Versions/F/Resources/epsg_csv/gcs.csv

/Library/Frameworks/GDAL.framework/Versions/2.2/Resources/gdal/gcs.csv

I stick with GDAL.Framework and just added this environment variable into my script:

import os

os.environ['GDAL_DATA'] = '/Library/Frameworks/GDAL.framework/Versions/2.2/Resources/gdal/'

Script is not complaining anymore.

Jakub
  • 106
  • 6