You can use overlay_nearest()
function that has an optional filter condition. The filter is a bit tricky, but you can use a variable @value
based on the attribute value
and than introduce it into the filter condition by concatenating it as a string and than convert it back to a function with eval()
.
Red arrowheads show the direction in whicht points are connected: 7 is linked to 5 and 5 to 7; 11 is linked to 7, too ("outgoing"), but 11 has no "incoming" connection:
You can use the expression with Geometry Generator (for visualization) or Geometry by Expression (for actual lines) - see here for differences.
The expression looks like this: you can freely change the percentage in line 3. Be sure to introduce the name of your point layer in line 11:
with_variable(
'percentage',
50, -- change this value
make_line (
$geometry,
with_variable (
'value',
value,
eval(
'overlay_nearest (
''points'', -- change to the name of your points layer
$geometry,
limit:=11,
filter:="value">=' || (@value/100*@percentage100*(100-@percentage)) || ' and "value" <=' || (@value* @value * (100+@percentage)/100 ) || ')'
)
)[1]
)
)