6

I have a simple graphical model that uses a Field calculator to build a URL by concatenating strings in 3 fields of its input layer. This URL should be fed into the Download File algorithm using the Pre-calculated Value parameter.

For reproducibility, a valid download URL is:

https://pkgstore.datahub.io/core/geo-countries/countries/archive/23f420f929e0e09c39d916b8aaa166fb/countries.geojson

How do I use an expression in the Download File algorithm (Pre-calculated Value) to query the Field Calculator output?

Normally, on a map layer, to get the content of the url field of the feature with id = 1, I would use:

attribute(get_feature_by_id('layer_name', 1), 'url') 

In the expression builder there is a variable called @Field_calculator_OUTPUT, however substituting this for the layer name does not work:

attribute(get_feature_by_id( @Field_calculator_OUTPUT, 1), 'url') 

enter image description here

The following error is thrown whereby there is no URL argument given:

Running Download file [3/3] Input Parameters: { DATA: '', METHOD: 0, OUTPUT: 'D:\\OneDrive\\geodata\\countries.geojson', URL: None } No URL specified Error encountered while running Download file Execution failed after 0.18 seconds 

I know that the URL is valid, I have tested it with the Download File tool outside the Graphical Modeller

I have tried using 'Calculated' for the layer name in the expression and also using the Rename Layer algorithm and using the new layer name in the expression. I have also set the Field Calculator as a dependency of Download File.

I cannot get the expression to recognise the output of the Field calculator as a layer. The expression works if the layer is already present in the layer tree.

There is some degree of recognition of the layer because entering @Field_calculator_OUTPUT in the expression makes a link between the two algorithms.

enter image description here

10
  • You cannot reference a temporary output within modeler, see github.com/qgis/QGIS/issues/30397#issuecomment-505699624 Commented Jan 30, 2022 at 15:01
  • I feared as much, thanks for investigating. Hopefully, given the recent discussion a fix will be applied soon. Commented Jan 30, 2022 at 15:14
  • @MrXsquared what about refering the initial (input) layer, thus not a temporary one, and concatenate the fields in the Download file dialog? Commented Jan 30, 2022 at 15:30
  • 1
    Using the field calculator and download file was more of a proof of concept for accessing a field calculator result, it was just an easy way to frame a question. I was attempting a slightly different use case but using the same principle. The important part was using an expression to reference a field calculation that was performed inside the model. Commented Jan 30, 2022 at 17:13
  • 1
    Not without breaking the model into two. The Download File algorithm will not pick it up until it is present in the layer tree. Which either means having separate models for the calculation and downloading the file, or running the model twice, the first time with an error, so that the Download File recognises the output as a map layer. Neither of which are particularly favourable. It should just be an intermediate step in the overall model. This is why I generally stick to scripts and not models. Commented Jan 31, 2022 at 17:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.