[postgis-users] breake lines

Martin Davis mtnclimb at gmail.com
Sun Sep 8 15:10:22 PDT 2019


You have to love how SQL always provides multiple ways of expressing things
(and the options increase with each new release of the standard).

So here's Solution #3 to this problem.  This one uses the nifty Postgres
JOIN LATERAL functionality.  I think it's the simplest of the 3
alternatives, but I'm not sure how it's performance will compare.  Perhaps
Paul could provide some performance numbers for comparison?  (And of course
confirm that it works in the same way as the other queries)

WITH
data AS (
    SELECT * FROM (VALUES
        ( 1, 'LINESTRING (100 100, 400 100)'::geometry ),
        ( 2, 'LINESTRING (100 300, 400 300)'::geometry ),
        ( 3, 'LINESTRING (250 400, 400 400)'::geometry ),
        ( 4, 'LINESTRING (-10 -10, -20 -20)'::geometry ),
        ( 5, 'LINESTRING (-30 -30, -40 -40)'::geometry )
    ) AS t(id, 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 id, CASE WHEN cut.geom IS NULL THEN d.geom
                ELSE ST_Split( d.geom, cut.geom ) END AS geom
    FROM data d
    CROSS JOIN LATERAL
        (SELECT ST_Collect(c.geom) geom
            FROM cutter c WHERE ST_Intersects(d.geom, c.geom)
        ) AS cut;

On Thu, Sep 5, 2019 at 3:01 PM Martin Davis <mtnclimb at gmail.com> wrote:

> Here's a slightly different way to do the same thing.  Instead of using a
> LEFT JOIN to find the non-split lines, it checks whether the result of the
> ST_Collect of intersecting lines, and then either computes the split or
> keeps the original input line.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20190908/cd98b6d8/attachment.html>


More information about the postgis-users mailing list