I write a request that allows to snap a point to another. Here is the request:
SELECT
f.gid as gid,
ST_Snap (f.Geom, g.Geom, min, 5) as geom
FROM
boiten as f,
(SELECT ST_Collect (Geom) as Geom
FROM ft_chambre) as g
It works but the snapped points missed the closest position
Update:
For the CRS it's 2154 ,I want to snap the point to the red ones I modified my code to this:
SELECT
f.gid as gid,
ST_Snap(f.Geom, g.Geom, st_distance(f.Geom, g.Geom)*1.2) as geom
FROM
boiten as f,
(SELECT ST_Collect(Geom) as Geom
FROM ft_chambre) as g
But like you see there are points witch snapped to the wrong place or has snapped to more than one.
For exemple This point has snapped to the wrong place where the other point has already snapped to
Answer
A quick hack to guarantee that you always snap to the closest point:
SELECT f.gid AS gid,
ST_Snap(
f.Geom,
ST_ClosestPoint(g.Geom, f.Geom),
ST_Distance(
f.Geom,
ST_ClosestPoint(g.Geom, f.Geom)
) * 1.01
) AS geom
FROM (
SELECT ST_Collect(Geom) as Geom
FROM ft_chambre
) AS g,
boiten AS f
Let me add: if this gives you the same (apoarently wrong) result, it's the tolerance that you need to define properly. If there are points that you don't want to be snapped due to them being too far, you need to specify what distance is too far.
No comments:
Post a Comment