4

I am trying to snap a series of points relative to the nearest line (which i know can be achieved via "Snap geometries to layer", however, i want to restrict snapping to the polygons the points sit within.

Does anyone have any ideas?

Taras
  • 32,823
  • 4
  • 66
  • 137

1 Answers1

2

Use Geometry generator or Geometry by expression (see details) with this expression (replace polygon in line 2 with the name of your polygon layer):

closest_point (
    overlay_within ('polygon', boundary ($geometry))[0],
    $geometry
)

enter image description here


If you want to snap the points to a separate line layer, but only to those sections of the line within the polygon, use this expression:

closest_point (
    intersection (
        overlay_nearest ('line',$geometry)[0],
        overlay_nearest ('poly',$geometry)[0]
    ),
    $geometry
)

Blue points snapped to line (red points), but not the closest point overall on the line, but only those sections that are within the polygon: enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208