Tests if a LINESTRING geometry is both closed and simple — that is, whether it forms a valid ring.
ST_IsRing returns true when both of the following conditions are met:
ST_IsClosed: the start point and end point of the LINESTRING are identical (
ST_StartPoint(g) = ST_EndPoint(g))ST_IsSimple: the LINESTRING does not self-intersect
If either condition fails, ST_IsRing returns false.
Syntax
boolean ST_IsRing(geometry g);Parameters
| Parameter | Description |
|---|---|
g | The geometry object that you want to specify. |
Examples
The following examples test two LINESTRING geometries and show how ST_IsClosed and ST_IsSimple determine the result of ST_IsRing.
A closed, simple LINESTRING — returns true
The geometry LINESTRING(0 0,0 2,2 0,0 0) forms a triangle: the start point (0,0) equals the end point (0,0), and the line does not cross itself.
SELECT ST_IsRing(geom), ST_IsClosed(geom), ST_IsSimple(geom)
FROM (SELECT 'LINESTRING(0 0,0 2,2 0,0 0)'::geometry AS geom) AS test; st_isring | st_isclosed | st_issimple
-----------+-------------+-------------
t | t | t
(1 row)A closed but self-intersecting LINESTRING — returns false
The geometry LINESTRING(0 0,0 2,0 0) is closed (same start and end point), but it backtracks along itself, making it non-simple. ST_IsRing returns false because ST_IsSimple fails.
SELECT ST_IsRing(geom), ST_IsClosed(geom), ST_IsSimple(geom)
FROM (SELECT 'LINESTRING(0 0,0 2,0 0)'::geometry AS geom) AS test; st_isring | st_isclosed | st_issimple
-----------+-------------+-------------
f | t | f
(1 row)