1

I am making a multiband virtual raster using gdalbuildvrt. Everything works fine, but a little detail remains annoying: I cannot control how the bands are sorted. I specified the input raster using the -input_file_list option, but the order is not kept by gdalbuildvrt. Instead it sort the band with lexicographic sorting, which is not what I want.

For instance, that would be my input file list:

/home/example/rasters/1634.tif
/home/example/rasters/5899.tif
/home/example/rasters/15680.tif

I'd like to have a vrt corresponding to:

band 1 -> 1634.tif
band 2 -> 5899.tif
band 3 -> 15680.tif

But instead I get:

band 1 -> 15680.tif
band 2 -> 1634.tif
band 3 -> 5899.tif

I could manually rearange things, but I'd like to avoid it if there is any cleaner solution...

So my question is: is there a way to control how gdalbuildvrt sort the bands when creating a multiband virtual raster?

  • 1
    A workaround could be to create a new sorted vrt with gdaltranslate and -b parameters. – user30184 Jul 8 '16 at 11:00
  • The problem here is that I have 679 bands... – Dim' Jul 13 '16 at 2:57
  • How about renaming source images so that they will be sorted as you wish by using vrt files? Should be possible to automate with a script that adds leading zeroes. – user30184 Jul 13 '16 at 9:16
  • Well, of course it is a possible workaround, but my question was more about if there is a way to do it within gdal, in order to avoid using this kind of workaround. But apparently there is not. Thank's! – Dim' Jul 17 '16 at 23:58
  • Gdalbuildvrt utility is based on an older gdalvrtmerge.py script. The script should still be available from GDAL sources. Perhaps it could be edited to sort files differently. – user30184 Jul 19 '16 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.