converting hundreds of BIL/HDR rasters to TIFF

6320
1
08-21-2012 12:26 PM
TimSzeliga
New Contributor
I have hundreds of snow maps to convert from BIL/HDR to geoTIFF format.
Each raster is in Albers projection, covering one of a dozen standard regions.
Each region has a consistent number of rows and columns and the same corner points.
The unique raster values are (0=NULL, 50=LAND, 100=CLOUD, 250=SNOW).

I have HDR and PRJ files with each BIL.  I would like to export these using
a common color map (black/blue/cyan/red).  As these came from 20 archival CDs,
I would like to use compression to try to get them all onto one or two DVDs.

I can do it by hand, loading the BIL, setting display to Unique Values, modifying
the colors, then exporting to PNG.  There are so many rasters, I have to come up
with an automated method.  I am running in 9.3.1 with Spatial Analyst, but have access
to 10.1 as well.

This is where it gets tricky.  I've included a .CLR file with the BIL/HDR/PRJ, but it
ignores it.  I've tried including only (0/50/100/250) in the .CLR and also filling in
every value from (0-255). 

Exporting as TIFF is preferred, but it assigns random colors and does not allow
compression, even though the input is 8-bit unsigned integer.  PNG with a world file
would work, but again, it does not preserve colors.

Should there be an intermediate step, converting BIL to GRID, modifying colors and
computing unique values, followed by the export to PNG/TIFF?  How can these display
functions be incorporated into a script?

Tim Szeliga
timothy.szeliga@noaa.gov
National Weather Service
0 Kudos
1 Reply
Luke_Pinner
MVP Regular Contributor
Get GDAL (the simplest installs are either from GISInternals or OSGEO4W). Then use the "gdal_translate" utility from the command line or a batch script. 

Command line example:
for %i in (C:\inputdir\*.bil) do @gdal_translate -co 'COMPRESS=LZW' %i C:\outputdir\%~ni.tif


This will preserve the colour table.  The -co 'COMPRESS=LZW' will use LZW lossless compression for the output tif.

And here's a batch file to do the same, but recursively over subfolders and preserve the folder hierarchy: (note, the previous one liner will work from a command prompt, if you want to use it in a batch file, change the "%" symbols to "%%").
@echo off
cd /D C:\inputdir
for /R %%i in ("*.bil") do (
    mkdir "C:\outputdir%%~dpi"
    gdal_translate -co "COMPRESS=LZW" "%i" "C:\outputdir%%~dpi%~ni.tif"
)