I have a Python script that I have exported from a QGIS model and I want to specify the layer it creates as output.

If defaultValue=None it outputs 'Reportpmbc': 'Centroids_9c779c9c_4bcc_471b_971e_fbea3bb27c7d', in the log window and a 'Centroids' layer is created in the project.

I want it to create a temporary layer 'Report-PMBC' as below but it won't run. (“.” files are not supported as outputs for this algorithm)

What am I missing in the statement below? I think I have to create a temporary layer in memory and write to it but I am not sure how to do that.

 self.addParameter(QgsProcessingParameterFeatureSink('Reportpmbc', 'Report-PMBC', type=QgsProcessing.TypeVectorPoint, createByDefault=True, defaultValue='Report-PMBC'))

1 Answer 1


Create the variable Report-PMBC in your algorithm like this:

class YourAlg(QgsProcessingAlgorithm):
    Report_PMBC = 'Report-PMBC'

Add the parameter like this in you initAlgorithm method:

  • Thanks but that doesn't appear to quite have it. Please see below; Traceback (most recent call last): File "<string>", line 397, in processAlgorithm KeyError: 'Reportpmbc' Execution failed after 10.94 seconds
    – Mikeoramma
    Jun 26, 2019 at 14:50
  • Take a look at my edit. Tell me if you did like that.
    – lcoandrade
    Jun 28, 2019 at 3:54
  • self.addParameter(QgsProcessingParameterFeatureSink(self.Report-PMBC,'Report-PMBC',QgsProcessing.TypeVectorPoint))
    – Mikeoramma
    Jun 28, 2019 at 19:11
  • Traceback (most recent call last): File "C:/PROGRA~1/QGIS3~1.8/apps/qgis/./python/plugins\processing\script\ScriptEditorDialog.py", line 224, in runAlgorithm exec(self.editor.text(), _locals) File "<string>", line 10 def initAlgorithm(self, config=None): ^ IndentationError: unexpected indent
    – Mikeoramma
    Jun 28, 2019 at 19:15
  • I added the two rows as you suggested and it returned the error in the third comment above. The second row you suggested is just under the line 10 it seems to be blowing up on.
    – Mikeoramma
    Jun 28, 2019 at 19:17

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.