QGIS Snapping – How to Handle Unexpected Behavior When Snapping Geometries to Layer

qgisqgis-3qgis-processingsnapping

I have been trying to snap points to a line layer (vertex or segment)
but the "Snap Geometries to Layer" processing algorithm with behavior 3 supposed to do what I want

Prefer closest point, don’t insert new vertices.

(Snap to closest point, regardless of it is a node or a segment. No new nodes will be inserted.)

don't seem to work as supposed
enter image description here

How am I supposed to snap the point to the middle of the line (the real closest point) using this tool ? or am I using the tool wrong and there is something I am not getting

Best Answer

The behaviour of this tool is a bit tricky, indeed. So instead of snapping, better create the closest point on the line layer using QGIS expressions with Geometry generator or Geometry by Expression (see here for details):

closest_point( 
     aggregate( 
        'lines',  -- name of your line layer
        'collect',
        $geometry
    )
    ,
    $geometry
)

enter image description here

Related Question