I am building an algorithm in the processing modeler which takes a csv file as input and creates a number of vector layers as output. I would like to automatically save these layers in the same folder as the project file. As I understand, it should be possible by entering the path "./filename.shp".
I can set the default save path for each layer in the final "Object Sink Parameter-definition" box in the modeler, but can't get this to work with a relative path.
When setting absolute path, everything works: C:/Users/Rasmus/Desktop/testfilQgis/målepunkter.shp
When setting only filename (felt.shp), the filename is added to the modelers default output directory path and saved to this path. When running the model on other computers, it will look for the local directory on my machine.
If I use a relative path (./koter.shp) that whole path will be added to the default output directory path (and break since the . folder doesn't exist).
Only the one folder up path seems to be accepted, but returns a "Failed to create: Permission denied".
See below image for the suggested save paths based on these inputs:
default save paths as suggested with above inputs
I've looked into using the project_folder as suggested here, but the "object sink parameter-definition" box only takes a path, so I'm not sure how to do that.
And setting the save path manually for each layer every time seems like defying the purpose of building a model.
Is it possible to suggest a relative save path?
project > properties > save paths is set to relative (default).
3 Answers 3
First, create the entire process within the modeler, and include the input "File/Folder". Image1
Then open it with the inbuilt Python editor in QGIS, then edit any code with the file path to the name of the input.
In my example, I have defined the folder as "folderlocation", given it a path. This is the only place you will need to change the folder path each time.Image2
You can see the output points to the folder location in the second red box.
building on Sanch's answer: Another (possible new) option is to also add the "set project variable
" algorithm in the graphical model (together with the "file/folder
" input). Give the variable a name and set the value to the "file/folder
" model input.
For your models output select pre-calculated value and enter @variable_name '||' filename.gpkg
. Only downside to this approach is that the created files aren't automatically added to your QGIS project.
If you want to save all output files to the same folder in the project directory you can enter the expression @project_home || '//output'
as output directory in an algorithm.
The folder "output" gets created in the project folder and will contain all the new layers.
Create output folder in graphical modeler
If you have several independant layers as output you can use the same approach. The example below extracts two layers based on text in the "NAME" field. They are saved to the project directory as .gpkg
and loaded directly into qgis.
Explore related questions
See similar questions with these tags.