2

I have a list with lots of VRTs. Each VRT is the mosaic for a single band for a single band. What I want to do is to make a final TIFF with as many layers as bands. I'm trying to first make one VRT and then convert it to a TIFF in Python. But what I get is a TIFF with a single layer...

My list of VRTs (vrts_per_date) kind of looks like this:

[296B02.vrt', 296B10.vrt', 296B08.vrt', 296B12.vrt', 296B07.vrt', 296B03.vrt', 296B11.vrt'...]

And then I use:

single_vrt = gdal.BuildVRT("my.vrt" vrts_per_date)

And finally I want to make a TIFF with all bands, so I use:

final_tif = gdal.Translate("my.tiff", single_vrt)

But when I open it in QGIS it's a mosaic, but with just one band... How can I get a TIFF as output with as many bands as VRTs in vrts_per_date?

1 Answer 1

2

By default BuildVRT creates a mosaic:

>>> verts_per_date = ['out1.vrt','out2.vrt','out3.vrt']
>>> mosaic_vrt = gdal.BuildVRT("my.vrt", verts_per_date)
>>> mosaic_tif = gdal.Translate("mymosaic.tiff", mosaic_vrt)

That creates mymosaic.tiff as a single band.

To create a multi-band VRT, pass separate=True:

>>> verts_per_date = ['out1.vrt','out2.vrt','out3.vrt']
>>> layer_vrt = gdal.BuildVRT("mylayer.vrt", verts_per_date, separate=True)
>>> layer_tif = gdal.Translate("mylayer.tiff", layer_vrt)

that creates mylayer.tiff with three bands.

Read the help for help(gdal.BuildVRTOptions) for more help, this is mentioned in help(gdal.BuildVRT).

  targetAlignedPixels --- whether to force output bounds to be multiple of output resolution.
  separate --- whether each source file goes into a separate stacked band in the VRT band.
  bandList --- array of band numbers (index start at 1).

Note there are some typos in your code and I had to create three VRTs to test this. Please try and make reproducible examples!

1
  • Sorry about the typos. That's really not great... But thank you so much, once again, for the help!! Commented Feb 2, 2020 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.