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:
It seems the Anaconda GDAL package is installed with a wrong path for shared files, when installed on Windows:
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:
To:
After this change (and a new activation of the environment), ImportFromEPSG works as expected:
My 'conda info' output looks like this:
And the output of 'conda search gdal':
It would be nice if this could be fixed in an upcoming version.
Thank you.