title: Snap points to linestring in Postgis
body: <p>This code snap line to points. Any ideas how to modify the code to snap the points to line. Thanks.</p>
  
  <pre><code>DROP TABLE IF EXISTS test_gps_point2;
  SELECT D.ordinality As sub_id, D.geom::geometry(LINESTRING,3414) AS 
  geom INTO test_table
  FROM
  gtd1304_line_2a AS L
  LEFT JOIN LATERAL
  (  -- form a multipoint of all the nodes
     -- close enough to line to be considered on the line
      SELECT
          ST_Union(N.geom ORDER BY L.matched_line &lt;-&gt; N.geom) AS geom
      FROM gtd1304_point_2 AS N
      WHERE ST_DWithin(L.matched_line, N.geom, 10000)
  ) AS MP ON TRUE
  CROSS JOIN LATERAL
  -- snap the LINE to the MP which forces nodes to be injected to the line
  -- then split at these node location and dump multilinestring into individual lines
  ST_Dump(
       COALESCE(ST_Split(ST_Snap(MP.geom, L.matched_line, 10), matched_line), MP.geom)
      ) WITH ORDINALITY AS D;
  </code></pre>