I am trying to split a line from its intersection with another line. I know I can use st_split
directly here but I wish to split a line from several positions where it intersects other lines. What I discover is the following:
I know that lines 1 and 31 intersect
select st_intersects(a.geom,b.geom) from dumped_roads as a,
dumped_roads as b where a.gid=1 and b.gid=31;
Output:
st_intersects
---------------
t
(1 row)
Also, st_intersection(a.geom,b.geom)
returns an intersection point.
But when I do,
select st_intersects(a.geom, st_intersection(a.geom,b.geom))
from
dumped_roads as a,dumped_roads as b where a.gid=1 and b.gid=31;
st_intersects
---------------
f
(1 row)
I can't understand what the problem is. Although a.geom && st_intersection(a.geom,b.geom)
returns true but that wouldn't help me in splitting the line with the point obtained from intersection.
If it is indeed how it is, is there any way out on breaking a line from an obtained point which physically lies on the line, but is not in the linestrings point set?
Best Answer
This is a robustness issue. ST_Intersection creates a new point that is probably not a vertex from either of the original LineStrings, but it probably is close to the line. A more robust test of intersection is to check if the distance is zero.