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.
You could try creating a custom script which:
- Ensures all features are deselected.
- Selects the feature(s) matching your expression.
- 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:
##Save_selected_features=name ##Input_Layer=vector ##Expression=string ##Output=output vector from qgis.core import QgsExpression, QgsFeatureRequest layer = processing.getObject(Input_Layer) layer.removeSelection() exp = QgsExpression( Expression) ids = [i.id() for i in layer.getFeatures(QgsFeatureRequest(exp))] layer.setSelectedFeatures(ids) 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: