Search code examples
python-2.7image-processingzipgdalspectral-python

Reading zipped ESRI BIL files with Python


I have precipitation data from the PRISM Climate Group which are now offered in .bil format (ESRI BIL, I think) and I'd like to be able to read these datasets with Python.

I've installed the spectral package, but the open_image() method returns an error:

def ReadBilFile(bil):
    import spectral as sp
    b = sp.open_image(bil)
ReadBilFile(r'G:\truncated\ppt\1950\PRISM_ppt_stable_4kmM2_1950_bil.bil')

IOError: Unable to determine file type or type not supported.

The documentation for spectral clearly says that it supports BIL files, can anyone shed any light on what's happening here? I am also open to using GDAL, which supposedly supports the similar/equivalent ESRI EHdr format, but I can't find any good code snipets to get started.


Solution

  • It's now 2017 and there is a slightly better option. The package rasterio supports bil files.

    >>>import rasterio
    >>>tmean = rasterio.open('PRISM_tmean_stable_4kmD1_20060101_bil.bil')
    >>>tmean.affine
    Affine(0.041666666667, 0.0, -125.0208333333335,
           0.0, -0.041666666667, 49.9375000000025)
    >>> tmean.crs
    CRS({'init': 'epsg:4269'})
    >>> tmean.width
    1405
    >>> tmean.height
    621
    >>> tmean.read().shape
    (1, 621, 1405)