I have a project in Qgis where I have 2 layers: 1. plot of land (in the project named as "lohko") and 2. observation.

Example of the situation

I have joined the id of the plot of land layer to the observation layer in the join section and have a relation widget on the observation layer that is connected to it. What I am trying to do is choose from a dropdown menu the id of the plot of land that the observation relates to and to make it easier, I would like to list only the plots of land that are located the nearest to the observation. For this, I have used the overlay_nearest expression in the filter section as follows:


the function

When using this expression, if I set the limit to 0, it does what I expect it to do and lists none of the ids of the plots of field. However, when entering any other number, or even leaving it empty, in which case according to the explanation of the expression it should only list the nearest one, it gives all plots of land that I have in the project. Am I understanding this expression wrong, since when choosing the limit, I expected the expression to give the amount of id's that is the integer value written in it?

  • I suppose you're using QIGS? If so, please add the corresponding tag, thank you.
    – Erik
    Commented Mar 16, 2022 at 12:43

1 Answer 1


By default, the overlay_nearest () function returns a true/false value, depending if there is at all a feature that fulfills the conditions defined in the function's arguments. If you want to get not a true/false value, but the features for which the fuctions returns true, you must specify them in the second argument expression. This is the syntax (see documentation):

overlay_nearest(layer, [expression], [filter], [limit=1], [max_distance], [cache=false])

Your expression evaluates if there is at least one feature at all on layer lohko with a value ohra in field tyyppi and returns a true/false output.

  • Thank you for your answer! I thought that as I write this expression in the filter section of value relation, it would filter the results based on whether the expression returns a true or false value. For example if I write in the filter section the following expression: if($area >7500=1, 'true', 'false'), the dropdown menu lists only the values whose area is over 7500. But it seems that in the case of the overlay_nearest, the filter section (with ohra)works just fine, but the limit section doesn't seem to limit anything (or only if I write 0 there). Commented Mar 17, 2022 at 13:26

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.