[gdal-dev] gdalbuilvrt and multiband files

Martin Lambers marlam at marlam.de
Tue Dec 6 15:08:21 EST 2011


Hi Jose!

On Tue, 6 Dec 2011 17:52:17 +0000, Jose Gomez-Dans wrote:
> I'm trying to build a VRT file out of a number of multiband files
> using gdalbuildvrt. Let's say I have N 7-band files, and I want build
> 7 N-band files (i.e., I want to stack all the bands in the same
> dataset). I have accomplished this thus far by having a prior step
> that creates a VRT for each individual band, and I then stack them
> using gdalbuildvrt -separate. However, i was wondering whether
> there's any more direct way of doing this? I guess that one way would
> be to build the XML file directly, but I was keen in finding some
> "shell-fu" way!

This might be slightly offtopic, but if you are using the latest GDAL
from svn, you could try the brand new GTA driver to store your files
in GTA format. Then you can use the gta tool, which was made for
exactly this kind of generic array data manipulation:

# loop over 7 bands, called 'components' in GTA
for j in `seq 0 6`; do
  # loop over N input files "in*.gta"
  for i in `seq 1 N`; do
    # extract the current component into its own file
    gta component-extract -k $j < in$i.gta > tmp$i.gta
  done
  # merge the extracted components into the output file
  gta component-merge tmp*.gta > out$j.gta
  rm tmp*.gta
done

Not a pure GDAL solution, but plenty of shell-fu :)

Martin


More information about the gdal-dev mailing list