I have been fighting with getting GDAL installed properly for some time now, and just when I thought I had everything working properly I discovered another road block.
I have installed GDAL using the solution described here, which is a form that supports HDF4 file formats. For example, using gdalinfo --formats
in bash returns a list of supported file formats, and HDF4 is included there. In addition, gdalinfo XYZ.hdf
returns a complete description of whatever hdf file I input.
However, when trying to work with HDF4 files through Python, I spring an error that HDF4 is not a supported file format. Using
import osgeo.gdal as gdal
gdal.GetDriverByName('HDF4')
yields no return whatsoever.
I am confused because GDAL appears to be built properly for me, but I can't get it to work through Python. I've explored this source as well as this source, but they describe GDAL installation with HDF4 support - which I've already accomplished. For some reason it seems like Python doesn't know how to use the GDAL I've installed to its fullest potential...
Versions: Mac OSX El Capitan Version 10.11.6; GDAL 2.2.1, released 2017/06/23
Finally figured it out, folks. I'm not sure which exact steps I needed or were not necessary, so I'll post my full workflow in order to maintain transparency.
As per the comments of Dmitri and Logan above, I investigated as to whether or not I had the proper gdal
python library, rather than simply a gdal
bash library. Still unsure of what the difference is, but as it turns out I had a couple different gdal libraries present within the packages subfolder in anaconda (cd /Users/myusername/anaconda/pkgs
, ls
). I removed these libraries using rm
and some tag (maybe -r
?).
I then reinstalled my spatial libraries using anaconda, following the guidelines posted here. Unfortunately my bash was unable to access the jgomezdans website but I was able to bypass this element of the equation by using conda install proj4
(rather than conda install -c https://conda.binstar.org/jgomezdans proj4
), etc.
After installing all of the scipy stuff etc, I brought in proj4
, hdf4
, and gdal
(in that order). When trying to install geos
I caught an error that it had already been installed.
With all of this completed, I used the command in my original post, as well as in Logan's comment, to check that HDF4
was present. My command returns the following:
<osgeo.gdal.Driver; proxy of <Swig Object of type 'GDALDriverShadow *' at 0x10fc66180> >
Logan's returns a full list of the available gdal
drivers in python's gdal
. Sure enough, hdf4
is on the list.
tl;dr I uninstalled everything and reinstalled many things.