1

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'))
0

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:

self.addParameter(QgsProcessingParameterFeatureSink(
            self.Report-PMBC,
            'Report-PMBC',
            QgsProcessing.TypeVectorPoint))
  • 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 at 14:50
  • Take a look at my edit. Tell me if you did like that. – lcoandrade Jun 28 at 3:54
  • class BcPolygonReport(QgsProcessingAlgorithm):Report_PMBC = 'Report-PMBC' – Mikeoramma Jun 28 at 19:10
  • self.addParameter(QgsProcessingParameterFeatureSink(self.Report-PMBC,'Report-PMBC',QgsProcessing.TypeVectorPoint)) – Mikeoramma Jun 28 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 at 19:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.