Umar Yusuf
Umar Yusuf

Reputation: 982

Stack geotiff images while retaining individual bands

I have two images with 3 and 5 bands respectively. How do I retain each image's individual bands after merging?

from osgeo import gdal

img_list = ['img1.tif', 'img2.tif']

vrt = gdal.BuildVRT("merged.vrt", img_list, separate=True)
gdal.Translate('merge_img.tif', vrt)

The code above will result in merge image with 2 bands. I want it to be 8 bands, that is: image1 (3 bands) + image2 (5 bands) = 8 bands.

Upvotes: 0

Views: 829

Answers (1)

Umar Yusuf
Umar Yusuf

Reputation: 982

gdal.BuildVRT can't do this, instead I used gdal_merge as follow;-

# pip install gdal-utils
import osgeo_utils.gdal_merge

parameters = ['', '-o', output_file_path] + img_list + ['-separate', '-ot', 'Float32']
osgeo_utils.gdal_merge.main(parameters)

Upvotes: 0

Related Questions