0

I have troubles running a Graphical Modeler Script as standalone via the OSGeo4W Shell console. Everything works fine when I run the script in QGIS. When I open it via shell, nothing happens. I think the problem comes from the fact that the Erneuerungsplanung(QgsProcessingAlgorithm) is not executed properly.

This is my Script:

import sys
from qgis.core import (
QgsProject,
QgsApplication,
QgsProcessingAlgorithm,
QgsProcessing, 
QgsProcessingMultiStepFeedback,
QgsProcessingParameterFeatureSink,
QgsCoordinateReferenceSystem,
QgsProcessingFeedback,
QgsProcessingOutputLayerDefinition,
QgsProcessingContext,
)
QgsApplication.setPrefixPath("C:\OSGeo4W64\apps\qgis\python\qgis", True)
qgs = QgsApplication([], False)
qgs.initQgis()

from qgis.analysis import QgsNativeAlgorithms
sys.path.append(r'C:\OSGeo4W64\apps\qgis\python\plugins')
import processing

from processing.core.Processing import Processing
Processing.initialize()
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())

class Erneuerungsplanung(QgsProcessingAlgorithm):
    def initAlgorithm(self, config=None):
        self.addParameter(QgsProcessingParameterFeatureSink('Verschneidung', 'verschneidung', type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue=None))
        self.addParameter(QgsProcessingParameterFeatureSink('Sektoren2', 'Sektoren2', type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue=None))
        self.addParameter(QgsProcessingParameterFeatureSink('Pufferzone_gasleitung', 'Pufferzone_Gasleitung', type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue=None))
        self.addParameter(QgsProcessingParameterFeatureSink('Gl_sl_ns_gemeinsamer_austausch', 'GL_SL_NS_gemeinsamer_Austausch', type=QgsProcessing.TypeVectorAnyGeometry, createByDefault=True, defaultValue='TEMPORARY_OUTPUT'))

    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(44, model_feedback)
        results = {}
        outputs = {}

        # SL_MS_import
        alg_params = {
            'INPUT': 'path/.shp',
            'NAME': 'Stromkabel_MS'
        }
        outputs['Sl_ms_import'] = processing.run('native:loadlayer', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(1)
        if feedback.isCanceled():
            return {}

        # GL_import
        alg_params = {
            'INPUT': 'path/.shp',
            'NAME': 'GL_import'
        }
        outputs['Gl_import'] = processing.run('native:loadlayer', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(2)
        if feedback.isCanceled():
            return {}

        # SL_NS_import
        alg_params = {
            'INPUT': 'path/.shp',
            'NAME': 'Stromkabel_NS'
        }
        outputs['Sl_ns_import'] = processing.run('native:loadlayer', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(3)
        if feedback.isCanceled():
            return {}

        # GL_Sektor
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Sektor',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 2,
            'FORMULA': '\'Gas\'',
            'INPUT': outputs['Gl_import']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_sektor'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(4)
        if feedback.isCanceled():
            return {}

        # SL_MS_Sektor
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Sektor',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 2,
            'FORMULA': '\'MS\'',
            'INPUT': outputs['Sl_ms_import']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Sl_ms_sektor'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(5)
        if feedback.isCanceled():
            return {}

        # WL_import
        alg_params = {
            'INPUT': 'path/.shp',
            'NAME': 'Wärmeleitung'
        }
        outputs['Wl_import'] = processing.run('native:loadlayer', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(6)
        if feedback.isCanceled():
            return {}

        # SL_NS_Sektor
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Sektor',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 2,
            'FORMULA': '\'NS\'',
            'INPUT': outputs['Sl_ns_import']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Sl_ns_sektor'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(7)
        if feedback.isCanceled():
            return {}

        # SL_NS_Umwandlung_Datum_zu_Jahr
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Verlegejahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'year(Verlegedat)',
            'INPUT': outputs['Sl_ns_sektor']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Sl_ns_umwandlung_datum_zu_jahr'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(8)
        if feedback.isCanceled():
            return {}

        # SL_MS_Umwandlung_Datum_zu_Jahr
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Verlegejahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'year(ERFASST_AM)',
            'INPUT': outputs['Sl_ms_sektor']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Sl_ms_umwandlung_datum_zu_jahr'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(9)
        if feedback.isCanceled():
            return {}

        # WL_Sektor
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Sektor',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 2,
            'FORMULA': '\'WL\'',
            'INPUT': outputs['Wl_import']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Wl_sektor'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(10)
        if feedback.isCanceled():
            return {}

        # WL_Umwandlung_Datum_zu_Jahr
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Verlegejahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'year(JAHR)',
            'INPUT': outputs['Wl_sektor']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Wl_umwandlung_datum_zu_jahr'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(11)
        if feedback.isCanceled():
            return {}

        # GL_Umwandlung_Datum_zu_Jahr
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Verlegejahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'year(Verlegedat)\r\n',
            'INPUT': outputs['Gl_sektor']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_umwandlung_datum_zu_jahr'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(12)
        if feedback.isCanceled():
            return {}

        # WL_Austauschjahr
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Austauschjahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'Verlegejahr',
            'INPUT': outputs['Wl_umwandlung_datum_zu_jahr']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Wl_austauschjahr'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(13)
        if feedback.isCanceled():
            return {}

        # SL_MS_Austauschjahr
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Austauschjahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'Verlegejahr',
            'INPUT': outputs['Sl_ms_umwandlung_datum_zu_jahr']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Sl_ms_austauschjahr'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(14)
        if feedback.isCanceled():
            return {}

        # GL_Austauschjahr
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Austauschjahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'Verlegejahr',
            'INPUT': outputs['Gl_umwandlung_datum_zu_jahr']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_austauschjahr'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(15)
        if feedback.isCanceled():
            return {}

        # SL_NS_Austauschjahr
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Austauschjahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'Verlegejahr',
            'INPUT': outputs['Sl_ns_umwandlung_datum_zu_jahr']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Sl_ns_austauschjahr'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(16)
        if feedback.isCanceled():
            return {}

        # GL_Auswahl_Austauschjahr
        alg_params = {
            'FIELD': 'Austauschjahr',
            'INPUT': outputs['Gl_austauschjahr']['OUTPUT'],
            'METHOD': 0,
            'OPERATOR': 0,
            'VALUE': '1958'
        }
        outputs['Gl_auswahl_austauschjahr'] = processing.run('qgis:selectbyattribute', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(17)
        if feedback.isCanceled():
            return {}

        # GL_Auswahl_Austauschjahr_speichern
        alg_params = {
            'INPUT': outputs['Gl_auswahl_austauschjahr']['OUTPUT'],
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_auswahl_austauschjahr_speichern'] = processing.run('native:saveselectedfeatures', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(18)
        if feedback.isCanceled():
            return {}

        # GL_Sektoren_zusammenführen
        alg_params = {
            'CRS': 'ProjectCrs',
            'LAYERS': [outputs['Gl_austauschjahr']['OUTPUT'],outputs['Sl_ns_austauschjahr']['OUTPUT']],
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_sektoren_zusammenfhren'] = processing.run('native:mergevectorlayers', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(19)
        if feedback.isCanceled():
            return {}

        # GL_Pufferzone
        alg_params = {
            'DISSOLVE': False,
            'DISTANCE': 5,
            'END_CAP_STYLE': 1,
            'INPUT': outputs['Gl_auswahl_austauschjahr_speichern']['OUTPUT'],
            'JOIN_STYLE': 1,
            'MITER_LIMIT': 2,
            'SEGMENTS': 5,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_pufferzone'] = processing.run('native:buffer', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(20)
        if feedback.isCanceled():
            return {}

        # GL_Puffer_ID
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Puffer_ID',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'ID',
            'INPUT': outputs['Gl_pufferzone']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': parameters['Pufferzone_gasleitung']
        }
        outputs['Gl_puffer_id'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
        results['Pufferzone_gasleitung'] = outputs['Gl_puffer_id']['OUTPUT']

        feedback.setCurrentStep(21)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS
        alg_params = {
            'INPUT': outputs['Gl_sektoren_zusammenfhren']['OUTPUT'],
            'INPUT_FIELDS': None,
            'OVERLAY': outputs['Gl_puffer_id']['OUTPUT'],
            'OVERLAY_FIELDS': None,
            'OVERLAY_FIELDS_PREFIX': '',
            'OUTPUT': parameters['Verschneidung']
        }
        outputs['Gl_verschneidung_sl_ns'] = processing.run('native:intersection', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
        results['Verschneidung'] = outputs['Gl_verschneidung_sl_ns']['OUTPUT']

        feedback.setCurrentStep(22)
        if feedback.isCanceled():
            return {}

        # GL_SymDiff_SL_NS
        alg_params = {
            'INPUT': outputs['Gl_sektoren_zusammenfhren']['OUTPUT'],
            'OVERLAY': outputs['Gl_puffer_id']['OUTPUT'],
            'OVERLAY_FIELDS_PREFIX': '',
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_symdiff_sl_ns'] = processing.run('native:symmetricaldifference', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(23)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_länge
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Länge_geometry',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 0,
            'FORMULA': ' $length ',
            'INPUT': outputs['Gl_verschneidung_sl_ns']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_lnge'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(24)
        if feedback.isCanceled():
            return {}

        # GL_SymDiff_SL_NS_länge
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Länge_geometry',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 0,
            'FORMULA': '$length',
            'INPUT': outputs['Gl_symdiff_sl_ns']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_symdiff_sl_ns_lnge'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(25)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Startpkt
        alg_params = {
            'FIELD_LENGTH': 50,
            'FIELD_NAME': 'Startpkt',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 2,
            'FORMULA': '$x_at(0) || \'; \' || $y_at(0)',
            'INPUT': outputs['Gl_verschneidung_sl_ns_lnge']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_startpkt'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(26)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Endpkt
        alg_params = {
            'FIELD_LENGTH': 50,
            'FIELD_NAME': 'Endpkt',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 2,
            'FORMULA': '$x_at(-1) || \'; \' || $y_at(-1)',
            'INPUT': outputs['Gl_verschneidung_sl_ns_startpkt']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_endpkt'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(27)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_filter_länge
        alg_params = {
            'FIELD': 'Länge_geometry',
            'INPUT': outputs['Gl_verschneidung_sl_ns_endpkt']['OUTPUT'],
            'METHOD': 0,
            'OPERATOR': 3,
            'VALUE': '5'
        }
        outputs['Gl_verschneidung_sl_ns_filter_lnge'] = processing.run('qgis:selectbyattribute', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(28)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_filter_länge_speichern
        alg_params = {
            'INPUT': outputs['Gl_verschneidung_sl_ns_filter_lnge']['OUTPUT'],
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_filter_lnge_speichern'] = processing.run('native:saveselectedfeatures', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(29)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Austauschjahr_Differenz
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Differenz',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 3,
            'FORMULA': 'Austauschjahr - Austauschjahr_2',
            'INPUT': outputs['Gl_verschneidung_sl_ns_filter_lnge_speichern']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_austauschjahr_differenz'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(30)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_filter_länge_aussortiert
        alg_params = {
            'FIELD': 'Länge_geometry',
            'INPUT': outputs['Gl_verschneidung_sl_ns_endpkt']['OUTPUT'],
            'METHOD': 0,
            'OPERATOR': 4,
            'VALUE': '5'
        }
        outputs['Gl_verschneidung_sl_ns_filter_lnge_aussortiert'] = processing.run('qgis:selectbyattribute', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(31)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_filter_länge_aussortiert_speichern
        alg_params = {
            'INPUT': outputs['Gl_verschneidung_sl_ns_filter_lnge_aussortiert']['OUTPUT'],
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_filter_lnge_aussortiert_speichern'] = processing.run('native:saveselectedfeatures', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(32)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_filter_länge_aussortiert_speichern_länge
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Länge_geometry',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 0,
            'FORMULA': '$length',
            'INPUT': outputs['Gl_verschneidung_sl_ns_filter_lnge_aussortiert_speichern']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_filter_lnge_aussortiert_speichern_lnge'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(33)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Austauschjahr_filter_Differenz_1
        alg_params = {
            'FIELD': 'Differenz',
            'INPUT': outputs['Gl_verschneidung_sl_ns_austauschjahr_differenz']['OUTPUT'],
            'METHOD': 0,
            'OPERATOR': 5,
            'VALUE': '5'
        }
        outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_1'] = processing.run('qgis:selectbyattribute', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(34)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Austauschjahr_filter_Differenz_2
        alg_params = {
            'FIELD': 'Differenz',
            'INPUT': outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_1']['OUTPUT'],
            'METHOD': 3,
            'OPERATOR': 3,
            'VALUE': '0'
        }
        outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_2'] = processing.run('qgis:selectbyattribute', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(35)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Austauschjahr_filter_Differenz_speichern
        alg_params = {
            'INPUT': outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_2']['OUTPUT'],
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_speichern'] = processing.run('native:saveselectedfeatures', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(36)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Austauschjahr_filter_Differenz_1_aussortiert
        alg_params = {
            'FIELD': 'Differenz',
            'INPUT': outputs['Gl_verschneidung_sl_ns_austauschjahr_differenz']['OUTPUT'],
            'METHOD': 0,
            'OPERATOR': 2,
            'VALUE': '5'
        }
        outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_1_aussortiert'] = processing.run('qgis:selectbyattribute', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(37)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Austauschjahr_anpassen
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Austauschjahr',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 1,
            'FORMULA': 'Austauschjahr + 50',
            'INPUT': outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_speichern']['OUTPUT'],
            'NEW_FIELD': False,
            'OUTPUT': parameters['Gl_sl_ns_gemeinsamer_austausch']
        }
        outputs['Gl_verschneidung_sl_ns_austauschjahr_anpassen'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
        results['Gl_sl_ns_gemeinsamer_austausch'] = outputs['Gl_verschneidung_sl_ns_austauschjahr_anpassen']['OUTPUT']

        feedback.setCurrentStep(38)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Austauschjahr_filter_Differenz_aussortiert_speichern
        alg_params = {
            'INPUT': outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_1_aussortiert']['OUTPUT'],
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_aussortiert_speichern'] = processing.run('native:saveselectedfeatures', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        feedback.setCurrentStep(39)
        if feedback.isCanceled():
            return {}

        # GL_Verschneidung_SL_NS_Austauschjahr_filter_Differenz_aussortiert_speichern_länge
        alg_params = {
            'FIELD_LENGTH': 10,
            'FIELD_NAME': 'Länge_geometry',
            'FIELD_PRECISION': 3,
            'FIELD_TYPE': 0,
            'FORMULA': '$length',
            'INPUT': outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_aussortiert_speichern']['OUTPUT'],
            'NEW_FIELD': True,
            'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT
        }
        outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_aussortiert_speichern_lnge'] = processing.run('qgis:fieldcalculator', alg_params, context=context, feedback=feedback, is_child_algorithm=True)

        # GL_Sektoren2_zusammenführen
        alg_params = {
            'CRS': QgsCoordinateReferenceSystem('EPSG:32632'),
            'LAYERS': [outputs['Gl_symdiff_sl_ns_lnge']['OUTPUT'],outputs['Gl_verschneidung_sl_ns_austauschjahr_anpassen']['OUTPUT'],outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_2_aussortiert_speichern_lnge']['OUTPUT'],outputs['Gl_verschneidung_sl_ns_austauschjahr_filter_differenz_aussortiert_speichern_lnge']['OUTPUT'],outputs['Gl_verschneidung_sl_ns_filter_lnge_aussortiert_speichern_lnge']['OUTPUT']],
            'OUTPUT': parameters['Sektoren2']
        }
        outputs['Gl_sektoren2_zusammenfhren'] = processing.run('native:mergevectorlayers', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
        results['Sektoren2'] = outputs['Gl_sektoren2_zusammenfhren']['OUTPUT']
        return results

    def name(self):
        return 'Erneuerungsplanung'

    def displayName(self):
        return 'Erneuerungsplanung'

    def group(self):
        return ''

    def groupId(self):
        return ''
qgs.exitQgis()

When I run this script, no output is generated, even if I specify a defaultValue= like (.../Test/Testnet/GL.shp') at Line: 38: self.addParameter to permanently save the layer.

I've already added the following code to the end of my script from this question and the subsequent solution::[https://gis.stackexchange.com/questions/333580/running-standalone-qgis-model-script-in-python][1]

Erneuerungsplanung = Erneuerungsplanung()
feedback = QgsProcessingFeedback()
context = QgsProcessingContext()
parameters = {} 
Erneuerungsplanung.initAlgorithm()
Erneuerungsplanung.processAlgorithm(parameters, context, feedback)

but then I get the following error:

Traceback (most recent call last):
  File "oeffnen4.py", line 813, in <module>
    Erneuerungsplanung.processAlgorithm(parameters, context, feedback)
  File "oeffnen4.py", line 362, in processAlgorithm
    'OUTPUT': parameters['Pufferzone_gasleitung']
KeyError: 'Pufferzone_gasleitung'

I think that I have forgotten a fundamental part in the code and therefore it is not executed or only with errors. I have only recently started to get involved with Python and QGIS and would greatly value an eye-opening answer.

Kind regards Bernd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.