ST_Split — Returns a collection of geometries created by splitting a geometry by another geometry.
geometry ST_Split(geometry input, geometry blade);
The function supports splitting a LineString by a (Multi)Point, (Multi)LineString or (Multi)Polygon boundary, or a (Multi)Polygon by a LineString. When a (Multi)Polygon is used as as the blade, its linear components (the boundary) are used for splitting the input. The result geometry is always a collection.
This function is in a sense the opposite of ST_Union. Applying ST_Union to the returned collection should theoretically yield the original geometry (although due to numerical rounding this may not be exactly the case).
|
|
|
If the the input and blade do not intersect due to numerical precision issues, the input may not be split as expected. To avoid this situation it may be necessary to snap the input to the blade first, using ST_Snap with a small tolerance. |
Availability: 2.0.0 requires GEOS
Enhanced: 2.2.0 support for splitting a line by a multiline, a multipoint or (multi)polygon boundary was introduced.
Enhanced: 2.5.0 support for splitting a polygon by a multiline was introduced.
Split a circular polygon by a diagonal line.
SELECT
ST_Split(
ST_Buffer('POINT(100 90)'::geometry, 50),
'LINESTRING(10 10,190 190)'::geometry
);
GEOMETRYCOLLECTION(POLYGON((150 90,149 80.2,146.2 70.9,141.6 62.2,135.4 54.6,127.8 48.4,119.1 43.8,109.8 41,100 40,90.2 41,80.9 43.8,72.2 48.4,64.6 54.6,60.1 60.1,129.9 129.9,135.4 125.4,141.6 117.8,146.2 109.1,149 99.8,150 90)), POLYGON((60.1 60.1,58.4 62.2,53.8 70.9,51 80.2,50 90,51 99.8,53.8 109.1,58.4 117.8,64.6 125.4,72.2 131.6,80.9 136.2,90.2 139,100 140,109.8 139,119.1 136.2,127.8 131.6,129.9 129.9,60.1 60.1)))
Split a MultiLineString by a Point, where the point lies exactly on both LineStrings elements.
SELECT ST_Split('MULTILINESTRING((10 10,190 190),(15 15,30 30,100 90))',
ST_Point(30, 30));
GEOMETRYCOLLECTION(
LINESTRING(10 10,30 30),
LINESTRING(30 30,190 190),
LINESTRING(15 15,30 30),
LINESTRING(30 30,100 90)
)
Split a LineString by a Point, where the point does not lie exactly on the line. Shows using ST_Snap to snap the line to the point to allow it to be split.
WITH data AS (SELECT
'LINESTRING(0 0,100 100)'::geometry AS line,
'POINT(51 50)':: geometry AS point
)
SELECT ST_Split(ST_Snap(line, point, 1), point) AS snapped_split,
ST_Split(line, point) AS not_snapped_not_split
FROM data;
-[ RECORD 1 ]--------- snapped_split | GEOMETRYCOLLECTION(LINESTRING(0 0,51 50), LINESTRING(51 50,100 100)) not_snapped_not_split | GEOMETRYCOLLECTION(LINESTRING(0 0,100 100))