1

enter image description here

I have been trying for a while but have not been able to split a polygon at multiple locations, using a table of lines, to get what is on the right side of the above image.

The best I can achieve is the large polygon being split at one of the locations. My query is below:

drop table if exists new_polygons;
CREATE TABLE new_polygons AS
SELECT ST_Split(a.geom, b.geom) as geom
FROM large_polygon as a, blades as b
WHERE ST_Intersects(a.geom, b.geom);
6
  • 2
    do those lines intersect within the polygon, creating areas?
    – geozelot
    Oct 23, 2018 at 15:33
  • Yes they do. This problem is also on a large scale, occurring numerous times throughout the 2 tables Oct 24, 2018 at 6:38
  • got this to work?
    – geozelot
    Oct 25, 2018 at 12:53
  • It seems to be working ok, the speed in practice is a bit of a issue though Oct 26, 2018 at 10:21
  • 1
    Your question is unclear. You say you want to split the polygon into multiple polygons, but the image you provide shows a set of multiple linestrings that don't for individual polygons.
    – jpmc26
    Jan 15, 2019 at 17:45

1 Answer 1

0

Update:

Starting with PostGIS 2.5 ST_Split supports splitting Polygons by MultiLinestrings.


This is actually expected behavior; ST_Split doesn't support splitting (Multi)Polygons by MultiLinestrings, and with your query you will get split parts of the same polygon for every intersecting line.

A possible workaround could be to use a recursive query and repeatedly split the collection by a single line:

WITH RECURSIVE
    split AS (
        SELECT (SELECT MAX(<id>) FROM blades) AS line_id,
               ST_Collect(a.geom) AS geom
        FROM large_polygon AS a
        UNION ALL
        SELECT line_id - 1 AS line_id,
               ST_Split(a.geom, b.geom) AS geom
        FROM split AS a,
             blade AS b
        WHERE b.<id> = a.line_id
    )

SELECT (ST_Dump(geom)).geom
FROM split
WHERE line_id = 0;

This will need your blade to have a consecutive row number (<id>) starting with 1 (I wrote this from the top of my head, there might be room for conceptual improvement).


As you mention 'large polygon' and seeing your images, it seems you are aiming at reducing size? If so, consider using ST_SubDivide; you may need to adjust the max_vertices parameter to fit your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.