[postgis-users] Break lines at intersections

Pavel Iacovlev iacovlev.pavel at gmail.com
Wed Mar 28 03:29:20 PDT 2012


Hello,

Anyone has any ideas/tips of how to break lines at intersections ?
I have a a layer of lines and I want to break them at intersections
with them selfs, also (not that important but would be nice) break
lines forming a collapsed loop, for example 0.0;1.0;0.0 is broken at
1.0.

Currently this can be done in grass with v.clean tool=break,rmdupl but
it's relatively hard to add GRASS to a web app.

So far I came up with this query and out of ideas right now:

SELECT DISTINCT
gid,
ST_AsText(intersect_geom),
ST_Line_Locate_Point(GeometryN(the_geom, 1), intersect_geom) as point_loc1
FROM

(SELECT a.gid, ST_Intersection(a.the_geom, b.the_geom) AS
intersect_geom, a.the_geom
FROM roads as a, roads as b
WHERE ST_Intersects(a.the_geom, b.the_geom) AND (a.gid = 1)
) AS res1

WHERE GeometryType(intersect_geom) = 'POINT' -- Need support for
MULTILINESTRINGS, take start and end point ?
ORDER BY point_loc1

which has the following result: http://jsfiddle.net/9RJ8a/
I have the line, and the point positions on the line, but I can't get
around how to create my NEW broken lines with
ST_Line_Substring(geometry a_linestring, float startfraction, float
endfraction)

Any suggestion of how to accomplished this ? is the approach correct ?
any other ideas ?



More information about the postgis-users mailing list