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.
-
Could you clarify why you are trying to do this in a model instead of opening the field calculator?Erik– Erik2021年03月12日 14:28:41 +00:00Commented Mar 12, 2021 at 14:28
-
@Erik because I have to do this task (or similar ones) multiple times on multiple layersJonas– Jonas2021年03月12日 14:29:59 +00:00Commented Mar 12, 2021 at 14:29
-
And where exactly is the "loop" in this task?Erik– Erik2021年03月12日 14:31:22 +00:00Commented Mar 12, 2021 at 14:31
1 Answer 1
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:
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:
-
-
@Jonas you missed to add an output layerMrXsquared– MrXsquared2021年03月12日 15:45:22 +00:00Commented Mar 12, 2021 at 15:45
-
The question is about modifying an existing layer though, not creating a new output.bugmenot123– bugmenot1232022年05月15日 17:42:54 +00:00Commented May 15, 2022 at 17:42