I'm approaching naw in the script and I'm trying to select many multi-band files from a folder and extract a single band from the file, putting everything in an output folder with the single-band transformed files.

Currently I concluded the following script:

 import sys, os

 output = "C:/../folder"

 layers =[layer for layer in QgsProject.instance().mapLayers().values()]

 for lyr in layers:
    if (lyr.type()==QgsMapLayer.RasterLayer): 

    cmd1 = "gdal_translate -b 1 "+ lyr.source() + "C:/..raster_input" + outputDir + "C:\..output" + lyr.name() + "test.ecw" 


    cmd2 = outputDir + "C:\..output" + lyr.name() + "test.ecw"


But it does not work!

1 Answer 1


Your path appears to be incorrect. I believe you would want something like

"gdal_translate -b 1 " raster_input_dir + "/" + raster_filename + " " + outputDir + 
 "/" + lyr.name() + "test.ecw"

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.