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.

4
  • 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, 2015 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 :( Jul 11, 2015 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, 2015 at 9:09
  • 1
    Cool - Thanks Joseph, I will give that a try. I was unaware that older versions were accessible. Jul 13, 2015 at 22:57

1 Answer 1

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

5
  • Can it be used with files from a database? (instead of shapefiles)
    – Skye
    Jun 15, 2018 at 8:23
  • @Skye - Yes it should still work :)
    – Joseph
    Jun 15, 2018 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..
    – nilsnolde
    Mar 10, 2020 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, 2020 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!
    – nilsnolde
    Mar 18, 2020 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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