Saturday 17 June 2017

python - Cannot install a version of GDAL via Anaconda that permits reading BigTIFFs


I have some BigTiff files that I need to read into Python using gdal to do some analyses. According to GDAL's documentation:



When built with internal libtiff or with libtiff >= 4.0, GDAL also supports reading and writing BigTIFF files (evolution of the TIFF format to support files larger than 4 GB).




My version of libtiff is 4.0.9, so there should be no problem. However, if I try


bt = gdal.Open('path_to_bigtiff.tif'), 

bt is a NoneType. I tested to ensure that non-BigTIFF files are readable with gdal.Open(), which they are.


Furthermore, if I check the list of gdal's supported drivers' metadata like this:


md = gdal.GetDriverByName('GTiff').GetMetadata()
if md['DMD_CREATIONOPTIONLIST'].find('BigTIFF') == -1:
return 'BigTIFF is not supported'

BigTIFFs are not supported. My version of gdal is 2.2.2.



Using Anaconda, I created a new environment with


conda create --name test1 gdal

but I get the same result--gdal 2.2.2 is installed along with libtiff 4.0.9 and BigTiff files still cannot be read.


Using Anaconda again, I created a new environment with


conda create --name test2 gdal=2.3.1 -c conda-forge

but when I run import gdal in the test2 environment, I get the error message



ImportError: DLL load failed: The specified module could not be found.




How can I install a version of gdal that will permit me to load BigTiffs? I would also like it to be compatible with rasterio and fiona if possible.


Here is the output from conda info for the environment containing 2.2.2: (geoenv) C:\Users\Jon>conda info


     active environment : geoenv
active env location : C:\Users\Jon\Anaconda3\envs\geoenv
shell level : 2
user config file : C:\Users\Jon\.condarc
populated config files : C:\Users\Jon\.condarc
conda version : 4.5.9
conda-build version : 3.0.27

python version : 3.6.3.final.0
base environment : C:\Users\Jon\Anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/win-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/pro/win-64
https://repo.anaconda.com/pkgs/pro/noarch

https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : C:\Users\Jon\Anaconda3\pkgs
C:\Users\Jon\AppData\Local\conda\conda\pkgs
envs directories : C:\Users\Jon\Anaconda3\envs
C:\Users\Jon\AppData\Local\conda\conda\envs
C:\Users\Jon\.conda\envs
platform : win-64
user-agent : conda/4.5.9 requests/2.18.4 CPython/3.6.3 Windows/10 Windows/10.0.15063
administrator : False

netrc file : None
offline mode : False

Answer



Issues:



  1. The Anaconda default gdal may be built without BigTIFF support. If I create a non conda-forge env, i.e conda create -n testgdal gdal I can reproduce the md['DMD_CREATIONOPTIONLIST'].find('BigTIFF') == -1 no BigTIFF issue.

  2. There seems to be an incompatibility between the latest version of conda and vs2015_runtime and conda-forge. I updated my conda to 4.5.9 to match yours and vs2015_runtime (the Visual C++ runtime for applications compiled with MS Visual Studio) was upgraded from 14 to 15. If I then create a conda env with gdal from the conda-forge channel, I get the same ImportError: DLL load failed.


Fix:


If I create a conda-forge env and specify vs2015_runtime=14, everything works:



conda create -n testgdal -c conda-forge gdal vs2015_runtime=14
activate testgdal

(testgdal) python
Python 3.6.6 | packaged by conda-forge | (default, Jul 26 2018, 11:48:23) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> md = gdal.GetDriverByName('GTiff').GetMetadata()
>>> md['DMD_CREATIONOPTIONLIST'].find('BigTIFF')
2953

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...