6

I believe that the answer to my question is 'no' but am hoping that I missed something in my Googling and trawling of StackExchange... I have a simple Graphical Model built in QGIS (2.12) that asks the user to specify a 'Site' string input which will be used to find a matching feature in a shapefile (e.g. 'Dartmoor' or 'Sussex'). A number of operations are then performed to create a buffer around urbanised areas falling inside the site, and the result is then added as a new layer to QGIS.

What I am trying to figure out is if there is any way to have the name of the new layer added to QGIS be 'informed' by the Site specified by the user. Right now, everything gets added with the same name (e.g. 'Urban Buffer') but it would be mighty handy if the output were automatically renamed to 'Dartmoor Urban Buffer' or 'Sussex Urban Buffer' by the model since that would prevent confusion if the user wants to create multiple buffers one after another.

Is there any way to parameterise the at the end of the model so that it uses the Input string as part of its name?

I've attached a screen grab just to show where the string is coming from (how it's named) and what the last dialogue box is offering. There's no point including the details of the rest of the model since it's only the first input and last output that I'm trying to 'connect' in some way by sprinkling some syntactic sugar in the Buffer spec.

Screenshot of Model

4

I think the only way to this through the GUI of the modeler is to run the model as batch process. However, this method only adds the name at the end of the shapefile, not at the beginning. You can do this by right-clicking your model:

Batch process

I created an example model with:

  • Site Name = Vector Layer
  • Site = String

Then when running the model as a batch, choose a layer for the Site Name (in my case, "polygon example") and enter the Site. Once done, click on the Results button with the ellipsis (highlighted in red):

Set parameters

Select the directory in which to save your shapefiles and enter Urban Buffer_:

Output name

Once you click Save, you will be prompted with the Autofill settings:

Autofill parameters

And set:

  • "Autofill mode" to Fill with parameter values
  • "Parameter to use" to Site

Setting autofill settings

Once confirmed, you should see the output file with the Site string at the end:

Output with autofill


The only other method I think is to create a custom script (which involves writing out your model in Python) and editing the output to include the Site string before "Urban Buffers". This would involve a little more work but there is an option to save your model as a Python script. However, I noticed there are some issues with this as I receive errors when running a script which was saved from a working model.

  • 1
    Interesting -- that's close enough for most of what I'm trying to do. I had also thought about the custom script idea, but the overhead of transferring the model to a Python script seems... substantial. Might suggest this kind of parameterisation to the QGIS team -- I might be alone in wanting to do this, but I suspect not. – JonR Mar 8 '16 at 18:58
  • 1
    @JonR - Depening on the model, it doesn't need to be a substantial amount of work but it helps if you have a general idea on how the processing scripts work and how to create them. There is documentation which helps describe the process =) – Joseph Mar 9 '16 at 9:28

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.