[GIS] How to export selected features in Processing Modeler

batchqgisvector

This question is a follow up from a suggestion from this thread:

How to export a single feature (line) from multiple layers and export to individual layers?

I'm creating a batch process that selects a line (feature) from a vector layer and saves the selected feature to a child layer containing the name of the parent.

I'm using $length = maximum($length, group_by:= "id") as the expression because I want to select the longest line in each layer.

The question is how do I export only selected features in the Processing Modeler? I can't find a "Export – Save Selected Features As…" option.

enter image description here

enter image description here

Best Answer

To export features from expression in the modeler, first you need to Extract features by expression instead of select them.

In the modeler algorithm, you can define a named output.

Output generated by an algorithm are handled a bit differently when the algorithm is used as a part of a model. Instead of selecting the filepath where you want to save each output, you just have to specify if that ouput is an intermediate layer (and you do not want it to be preserved after the model has been executed), or it is a final one.

When layers are not a final result, you should just leave the corresponding field. Otherwise, you have to enter a name that will be used to identify the layer in the parameters dialog that will be shown when you run the model later.

Source: https://docs.qgis.org/testing/en/docs/training_manual/processing/modeler_twi.html#starting-with-the-graphical-modeler

When you run the model, you can define to write the named output to a file (instead a temporary file) and load it to the canvas or not.

Related Question