[postgis-users] breake lines

Martin Davis mtnclimb at gmail.com
Wed Sep 4 15:01:34 PDT 2019


On Wed, Sep 4, 2019 at 4:54 AM <paul.malm at lfv.se> wrote:

> Hi,
>
> If I understand your question correct, yes I would like to break all lines
> in the intersections with another layer.
>
> No I have not tried MultiLinestrings comprised of all lines that are
> intersecting the lines to be broken. Don’t know how to do this. L
>
>
>
Here's an example query showing how to collect all cutting lines which
intersect each data line and then use them to split the data line:

WITH
data AS (
    SELECT * FROM (VALUES
        ( 'LINESTRING (100 100, 400 100)'::geometry ),
        ( 'LINESTRING (100 300, 400 300)'::geometry ),
        ( 'LINESTRING (250 400, 400 400)'::geometry )
    ) AS t(geom)
),
cutter AS (
    SELECT * FROM (VALUES
        ( 'LINESTRING (150 50, 150 350)'::geometry ),
        ( 'LINESTRING (200 50, 200 150)'::geometry ),
        ( 'LINESTRING (250 350, 250 250)'::geometry ),
        ( 'LINESTRING (300 350, 300 50)'::geometry ),
        ( 'LINESTRING (350 250, 350 450)'::geometry )
    ) AS t(geom)
)
SELECT ST_Split( d.geom,
            (SELECT ST_Collect(c.geom) geom
                FROM cutter c WHERE ST_Intersects(d.geom, c.geom)
            )) geom
    FROM data d;

I think this should work even if the inputs are MultiLineStrings, but
you'll have to verify that.

One issue that might arise depending on your data is that ST_Split errors
out if the splitting line has any portion which is collinear with a portion
of the input.  I guess the theoretical rationale for this is that the
splitting code doesn't know which "side" of the output to allocate the
common line to.  But really this isn't very useful, since there's no easy
way to detect this situation and prevent it from happening. If this is an
issue for you then report back to the list, and we can think about how to
fix this.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20190904/2d6cf459/attachment.html>


More information about the postgis-users mailing list