ST_SelfIntersection — Returns the points where a Line intersects itself.
geometry ST_SelfIntersection(bytea Line);
Returns the points where a Line intersects itself.
The incoming geometry must be a LineString or MultiLineString. Return Null if there isn't an Intersection
![]() | |
This method does not support GeometryCollections |
| 2D | 3D | M |
|---|---|---|
![]() | - | - |
| OGC SFS for SQL. 1.1 (1999) | OGC SFS for SQL. 1.1.0 (2005) | OGC SFS for SQL. 1.2.0 (2006) | SQL-MM Part 3 |
|---|---|---|---|
| - | - | - | - |
--3D LineString
SELECT ST_AsEWKT(ST_SelfIntersection(ST_GeomFromText('LINESTRING (1 1 2, 3 3 4, 3 2 3, 2 4 6)')));
--Result
POINT (2.666666666666666 2.666666666666666)
--2D MultiLineString
SELECT ST_AsEWKT(ST_SelfIntersection(ST_GeomFromText('MULTILINESTRING ((1 1, 3 3, 3 2, 2 4),
(1 2, 3 4))')));
--Result
MULTIPOINT ((2.333333333333334 3.333333333333334), (2.666666666666666 2.666666666666666))
--Line without self-intersection
SELECT ST_Issimple(GeomA), ST_AsText(ST_SelfIntersection(GeomA))
FROM (SELECT ST_GeomFromText('LINESTRING (1 2, 3 4)') as geomA) as foo;
--Result
st_issimple | st_astext
-------------+-----------
t |
![]() GeomA | ![]() ST_SelfIntersection(GeomA) |