2

I got a feeling I'm missing something very simple here, but how can I use the modeler in QGIS to do the following tasks:

  • Adding/Removing a field
  • Looping through a field
  • Calculate field values based on other fields

I can only find how to do new layers and work with them - but most of the time, I already have the layer loaded in QGIS - I just need to edit the fields. Processing modeler to update table suggests to use the Network plugin, but even then I can't get it to work.

"Update field" algorithm from the network plugin

My understanding was, that the layer has to be connected with the field calculator in order to work, like in QGIS 3 Graphical Modeler field calculator with attribute's parameters but when I choose a vector layer as Input in the model builder, I can't choose my existing layer.

How am I supposed to connect them then?

Until now, I used PyQGis to do these basic tasks, but my shapefile is too big and I was hoping the modeler loops through a big attribute table a bit faster.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Mar 12, 2021 at 14:24
3
  • Could you clarify why you are trying to do this in a model instead of opening the field calculator? Commented Mar 12, 2021 at 14:28
  • @Erik because I have to do this task (or similar ones) multiple times on multiple layers Commented Mar 12, 2021 at 14:29
  • And where exactly is the "loop" in this task? Commented Mar 12, 2021 at 14:31

1 Answer 1

3

You can use "refactor fields" tool to add or remove fields as well as to calculate fields based on other fields or values.

First click on the "123" button and choose "model input" to use a input file of the model or "algorithm output" if you want to use the result of a previous calculation step of your model:

enter image description here

Then you can add, remove or change fields as you like.

The "loop" as you say, will be performed automatically on all features of a layer.

If you want to "loop" over several layers, you can run the model as batch process:

enter image description here

answered Mar 12, 2021 at 14:34
3
  • I tried like this, and it ran the model - but nothing happened. I got no new field in the attribute table - what did I do wrong? The expression is correct Commented Mar 12, 2021 at 15:31
  • @Jonas you missed to add an output layer Commented Mar 12, 2021 at 15:45
  • The question is about modifying an existing layer though, not creating a new output. Commented May 15, 2022 at 17: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.