The ST_IsRing() function

The ST_IsRing() function takes an ST_LineString and returns t (TRUE) if it is a ring (that is, the ST_LineString is closed and simple); otherwise, it returns f (FALSE).

Properties of geometries are described in ids_spat_036.html.

Syntax

ST_IsRing(ln1 ST_LineString)

Return type

BOOLEAN

Example

The ring_linestring table is created with the SMALLINT column gid and the ST_LineString column ln1:
CREATE TABLE ring_linestring (gid smallint,
                              ln1 ST_LineString);
The following INSERT statements insert three linestrings into the ln1 column. The first row contains a linestring that is not closed and is not a ring. The second row contains a closed and simple linestring that is a ring. The third row contains a linestring that is closed, but not simple, because it intersects its own interior. It is also not a ring:
INSERT INTO ring_linestring VALUES( 
   1,
   ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)', 1000) 
);

INSERT INTO ring_linestring VALUES( 
   2,
   ST_LineFromText('linestring (10.02 20.01,11.92 35.64,25.02
34.15,19.15 33.94, 10.02 20.01)', 1000) 
);

INSERT INTO ring_linestring VALUES( 
   3,
   ST_LineFromText('linestring (15.47 30.12,20.73 22.12,10.83
14.13,16.45 17.24,21.56 13.37,11.23 22.56,19.11 26.78,15.47 30.12)', 1000) 
);
The query returns the results of the ST_IsRing() function. The first and third rows return 0 because the linestrings are not rings, while the second row returns 1 because it is a ring:
SELECT gid, ST_IsRing(ln1) Is_it_a_ring
   FROM ring_linestring;

   gid is_it_a_ring 

     1            f
     2            t
     3            f