5

I have a model in QGIS where there are two vector layers that remain the same everytime I execute a model.

Is there a way that I can configure my model so that these layers don't require the user to "input" them. Ideally I could point to their location in my model file and not need the user to even know about them. Maybe you can do this already but I can't find the tool I need in the processing toolbox.

  • Not sure if this is possible through the QGIS modeler but you can certainly do this through a script. Which QGIS version are you using? Version 2.2 of the Processing plugin version (the earliest one) had a very useful feature of saving models as a Python script. This feature hasn't appeared in the recent versions unfortunately. – Joseph Jul 10 '15 at 10:51
  • Using QGIS version 2.10. I seen some articles mentioning the export to python script that you mentioned, but can't seem to do it in QGIS 2.10. I had thought of editing it as a script but I can't get it out to one :( – Andrew Jeffrey Jul 11 '15 at 0:52
  • If you're still interested, you could download the early Processing version from here and move it to the directory of the .qgis2 folder (in my case using Windows: C:\Users\Me\.qgis2\python\plugins ). You can just move the folders instead of overwriting them (i.e. keep one folder on the Desktop) as I, personally, tend to switch between versions. Note that some tools might not be available in the other version. – Joseph Jul 13 '15 at 9:09
  • 1
    Cool - Thanks Joseph, I will give that a try. I was unaware that older versions were accessible. – Andrew Jeffrey Jul 13 '15 at 22:57
3

Quite a late answer but instead of using a Vector layer input in your modeler, you can instead create two custom scripts and add the paths of your layers into each script. To create such a script, go to:

Processing Toolbox > Scripts > Tools > Create new script

Then use similar code below.

First script:

##layer_1=name
##output=output vector
output = "C:/Users/You/Desktop/layer_1.shp"

Second script:

##layer_2=name
##output=output vector
output = "C:/Users/You/Desktop/layer_2.shp"

Make sure the scripts are saved in:

/.qgis2/processing/scripts/

If you run the scripts individually, they will simply load the layer into the interface.


Then add them to your model:

Model

| improve this answer | |
  • Can it be used with files from a database? (instead of shapefiles) – Skye Jun 15 '18 at 8:23
  • @Skye - Yes it should still work :) – Joseph Jun 15 '18 at 9:08
  • Hi @Joseph, I never came across that script notation. Is it documented somewhere? Specifically I'd like to know if there's a way to let a similar script take some input from a another algo in a model? I can't find a way by trial & error.. – nnolde Mar 10 at 3:54
  • Hi @nnolde, this script notation is for QGIS 2 and not used in QGIS 3. Either way, I would suggest you ask this as a new question. – Joseph Mar 16 at 15:35
  • 1
    Thanks @Joseph! I actually did: gis.stackexchange.com/questions/353519/…. If you have an idea, I'd appreciate it. All the best and heatlh! – nnolde Mar 18 at 7:39

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.