Billy,

bandList is currently ignored in the separate=True case. This would be a reasonable enhancement request that you could file on https://github.com/OSGeo/gdal/issues/new

One of the workaround for now is to postedit the generate VRT file and substitute the <SourceBand>1</SourceBand> element with <SourceBand>2</SourceBand>

You could also use use gdal.Translate() to produce a VRT with the second band of each source file, and run gdal.BuildVRT() on those files, but that would produce temporary files. If you don't need to serialize the output_vrt_fname, but use the returned dataset object with other APIs in the same process, you could avoid actual file creation by using an empty name for those intermediate VRT files, get the returned dataset object, and pass an array with those dataset objects instead of lst_of_input_geotiff_files.

Even

Le 19/01/2022 à 16:51, Billy Babis a écrit :

Hi there.

Given 3 input geotiffs (each with 2 bands), I want to create 1 geotiff with 3 bands (the 2nd band from each aforementioned geotiff). This should be quite simple using gdal.BuildVRT and gdal.translate. But, gdal.BuildVRT will not allow me to select the 2nd band from each input image. The following code produces the following warning:

*Code:*
gdal.BuildVRT(output_vrt_fname, lst_of_input_geotiff_files, separate=True, bandList=[2])

*Warning:*
 "fname.tif has 2 bands. Only the first one will be taken into account for the -separate case"

Of course, I do not want to only use the first band, I want to use the 2nd band to create the VRT. Please let me know what I'm doing wrong and how I can fix it.

Best,
Billy B

--
Billy Babis
PhD Candidate: Environmental Economics & Policy (ABD)
Computer Science B.S.
1-(908)-403-2006


_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

--
http://www.spatialys.com
My software is free, but my time generally not.

_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to