ST_Split
Name
ST_Split — Returns a collection of geometries created by splitting a geometry by another geometry.
Synopsis
geometry
ST_Split
(
geometry
input
, geometry
blade
)
;
Description
The function supports splitting a LineString by a (Multi)Point, (Multi)LineString or (Multi)Polygon boundary, or a (Multi)Polygon by a LineString. 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).
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.
To improve the robustness of ST_Split it may be convenient to ST_Snap the input to the blade in advance using a very low tolerance. Otherwise the internally used coordinate grid may cause tolerance problems, where coordinates of input and blade do not fall onto each other and the input is not being split correctly (see #2192 ). |
When a (Multi)Polygon is passed as as the blade, its linear components (the boundary) are used for cutting the input. |
Examples
Polygon Cut by Line
|
|
-- this creates a geometry collection consisting of the 2 halves of the polygon -- this is similar to the example we demonstrated in ST_BuildArea SELECT ST_Split(circle, line) FROM (SELECT ST_MakeLine(ST_Point(10, 10),ST_Point(190, 190)) As line, ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50) As circle) As foo; -- result -- GEOMETRYCOLLECTION(POLYGON((150 90,149.039264020162 80.2454838991936,146.193976625564 70.8658283817455,..), POLYGON(..))) -- To convert to individual polygons, you can use ST_Dump or ST_GeometryN SELECT ST_AsText((ST_Dump(ST_Split(circle, line))).geom) As wkt FROM (SELECT ST_MakeLine(ST_Point(10, 10),ST_Point(190, 190)) As line, ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50) As circle) As foo; -- result -- wkt --------------- POLYGON((150 90,149.039264020162 80.2454838991936,..)) POLYGON((60.1371179574584 60.1371179574584,58.4265193848728 62.2214883490198,53.8060233744357 ..))
Multilinestring Cut by point
|
|
SELECT ST_AsText(ST_Split(mline, pt)) As wktcut FROM (SELECT ST_GeomFromText('MULTILINESTRING((10 10, 190 190), (15 15, 30 30, 100 90))') As mline, ST_Point(30,30) As pt) As foo; wktcut ------ GEOMETRYCOLLECTION( LINESTRING(10 10,30 30), LINESTRING(30 30,190 190), LINESTRING(15 15,30 30), LINESTRING(30 30,100 90) )
See Also
ST_AsText , ST_BuildArea , ST_CollectionExtract , ST_Dump , ST_GeometryN , ST_Subdivide , ST_Union