Merge TIFF files using GDAL. Output file was not created. How can I solve it?
Code
import subprocess
import glob
import os
import shlex
file_list = glob.glob(r"E:\Spekter\data\data\Task2\*.tif")
files_string = " ".join(file_list)
output_path = r"E:\Spekter\Task 2\output.tif"
command = f"gdal_merge.py -o {output_path} -of gtiff {files_string}"
print("Command:", command)
os.system(command)
if os.path.exists(output_path):
print(f"Output file '{output_path}' created successfully.")
else:
print("Output file was not created. Check for errors and permissions.")
Output
Command: gdal_merge.py -o E:\Spekter\Task 2\output.tif -of gtiff E:\Spekter\data\data\Task2\618_5405.tif E:\Spekter\data\data\Task2\618_5406.tif E:\Spekter\data\data\Task2\618_5407.tif E:\Spekter\data\data\Task2\619_5403.tif E:\Spekter\data\data\Task2\619_5404.tif E:\Spekter\data\data\Task2\619_5405.tif E:\Spekter\data\data\Task2\619_5406.tif E:\Spekter\data\data\Task2\619_5407.tif E:\Spekter\data\data\Task2\619_5408.tif E:\Spekter\data\data\Task2\619_5409.tif E:\Spekter\data\data\Task2\620_5400.tif E:\Spekter\data\data\Task2\620_5401.tif E:\Spekter\data\data\Task2\620_5402.tif E:\Spekter\data\data\Task2\620_5403.tif E:\Spekter\data\data\Task2\620_5404.tif E:\Spekter\data\data\Task2\620_5405.tif E:\Spekter\data\data\Task2\620_5406.tif E:\Spekter\data\data\Task2\620_5407.tif E:\Spekter\data\data\Task2\620_5408.tif E:\Spekter\data\data\Task2\620_5409.tif
Output file was not created. Check for errors and permissions.
command = f'gdal_merge.py -o "{output_path}" -of gtiff {files_string}'
Task 2
->Task2
.-v
to get more output.