For several tasks in QGIS 3.4 I need a python script. As I am not used to use python I created the script with the graphical modeler (I modeled the tasks in the graphical modeler and exported the python script). The first part of the script is basically
- an object-filter to choose all points with a common attribute of a point layer
- create a heatmap with all the points choosen with the object-filter
When I start the model from the graphical modeler it works as it should. But after exporting the python script and start this from the processing toolbox, it gaves a "KeyError", that the output of the object-filter is not specified.
The first two algorithms in the python script are as follow:
from qgis.core import QgsProcessing
from qgis.core import QgsProcessingAlgorithm
from qgis.core import QgsProcessingMultiStepFeedback
from qgis.core import QgsProcessingParameterVectorLayer
import processing
class Automatisierung_20190527(QgsProcessingAlgorithm):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterVectorLayer('punkte', 'punkte', types=[QgsProcessing.TypeVectorPoint], defaultValue=None))
def processAlgorithm(self, parameters, context, model_feedback):
# Use a multi-step feedback, so that individual child algorithm progress reports are adjusted for the
# overall progress through the model
feedback = QgsProcessingMultiStepFeedback(8, model_feedback)
results = {}
outputs = {}
# Objektfilter
alg_params = {
'INPUT': parameters['punkte'],
'OUTPUT_gefiltert_1990': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['Objektfilter'] = processing.run('native:filter', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(1)
if feedback.isCanceled():
return {}
# Heatmap (Kerndichtenschätzung)
alg_params = {
'DECAY': 0,
'INPUT': outputs['Objektfilter']['OUTPUT_gefiltert_1990'],
'KERNEL': 0,
'OUTPUT_VALUE': 0,
'PIXEL_SIZE': 100,
'RADIUS': 15000,
'RADIUS_FIELD': None,
'WEIGHT_FIELD': None,
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
}
outputs['HeatmapKerndichtenschtzung'] = processing.run('qgis:heatmapkerneldensityestimation', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
feedback.setCurrentStep(2)
if feedback.isCanceled():
return {}
The error message says the following:
Results: {}
Traceback (most recent call last):
File "<string>", line 34, in processAlgorithm
KeyError: 'OUTPUT_gefiltert_1990'
Can somebody help me with fixing that error?