4

My first processing runalg creates a memory layer as output. I need to use this layer as the input for the second runalg.

#first
processing.run("qgis:fieldcalculator", {
    'INPUT': 'test_1_f08f5cd1_13ea_445b_9778_6ee0ab919030',
    'FIELD_NAME': '1.3-field',
    'FIELD_TYPE': 0,
    'FIELD_LENGTH': 10,
    'FIELD_PRECISION': 3,
    'NEW_FIELD': True,
    'FORMULA': '((length(shortest_line(centroid($geometry),boundary($geometry)))))*1.3',
    'OUTPUT': 'memory:'
    })

#second processing.run("qgis:fieldcalculator", { 'INPUT':?????, 'FIELD_NAME': '1.3-field', 'FIELD_TYPE': 0, 'FIELD_LENGTH': 10, 'FIELD_PRECISION': 3, 'NEW_FIELD': True, 'FORMULA': '((length(shortest_line(centroid($geometry),boundary($geometry)))))*1.3', 'OUTPUT': 'memory:' })

I have found this links but none could help me.

Taras
  • 32,823
  • 4
  • 66
  • 137
Kajo
  • 691
  • 1
  • 6
  • 11

1 Answers1

0

I have chained processing algorithms within a processing script by adding the output of the first algorithm to a sink (see underdark's tutorial) then using dest_id1 (for example) as the input for the next processing script. I found that it was necessary to add the line del sink between uses of the sink and to declare OUTPUT1 = "OUTPUT_1" and OUTPUT2 = "OUTPUT_2" at the start of the script and the syntax at the end that worked for me was:

results = {}
results[self.OUTPUT1] = dest_id1
results[self.OUTPUT2] = dest_id2
return results

All other syntax to do with outputs has to be duplicated.

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Andrew
  • 67
  • 5