1

I created a model in the graphical modeler and I want to run that model always with two specific polygon shapefiles from my project, e.g. pst and astenot. Whenever I run my model, it asks me to set the inputs from the list of shapefiles that are in my MapCanvas. To be more specific, I always want vectorlayer_1='pst' and vectorlayer_2='astenot'.

This is the script from my model. Can anyone tell me how I can do that? I'm wondering if there is a way to do that directly in graphical modeler.

##difference_between_pst/astenot=name
##vectorlayer_1=vector
##vectorlayer_2=vector
##output_alg0=output vector
##output_alg1=output vector
##output_layer_alg2=output vector
##output_layer_alg3=output vector
outputs_0=Processing.runalg("qgis:difference", vectorlayer_1, vectorlayer_2, output_alg0)
outputs_1=Processing.runalg("qgis:difference", vectorlayer_2, vectorlayer_1, output_alg1)
outputs_2=Processing.runalg("qgis:saveselectedfeatures", outputs_0['OUTPUT'], output_layer_alg2)
outputs_3=Processing.runalg("qgis:saveselectedfeatures", outputs_1['OUTPUT'], output_layer_alg3)
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
elena
  • 11
  • 3

1 Answers1

2

Change you script in:

##difference_between_pst/astenot=name
##output_alg0=output vector
##output_alg1=output vector
##output_layer_alg2=output vector
##output_layer_alg3=output vector
vectorlayer_1 = "pst"
vectorlayer_2 = "astenot"
outputs_0=Processing.runalg("qgis:difference", vectorlayer_1, vectorlayer_2,   output_alg0)
outputs_1=Processing.runalg("qgis:difference", vectorlayer_2, vectorlayer_1,  output_alg1)
outputs_2=Processing.runalg("qgis:saveselectedfeatures", outputs_0['OUTPUT'], output_layer_alg2)
outputs_3=Processing.runalg("qgis:saveselectedfeatures", outputs_1['OUTPUT'], output_layer_alg3)

enter image description here

gene
  • 54,868
  • 3
  • 110
  • 187
  • It came up with an error :name 'Processing' is not defined. – elena Nov 28 '13 at 06:12
  • 1
    In QGIS 2.0, it is processing, in QGIS master, it is Processing – gene Nov 28 '13 at 17:38
  • After changing Processing with processing, another error came up : name 'vectorlayer_1' is not defined. – elena Nov 29 '13 at 06:38
  • I found this :map = QgsMapCanavs() ,
    layer = QgsVectoryLayer('path.shp','myshapefile','ogr'), map.setLayerSet([layer]), to create a script that opens a layer in a map canvas (http://gis.stackexchange.com/questions/29580/how-to-run-a-simple-python-script-for-qgis-from-outside-e-g-sublime-text). But i don't know how to use it in the code. It would be helpful if you have any idea. Thanks for your help anyway!
    – elena Nov 29 '13 at 08:05
  • Maybe it's working only from python console and not from script editor? – elena Nov 29 '13 at 08:10
  • Sorry, no problem for me – gene Nov 29 '13 at 23:13
  • I found what's missing!@gene Your changes in the script were absolutely right. It additionally wants: ##vectorlayer_1=input vector, ##vectorlayer_2=input vector, and the script run perfectly. But for some reason after the changes, I can’t see it in user scripts (Processing Toolbox, it is saved in the same correct folder). Do you have any idea about that? – elena Dec 06 '13 at 09:57