[Gdal-dev] Batch export from a directory?

Matthew Perry perrygeo at gmail.com
Sat Mar 25 20:05:18 EST 2006


Jonathan,


On 3/25/06, Jonathan Greenberg <jgreenberg at arc.nasa.gov> wrote:
> Is there a way to select a directory and batch export using gdal all
> workable image files to a single output format (modifying the extension as
> necessary?)
>

 If you're using a bash shell, you might try a script along these lines:

====================
outputdir=/home/newdata
inputdir=/home/data

cd $inputdir
for raster in *; do

  gdalinfo $raster

  # If gdalinfo returned exit code 0,
  # we can assume its a valid raster image
  if [ $? = 0 ]; then

    # Assume the file prefix is everything before the first '.'
    prefix=` echo $raster | sed 's/\..*//'`

    # use gdal_translate to convert to ERDAS Imagine format
    gdal_translate -of "HFA" $raster ${outputdir}/${prefix}.img

  fi
done
=====================



--
Matt Perry
perrygeo at gmail.com
http://www.perrygeo.net




More information about the Gdal-dev mailing list