7

I'm using QGIS graphical modeler to build an iterative process that is supposed to:

  1. extract features from vector layer 1 (VL1) overlapping with features from vector layer 2 (VL2) (iterative per features in VL2)
  2. then process these extractions individually
  3. then collect/merge the separate outputs for further processing (e.g. merge all outputs to a single layer, then proceed with other algorithms)

How do I realize step 3 in the graphical model? Is that even possible?

Step 1 and 2 work fine as an "iterative process" when using Vector Features as input (instead of Vector Layer), as was suggested here: When running the model I can tap the "iterative" button: iterative button

But subsequently using the "Algorithm output" will always be just for the output of one "feature-iteration" (generating an output for each feature in VL2), but not the collection of all of them (generating one output).

Below is a picture of the model I need it for: Extract by polygon (yellow circle) has to be applied per feature (not per layer). The "Merge vector layers" (pink circle) merges the output of the various algorithm outputs, but not per feature iteration.

example model

3
  • 1
    Confess that I have never used this feature, what ist the point of having iterative processing and then merge the resulting layers into one? Commented Apr 22, 2021 at 8:16
  • 1
    And wouldn't it thus be the simplest solution not to tap the 'iterative' button? Commented Apr 22, 2021 at 8:45
  • in this particular process I need it. I am extracting a set of point features by each feature of a different layer, then do some percentage/min/max operations on the subset. If I don't tap the 'iterative' button, extract by feature would give me the whole set of points (intersected by all features together). As my "small" testset already generates 96 outputs that I manually have to merge (preferably not all in one big one but separated by some criteria), I'd rather have this repetitive task automated ;)
    – Honeybear
    Commented Apr 22, 2021 at 12:30

1 Answer 1

5

I faced the same problem with the modeller in QGIS and find some workaround but no solution inside the modeller.

The only way to get an iterative algorithm is to use Vector Features like you do. Then all the model is run for every feature so the merge vector layer algorithm will be run once for every feature...

My workaround using two models. The goals is to separate in two different models : the process you run for every feature and the process you run once. To connect the two models you will have to set the output folder of the first model to be used as the input of the second.

Open your actual model and create a new one. Displace the model boxes that have to be run once (after the yellow one if I get it) in a new model created for that.

In your first model you will have to set the last algorithm result as an output. Open the parameter of this output and set as default value a new file in a folder that will not move. The iterative model will create one file per iteration that will have name_you_set_id_current_itteration. Every time you want to use your first model don't forget to clear your output folder.

enter image description here

For the first try you can use the tool merge vector layer in your folder created and check the result is what you want. Then in your second model (the one you just created) add a file/folder entry and set default value to the folder you just created. Connect this entry to all the model boxes it has to be connected to. You may have to do test and some adjustment to make it work, then it will be only two subsequent models you have to execute.

Other solutions

  1. Use two models embedded one in another. I have tried and the problem is that you can not set the iteration on a model inside another model. (or I didn't find how to do it).

  2. Use a post-processing algorithm in your model. I have seen in the documentation here that there is a way to add post-processing algorithm, as it has to be coded I didn't explore this solution for the moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.