I have the following problem: I try to do two parallel selections. For this I have applied before the "extract by location" algorithm. Now I would like to execute in the next step from this layer two parallel selections with the "select by expression" algorithm. However, this probably does not work. The modeller created me the two selection layers, but contain both the same records. So the one selection is carried out correctly, but for the other selection it takes the same value.

  • After you run the first "select by expression" alg are you saving the selection before you run the second? – firefly-orange Jun 29 '17 at 10:56
  • yes, i have saved the selections. one moment please, i'll send a screenshot – user100002 Jun 29 '17 at 11:21
  • i've used the following expressions: For Routes_without_bridge_and_tunnel: "bridge"='F' AND "tunnel"='F' For bridge_and_tunnel: "bridge"='T' OR "tunnel"='T' – user100002 Jun 29 '17 at 11:30
  • I think this bug report might be relevant. Try either going to the menubar Processing > Options > General and make sure the Use only selected features option is unchecked; or use the Extract by attribute algorithm instead. A third option could be to replace your Select by expression algorithms with a custom script which ensures all features are deselected and then selects the features based on the expression. – Joseph Jun 29 '17 at 12:01
  • 1
    i've unchecked "use only selected features", but it doesn't function, too. So if i've understand it correctly i have to use the "Extract by attribute" instead the Select_algorithm, because there are more Selection_algorithms, right? And when i have more attributes to select, so i must use a new extend algorithm for each attribute? – user100002 Jun 29 '17 at 12:53

You could try creating a custom script which:

  1. Ensures all features are deselected.
  2. Selects the feature(s) matching your expression.
  3. Saves the selected feature(s) in a layer.

You can create one from:

Processing Toolbox > Scripts > Tools > Create new script

Then use something like the following:

##Output=output vector

from qgis.core import QgsExpression, QgsFeatureRequest

layer = processing.getObject(Input_Layer)
exp = QgsExpression( Expression)
ids = [i.id() for i in layer.getFeatures(QgsFeatureRequest(exp))]

processing.runalg("qgis:saveselectedfeatures", layer, Output)

Make sure the script is saved in your /.qgis2/processing/scripts/ directory. Now in your modeler, replace the Select by expression and Save selected features algorithms with the script and use the same parameters. Then repeat for the other side. Hopefully, this should save the correct features into their respective layers.


You could set up your model like shown and entering the parameters for the script:

Step 1

Then repeat:

Step 2

  • 1
    ok, thx. At first i will try to replace the select-alg with the extract-alg. If it doesn't function i will write the custom script. – user100002 Jun 29 '17 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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