I am trying to stack the single band image into a composite band. I am able to do the stack the bands but the crs is not set.Also when i use the outputSRS in my code the code runs but the image is not created and if i leave it out the stacking is done but no crs is set

import rasterio
import os
import gdal
file_list = []
path = "M:\\sentinel\\tiff\\"
file_path = os.listdir(path)
cp_meta = rasterio.open(path + file_path[0])
meta = cp_meta.meta
meta.update(count = len(file_list))
for file in file_path:
    file = os.path.join(path,file)

meta.update(count = len(file_list))

save_path = "M:\\sentinel\\stack\\stack.tif"
outvrt = './stacked.vrt'
outds = gdal.BuildVRT(outvrt, file_list,xRes=10,yRes=10,separate=True)
outds = gdal.Translate(save_path,outds,format = "GTiff",creationOptions['TILED:YES'],outputSRS="EPSG:32633" )

i dont want to create another file using gdal.Warp just to set the crs.In the documentation for gdal translateoptions this is the correct way, but i dont know why its not working


1 Answer 1


I had a similar problem some time ago when assigning crs with gdal.Translate. I ended up using gdal.Warp as a small intermediate step before producing the .tif output. The good thing is that the warping operation on the .vrt file is fast.

So maybe in your case you could try out adding:

outds = gdal.BuildVRT(outvrt, file_list,xRes=10,yRes=10,separate=True)
final_outds = gdal.Warp(outvrt, outds, dstSRS='EPSG:32633')
final_outds = gdal.Translate(save_path, final_outds, format = "GTiff", creationOptions['TILED:YES'])
final_outds = None

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.