Search code examples
pythongdal

unable to load "gcs.csv" file in gdal


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.


Solution

  • 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