I am trying to make a script, to run at the toolbox, that receives a raster file and has an identical output to it, following the idea from here.
I couldn't find a complete script that works unchanged so I can understand how to manipulate rasters with PyQGIS 3. The most complete I found was the answer from root676 here, but I couldn't execute the script.
So I would like guidance on how to set up a simple script for input and output of raster files, without using native QGIS or GDAL tools, to not pre-define the output file name.
EDIT:
When I run the script mentioned, I get:
The following layers were not correctly generated.
You can check the 'Log Messages Panel' in QGIS main window to find more information about the execution of the algorithm.
- C:/Users/cs279069/AppData/Local/Temp/processing_26353d6a350741f99b38886692ba0306/35605f7cacd647be810cbfc73ee98186/OUTPUT_RASTER_A.tif
- C:/Users/cs279069/AppData/Local/Temp/processing_26353d6a350741f99b38886692ba0306/d89846f8fbb8400da1e7891ff94270f0/OUTPUT_RASTER_B.tif
The Log Messages Panel is empty. Probably because there is no calculation on it.
Clarifying the question:
The input raster can be any raster of any size, because I'll use this in several different scripts, just to rename the output file. When I create some script, I use the native tools of QGIS, and that generaty an output with the tool predefined name. Like "Reprojected", "Clipped (mask)".
So basically I need something like this: OUTPUT_RASTER = INPUT_RASTER * 1
So the output will be identical from the input and will have the display name that was defined in the def initAlgorithm
section.
More info:
I´m trying to run this code.
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterRasterLayer(
self.INPUT_RASTER,
self.tr("Input Raster"), None, False))
self.addParameter(QgsProcessingParameterRasterDestination(
self.OUTPUT_RASTER,
self.tr("Output Raster"),
None, False))
def processAlgorithm(self, parameters, context, feedback):
input_raster = self.parameterAsRasterLayer(parameters, self.INPUT_RASTER, context)
output_raster = self.parameterAsOutputLayer(parameters, self.OUTPUT_RASTER, context)
output_raster = input_raster
results = {}
results[self.OUTPUT_RASTER] = output_raster
return results
That´s the error given:
The following layers were not correctly generated.
You can check the 'Log Messages Panel' in QGIS main window to find more information about the execution of the algorithm.
- C:/Users/cs279069/AppData/Local/Temp/processing_779dd8aa0c284112b878829e6b56c348/4bacded9efb04c6c8c9502e6572f5c1d/OUTPUT_RASTER.tif