I have a simple QGIS plugin and I use processing algorithms from my models.
Now I want to load my export from processing in my QGIS project that I do easy with runandload
but I can't to define name that show me an default name how to load memory layer with my name?
outputs_QGISFIELDCALCULATOR_4=processing.runandload('qgis:fieldcalculator', outputs_QGISFIELDCALCULATOR_3['OUTPUT_LAYER'],'newnew',2,50.0,0.0,True,'left(\"TOP_KOIN\", strpos(\"TOP_KOIN\" ,\' \')-1)',"memeory:layer")
And if I need that memory layer to continue my script for example to do something else how to take ?with memory name? or like this outputs_QGISFIELDCALCULATOR_4
?
update
if result:
selectedLayerIndex = self.dlg.comboBox.currentIndex()
selectedLayer = layers[selectedLayerIndex]
print selectedLayer
#calc='C:/Users/saran/Desktop/qq/calc.shp'
outputs_QGISFIELDCALCULATOR_1=processing.runalg('qgis:fieldcalculator', selectedLayer,'trid',1,10.0,0.0,True,'$id',None)
load_it1 = QgsVectorLayer(outputs_QGISFIELDCALCULATOR_1['OUTPUT_LAYER'], 'tid', 'ogr')
outputs_QGISFIELDCALCULATOR_2=processing.runalg('qgis:fieldcalculator', outputs_QGISFIELDCALCULATOR_1['OUTPUT_LAYER'],'area',0,10.0,3.0,True,'$area',None)
load_it2 = QgsVectorLayer(outputs_QGISFIELDCALCULATOR_2['OUTPUT_LAYER'], 'area', 'ogr')
outputs_QGISFIELDCALCULATOR_3=processing.runalg('qgis:fieldcalculator', outputs_QGISFIELDCALCULATOR_2['OUTPUT_LAYER'],'perimetre',0,10.0,3.0,True,'$perimeter',None)
load_it3 = QgsVectorLayer(outputs_QGISFIELDCALCULATOR_3['OUTPUT_LAYER'], 'perimetre', 'ogr')
outputs_QGISFIELDCALCULATOR_4=processing.runandload('qgis:fieldcalculator', outputs_QGISFIELDCALCULATOR_3['OUTPUT_LAYER'],'newnew',2,50.0,0.0,True,'left(\"TOP_KOIN\", strpos(\"TOP_KOIN\" ,\' \')-1)',None)
load_it4 = QgsVectorLayer(outputs_QGISFIELDCALCULATOR_4['OUTPUT_LAYER'], 'new', 'ogr')
QgsMapLayerRegistry.instance().addMapLayer(load_it1)
QgsMapLayerRegistry.instance().addMapLayer(load_it2)
QgsMapLayerRegistry.instance().addMapLayer(load_it3)
QgsMapLayerRegistry.instance().addMapLayer(load_it4)
my_output1 = processing.getObject(outputs_QGISFIELDCALCULATOR_1['OUTPUT_LAYER'])
my_output2 = processing.getObject(outputs_QGISFIELDCALCULATOR_2['OUTPUT_LAYER'])
my_output3 = processing.getObject(outputs_QGISFIELDCALCULATOR_3['OUTPUT_LAYER'])
my_output4 = processing.getObject(outputs_QGISFIELDCALCULATOR_4['OUTPUT_LAYER'])
Best Answer
You may continue using the memory layer by loading it as an object. Before doing this, you need to know how the output from the algorithm is called, so typing these lines in the Python Console:
you will see that the output's name is
OUTPUT_LAYER
:This means that you will be able to use it if you add a new variable and call it in this way:
By now, you are ready to do something with it.
EDIT
From a more general point of view, I would use this code for accomplish both the tasks described in the question: