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,136
  • 29
  • 109
  • 338
Jonas
  • 159
  • 9

1 Answers1

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

MrXsquared
  • 34,292
  • 21
  • 67
  • 117