2

This code snap line to points. Any ideas how to modify the code to snap the points to line. Thanks.

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 <-> 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;
2
  • I tried to run a provided query and I am getting following error: "[XX000] ERROR: Splitting of MultiPoint geometries is unsupported". What kind of point geometry are you inserting? You might move your question to gis.stackexchange.com
    – Losbaltica
    Oct 2, 2018 at 15:04
  • And your query could be simplify to something like that: SELECT st_snap(geom, (SELECT st_collect(geom) geom FROM points), 10000) geom, chunk_id FROM lines;
    – Losbaltica
    Oct 2, 2018 at 15:23

1 Answer 1

0

As far as I know you cannot do that, at least not with ST_Snap. I think the reason is that since you snap something A onto something B and get back something of type A with B snapped on it, and you can't get back something of type point with something snapped on it since then it becomes a line.

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.