The ST_IsClosed() function

The ST_IsClosed() function takes an ST_LineString or ST_MultiLineString and returns t (TRUE) if it is closed; otherwise, it returns f (FALSE).

Properties of geometries are described in ids_spat_036.html.

Syntax

ST_IsClosed(ln1 ST_LineString)
ST_IsClosed(mln1 ST_MultiLineString)

Return type

BOOLEAN

Example

The closed_linestring table is created with a single ST_LineString column:
CREATE TABLE closed_linestring (ln1 ST_LineString);
The following INSERT statements insert two records into the closed_linestring table. The first record is not a closed linestring, while the second is:
INSERT INTO closed_linestring VALUES( 
   ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)', 1000) 
);

INSERT INTO closed_linestring VALUES( 
   ST_LineFromText('linestring (10.02 20.01,11.92 35.64,25.02 34.15,
   19.15 33.94,10.02 20.01)',1000) 
);
The query returns the results of the ST_IsClosed() function. The first row returns a 0 because the linestring is not closed, while the second row returns a 1 because the linestring is closed.
SELECT ST_IsClosed(ln1) Is_it_closed 
   FROM closed_linestring;

is_it_closed 

           f
           t
The closed_mlinestring table is created with a single ST_MultiLineString column:
CREATE TABLE closed_mlinestring (mln1 ST_MultiLineString);
The following INSERT statements insert an ST_MultiLineString record that is not closed and another that is:
INSERT INTO closed_mlinestring VALUES( 
   ST_MLineFromText('multilinestring ((10.02 20.01,10.32 23.98,
   11.92 25.64),(9.55 23.75,15.36 30.11))',1000) 
);

INSERT INTO closed_mlinestring VALUES( 
   ST_MLineFromText('multilinestring ((10.02 20.01,11.92 35.64,
   25.02 34.15,19.15 33.94,10.02 20.01),(51.71 21.73,73.36 27.04,
   71.52 32.87,52.43 31.90,51.71 21.73))',1000) 
);
The query lists the results of the ST_IsClosed() function. The first row returns 0 because the multilinestring is not closed. The second row returns 1 because the multilinestring stored in the mln1 column is closed. A multilinestring is closed if all of its linestring elements are closed:
SELECT ST_IsClosed(mln1) Is_it_closed 
   FROM closed_mlinestring;

is_it_closed 

           f
           t