8

I need to use the input filename in the output filename in a QGIS model. I have spent a couple of hours trying to find a solution but can't.

Qgis model

If the input is contourXY.tab and I want output to be \refactored\contourXY_refactored.tab and \refactored\contour_5m\contourXY_refactored_5m.tab

This is easy in ArcGIS modeler (see here) but I need a QGIS process OR is this python solution the only option?

Jochen Schwarze
15k8 gold badges56 silver badges124 bronze badges
asked Nov 17, 2015 at 1:29

1 Answer 1

4

I think you should consider a new approach: not defining the output name inside the model (even if you think now that it will always be related to the input) if not using batch mode. This allows you to be flexible on the definition of the output name and use the Input name or use a new one if you need to. It is quite easy to give the output the name of the Input layer. User this code in the output:

'C:/Users/user/Desktop/' || @layer || '_new' || '.gpkg'

This will automatically replace that @layer for the object called @layer within the model (see screenshots). Just find how the object is called within the model and substitute it keeping the @ before.

Here are some screepshots of the process:

Layer with different names and a simple model that do some calculation. enter image description here

Execute your model in batch mode and, instead of select each output name, go to 'calculate by expression' and use the above structure: enter image description here

After writting yours correctly, the output names are going to be filled using the input (@layer) name: enter image description here

answered Jan 9, 2020 at 13:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.