ContinuumIO / anaconda-issues

Anaconda issue tracking
646 stars 220 forks source link

Wrong GDAL_DATA path on Anaconda Windows installation #2167

Open tingeman opened 7 years ago

tingeman commented 7 years ago

It seems the Anaconda GDAL package is installed with a wrong path for shared files, when installed on Windows:

In [1]: from osgeo import osr
In [2]: my_srs = osr.SpatialReference()
In [3]: my_srs.ImportFromEPSG(32622)
ERROR 4: Unable to open EPSG support file gcs.csv.
Try setting the GDAL_DATA environment variable to point to the
directory containing EPSG csv files.
Out[3]: 6

In [4]: import os
In [5]: os.environ['GDAL_DATA']
Out[5]: '"C:\\Anaconda2\\etc\\conda\\activate.d\\\\..\\..\\..\\Library\\share\\gdal"'

The GDAL_DATA environment variable is enclosed in an extra set of double quotes. It is not enough to strip the double quotes from the string and reassign it to the environvariable. Even after reloading the osr module, the ImportFromEPSG does not work.

The "gdal_activate.bat" script has to be changed from:

if not defined GDAL_DATA (
  set GDAL_DATA="%~dp0\..\..\..\Library\share\gdal"
  set _CONDA_SET_GDAL_DATA=1
)

To:

if not defined GDAL_DATA (
  set GDAL_DATA=%~dp0\..\..\..\Library\share\gdal
  set _CONDA_SET_GDAL_DATA=1
)

After this change (and a new activation of the environment), ImportFromEPSG works as expected:

In [1]: import os
In [2]: os.environ['GDAL_DATA']
Out[2]: 'C:\\Anaconda2\\etc\\conda\\activate.d\\\\..\\..\\..\\Library\\share\\gdal'

In [3]: from osgeo import osr
In [4]: my_srs = osr.SpatialReference()
In [5]: my_srs.ImportFromEPSG(32622)
Out[5]: 0

In [6]: print my_srs
PROJCS["WGS 84 / UTM zone 22N",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",-51],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","32622"]]

My 'conda info' output looks like this:

(C:\Anaconda2) C:\Users\thin>conda info Current conda install:

           platform : win-64
      conda version : 4.3.21
   conda is private : False
  conda-env version : 4.3.21
conda-build version : not installed
     python version : 2.7.13.final.0
   requests version : 2.14.2
   root environment : C:\Anaconda2  (writable)
default environment : C:\Anaconda2
   envs directories : C:\Anaconda2\envs
                      C:\Users\thin\AppData\Local\conda\conda\envs
                      C:\Users\thin\.conda\envs
      package cache : C:\Anaconda2\pkgs
                      C:\Users\thin\AppData\Local\conda\conda\pkgs
       channel URLs : https://conda.anaconda.org/anaconda-fusion/win-64
                      https://conda.anaconda.org/anaconda-fusion/noarch
                      https://repo.continuum.io/pkgs/free/win-64
                      https://repo.continuum.io/pkgs/free/noarch
                      https://repo.continuum.io/pkgs/r/win-64
                      https://repo.continuum.io/pkgs/r/noarch
                      https://repo.continuum.io/pkgs/pro/win-64
                      https://repo.continuum.io/pkgs/pro/noarch
                      https://repo.continuum.io/pkgs/msys2/win-64
                      https://repo.continuum.io/pkgs/msys2/noarch
        config file : C:\Users\thin\.condarc
         netrc file : None
       offline mode : False
         user-agent : conda/4.3.21 requests/2.14.2 CPython/2.7.13 Windows/7 Windows/6.1.7601
      administrator : True

And the output of 'conda search gdal':

(C:\Anaconda2) C:\Users\thin>conda search gdal Fetching package metadata ............. gdal 1.10.1 py26_0 defaults 1.10.1 py27_0 defaults 1.10.1 py33_0 defaults 1.10.1 np18py26_2 defaults 1.10.1 np18py27_2 defaults 1.10.1 np18py33_2 defaults 1.10.1 np18py34_2 defaults 1.11.0 np19py26_0 defaults 1.11.0 np19py27_0 defaults 1.11.0 np19py33_0 defaults 1.11.0 np19py34_0 defaults 1.11.1 np19py26_0 defaults 1.11.1 np19py27_0 defaults 1.11.1 np19py33_0 defaults 1.11.1 np19py34_0 defaults 1.11.2 np19py26_0 defaults 1.11.2 np19py27_0 defaults 1.11.2 np19py33_0 defaults 1.11.2 np19py34_0 defaults 1.11.2 np19py26_1 defaults 1.11.2 np19py27_1 defaults 1.11.2 np19py33_1 defaults 1.11.2 np19py34_1 defaults 1.11.2 np19py26_2 defaults 1.11.2 np19py27_2 defaults 1.11.2 np19py33_2 defaults 1.11.2 np19py34_2 defaults 1.11.2 np19py26_3 defaults 1.11.2 np19py27_3 defaults 1.11.2 np19py33_3 defaults 1.11.2 np19py34_3 defaults 1.11.2 np19py26_4 defaults 1.11.2 np19py27_4 defaults 1.11.2 np19py33_4 defaults 1.11.2 np19py34_4 defaults 2.0.0 np110py27_0 defaults 2.0.0 np110py34_0 defaults 2.0.0 np19py26_0 defaults 2.0.0 np19py27_0 defaults 2.0.0 np19py33_0 defaults 2.0.0 np19py34_0 defaults 2.0.0 py27_1 defaults 2.0.0 py34_1 defaults

  • 2.1.0 py27_0 defaults 2.1.0 py34_0 defaults libgdal 1.11.2 0 defaults 1.11.2 1 defaults 1.11.2 2 defaults 2.0.0 0 defaults 2.0.0 vc10_1 defaults [vc10] 2.0.0 vc9_1 defaults [vc9] 2.0.0 vc10_2 defaults [vc10] 2.0.0 vc9_2 defaults [vc9] 2.1.0 vc10_0 defaults [vc10]
  • 2.1.0 vc9_0 defaults [vc9]

It would be nice if this could be fixed in an upcoming version.

Thank you.

letmaik commented 6 years ago

I have exactly the same problem. Applying the fix in etc\conda\activate.d\gdal-activate.bat solved it. Version: gdal 2.1.0-py34_0