QGIS version 3.16.16-Hannover OS Version Linux Mint 19.3

So I am trying to run a simple Extract by location algorithm in the graphical modeler

I have as Input a polygon file with a field call NUMPOINTS that comes from counting points in polygons.

I want to extract the polygon with the maximum value

I use the expression


I tested the expression using the algorithm outside the graphical modeler and everything works fine.

Then I go to the graphical model to create the model


alorithm parameters

And when I run it I get this error message

syntax error, unexpected $end
Error encountered while running Extract by expression
Execution failed after 0.12 seconds

So I open the model as a python script to try see what is happening. The corresponding code line is

# Extract by expression
alg_params = {
    'EXPRESSION': QgsExpression('\"NUMPOINTS\" = maximum(\"NUMPOINTS\")').evaluate(),
    'INPUT': parameters['InputPoints'],
    'OUTPUT': parameters['Test1']
outputs['ExtractByExpression'] = processing.run('native:extractbyexpression', alg_params, context=context, feedback=feedback, is_child_algorithm=True)
results['Test1'] = outputs['ExtractByExpression']['OUTPUT']
return results

And when I run it from there I get the following message

Unable to execute algorithm
Incorrect parameter value for EXPRESSION
Unable to execute algorithm
Incorrect parameter value for EXPRESSION
Execution failed after 0.09 seconds

As I said before, I tested the expression outside the graphical modeler and it works fine.

I just do not understand why the algorithm is not working here or how to make it work.

What am I missing?

  • By the way: you write you want to use extract by expression on a polygon layer, but in your screenshot, you have Input Points. However, this is just a detail, see solution how to solve the problem.
    – Babel
    Commented Sep 19, 2022 at 17:34

1 Answer 1


In the expression field, select the first entry: Value insted of Precalculated Value. Then the model runs fine.

If you're using the second entry: Pre calculated Value, you have to enclose the expression in single qutotes ': ' "NUMPOINTS" = maximum("NUMPOINTS") '

enter image description here

  • 1
    thank you very much for that, it seemed very simple and it was driving me crazy. I have tested both options you described and both worked for me
    – geotyr
    Commented Sep 19, 2022 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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