Basically this is possible using a custom function. You just have to rebuild the Python syntax. For my testing purposes this worked fine:
from qgis.core import *
from qgis.gui import *
def run_processing_algorithm(algorithmName, algorithmParams, feature, parent):
algorithm_result = processing.run(algorithmName, algorithmParams)
result_layer = algorithm_result['OUTPUT']
result_feature = result_layer.getFeature(feature.id())
While e.g. using this as expression to return a feature:
'native:zonalstatisticsfb', -- name of the algorithm to run
map( -- dictionary of parameters
With this feature you can do whatever you want. E.g. return an attribute, its geometry or whatever. To return a specific attribute, combine it with
attribute() expression or
attributes() to get all fields and values as dictionary/map. For example:
Tested this with the native processing algorithms
buffer in QGIS 3.22. Both work fine, so I guess most algorithms should be usable this way. Note that you can not input a layer by using e.g.
@layer as this will return an error; You have to write the layernames as strings.
Also you can of course adjust the custom function to your personal needs or tweak it a little. For example use default settings or add an optional expression as input to pick the feature you want instead of getting the result feature by its id. The latter would e.g. make sense when running
qgis:voronoipolygons as here the resulting feature id does not match with the input feature id.