2

I'm getting this error when trying to merge 5 different files:

2020-08-25T15:52:53     WARNING    Traceback (most recent call last): File "C:/Users/.../AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\interference_zone\interference_zone.py", line 362, in interference_calculation
              processing.run("gdal:merge", parameters)
              File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\tools\general.py", line 106, in run
              return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
              File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\core\Processing.py", line 137, in runAlgorithm
              raise QgsProcessingException(msg)
             _core.QgsProcessingException: Unable to execute algorithm
             Incorrect parameter value for INPUT

This is the code I am running:

parameters = {
        'INPUT': final_result_layers,
        'PCT' : True,
        'SPERATE' : True,
        'OUTPUT' : outputfile_path
    }
processing.run("gdal:merge", parameters)

The final_result_layers is a list of type QgsRasterLayer.

3
  • 1
    Can you merge those rasters without Python, i.e. through a normal working window of the Merge geoalgorithm? what is final_result_layers? can show them please?
    – Taras
    Aug 25, 2020 at 8:17
  • 1
    I would concentrate on the message Incorrect parameter value for INPUT. It may really mean that the value you are feeding is somehow wrong.
    – user30184
    Aug 25, 2020 at 8:27
  • @Taras I am runnin some QGIS raster calculator python scripts and the exported results are then loaded back into the program into an array result = QgsRasterLayer(outputfile_path, 'result') `final_result_layers.append(result)'
    – T-RexMan
    Aug 25, 2020 at 8:38

1 Answer 1

5

Input of function gdal:merge must be a list of path and not a list of QgsRasterLayer.

Here is a snippet wich works with your code:

layer_1 = QgsProject.instance().mapLayersByName("Fusionné")[0]
layer_2 = QgsProject.instance().mapLayersByName("Interpolé")[0]

final_result_layers = []
final_result_layers.append(layer_1.dataProvider().dataSourceUri())
final_result_layers.append(layer_2.dataProvider().dataSourceUri())

outputfile_path = "/home/jules.grillot/Bureau/test.tif"
parameters = {
        'INPUT': final_result_layers,
        'PCT' : True,
        'SPERATE' : True,
        'OUTPUT' : outputfile_path
    }
processing.runAndLoadResults("gdal:merge", parameters)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.