If you select your features before running the Field Calculator in the modeler, the output will contain only those selected features.
A workaround would be to use a custom script in your model which allows you to update your selected features within the same layer.
To do this, go to Processing Toolbox > Scripts > Tools > Create new script and copy the following:
from qgis.core import QgsExpression
layer = processing.getObject(Layer)
idx = layer.fieldNameIndex(Fields)
e = QgsExpression(Formula)
for f in layer.selectedFeatures():
f[idx] = e.evaluate(f)
layer.updateFeature( f )
Save the script into
C:\Users\You\.qgis2\processing\scripts. In your modeler, create 3 parameters:
- Layer - Vector layer
- Field - Table field
- Formula - String
Then add the custom script from the list of algorithms and fill in the options:
I ran a test on a layer where I want to change the values in the
id field for the selected features:
I ran the model selecting the layer, field and entering a value of
Once finished, the attributes of the layer should be updated:
Note that you could use the same expressions as you would in the Field Calculator such as
CASE statements etc. due to the QgsExpression class used in the script.