2

I am trying to develop a process with the model builder in QGIS (3.38) where the process loads a CSV file as vector features, for the ability to go over each combination at a row level. The later part of the algorithm uses the row i.e. feature to get the WFS layer and save it to SQL.

The csv file has a name and id, amongst which id is used in the get WFS step. I am after the ability to refer to the current feature in the iteration. I've tried the @id, and @feature variables available with the precalculated value, without any result.

I could access the field if I use an absolute number against the id rather than using @id or use $current_feature directly:

concat(@var_TypeNameHeader, to_string(attribute(get_feature_by_id(@select_layers_table, 1), @layer_id_field)))

Example like this one - Iterate Graphical Model over a set of numbers in a non geometric layer

The solutions on SE are mostly diverging to the Python side and I am looking for solutions within graphic modeler inputs or algorithms.

Taras
35.7k5 gold badges77 silver badges151 bronze badges
asked Sep 11, 2024 at 22:17
1

1 Answer 1

0

The following solution will also work in the modeler when needing to iterate over features of a layer using an algorithm that only takes a hard-coded value (and does not accept a field or calculated value when used in stand alone).

This works by using the green "iterate over this layer" button on the input field when running the model

In your model:

  1. Use field calculator on your input layer:
  • add a new field (I call it "id_1")
  • integer
  • field length of 1
  • value of 1
  1. Access the current feature by calling the result of the field calculator step:

    get_feature( @Field_calculator_OUTPUT,'id_1', 1 )

  2. Run the model by using the green "iterate over this layer" button for your input field.

  3. You can then use the attribute you need with:

    attribute(get_feature( @Field_calculator_OUTPUT,'id_1', 1 ), @field_name )

    where @field_name is a string input containing the field name you want to access.

You can also add that value 1 before using the model so you don't need to use field calculator in the model.

You were half-way there by accessing the field with get_feature_by_id, this solution just creates a new 'fake' id of value 1 and accesses the feature with get_feature instead of get_feature_by_id.

answered May 28 at 14:11

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.