1

I create a plugin in QGIS using some algorithms from Processing. When I try to use one algorithm in two different outputs, the variable is not well called and I do not know why.

First call:

Processing.initialize()

params_ndvi = {
'INPUT': str(self.dlg.lineEdit.text()),
'POLYGONS': vl,
'OUTPUT': 'TEMPORARY_OUTPUT'}
feedback1 = QgsProcessingFeedback()
clip_ndvi = Processing.runAlgorithm("saga:cliprasterwithpolygon", params_ndvi, feedback=feedback1)
out_ndvi = clip_ndvi['OUTPUT']

Second call:

params_class_image = {
'INPUT': str(self.dlg.lineEdit_2.text()),
'POLYGONS': vl,
'OUTPUT': 'TEMPORARY_OUTPUT'}
feedback2 = QgsProcessingFeedback()
clip_classified = Processing.runAlgorithm("saga:cliprasterwithpolygon", params_ndvi, feedback=feedback2)
out_classified = clip_classified['OUTPUT']

In this third call, I want to run with the second call output as input but in the final result, in temporary files, the algorithm gives me the report of the first call. I do not know why because the input is well defined:

params_raster = {
'INPUT': str(out_classified),
'BAND': 1, 'OUTPUT_HTML_FILE': 'TEMPORARY_OUTPUT'}
feedback3 = QgsProcessingFeedback()
raster_class = Processing.runAlgorithm("native:rasterlayeruniquevaluesreport", params_raster, feedback=feedback3)
params = raster_class['OUTPUT']

1 Answer 1

1

I find the error. If it can be useful to someone.

Instead of feedback, I just replaced by QgsProcessing.TEMPORARY_OUTPUT in the OUTPUT parameter.

Also in

params_raster = {
'INPUT': str(out_classified),
'BAND': 1, 'OUTPUT_HTML_FILE': 'TEMPORARY_OUTPUT'}
feedback3 = QgsProcessingFeedback()
raster_class = Processing.runAlgorithm("native:rasterlayeruniquevaluesreport", params_raster, feedback=feedback3)
params = raster_class['OUTPUT']

The output must be correctly called as:

params_raster = {
    'INPUT': str(out_classified),
    'BAND': 1, 'OUTPUT_HTML_FILE': 'TEMPORARY_OUTPUT'}
    feedback3 = QgsProcessingFeedback()
    raster_class = Processing.runAlgorithm("native:rasterlayeruniquevaluesreport", params_raster, feedback=feedback3)
    params = raster_class['OUTPUT_HTML_FILE']

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.