From two layers with point geometry, I use the following expression to draw a line from the 'POINT_LAYER_2' layer to the 'POINT_LAYER_1' layer.
make_line($geometry,overlay_nearest('POINT_LAYER_1',$geometry,limit:=1))
The layer 'POINT_LAYER_2' contains the numeric field "HOUSES" representing the number of houses.
I would like to label the 'POINT_LAYER_1' layer with the sum value of the "HOUSES" field of the 'POINT_LAYER_2' layer corresponding to points connected.
So far I only manage to label the sum, but on the layer 'POINT_LAYER_2', with the following expression:
sum("HOUSES", group_by:=overlay_nearest('POINT_LAYER_1',$id,limit:=1))
What I would need to get is an expression that works on layer 'POINT_LAYER_1' with the following result:
I have tried another approach, but it still does not give the expected result, as it shows the total sum value without filtering the nearest point:
aggregate(
layer:='POINT_LAYER_2',
aggregate:='sum',
expression:="HOUSES",
filter:=touches(make_line($geometry,overlay_nearest('POINT_LAYER_1',$geometry,limit:=1)), $geometry)
)