1

I have two layers. One contains multiline and other contains point geometry. I want to check on a given line segment which point lies. In this way I need to list all points which is marked on the point layer. Grey color lines are drawn on one vector layer and point drawn on other vector layer.enter image description here

1 Answer 1

1

On the line layer, use this expression to identify the id of the point that lies on (or nearest to) the line: overlay_nearest( 'point_layer', $id)[0]. Instead of point_layer, use the name of your point layer.

You might use the expression in Field calculator to create a new attribute or as label source to create a label.

The expression highlighted in yellow creates the line's label in red; it identifies the value of the points (labeled in black): enter image description here


Variants:

  • Replace $id by any attribute of the point layer to return this value.

  • The expression above returns only one (the first) result, e.g. 3. If want to get more then one point, the expression looks like:

    array_to_string (overlay_nearest( 'point_layer', $id, limit:=4, max_distance:=0.0001))
    

    The limit parameter defines how many results you want to get. Set to -1 to get all results. Returns a string of points, e.g.: '1,2,3,4'

  • Using overlay_nearest(), you get also results for points that are not on the line. So theoretically, it would be better to use overlay_intersects() to get the point(s) that are on the line.

    Practically, this often doesn't find all points because of rounding errors (points cannot be correctly identified as lying on the line). That's why you have to stick to identify the nearest points. You can set an additional condition to only find points extremely close to the line (thus in fact exluding those who are not on the line) by defining an additional parameter with a (very short) distance: overlay_nearest( 'point_layer', $id, max_distance:=0.0001)[0]

1
  • Thanks @Babel for your help. It working fine!!!!!!!!!! Commented Aug 19, 2022 at 18:46

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.