ST_IsClosed

ST_IsClosed takes a linestring or a multilinestring as an input parameter and returns 1 if the given linestring or multilinestring is closed. Otherwise, 0 (zero) is returned.

A linestring is closed if the start point and end point are equal. If the linestring has Z coordinates, the Z coordinates of the start point and end point must be equal. Otherwise, the points are not considered equal, and the linestring is not closed. A multilinestring is closed if each of its linestrings are closed.

If the given linestring or multilinestring is empty, then 0 (zero) is returned. If the geometry is null, then null is returned.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_IsClosed(geometry)

Parameter

geometry
A value of type ST_LineString or ST_MultiLineString that represents the linestring or multilinestring that is to be tested.

Return type

INTEGER

Examples

Example 1

This example creates several linestrings. The last two linestrings have the same X and Y coordinates, but one linestring contains varying Z coordinates that cause the linestring to not be closed, and the other linestring contains varying M coordinates (measures) that do not affect whether the linestring is closed.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_lines (id INTEGER, geometry ST_Linestring)

INSERT INTO sample_lines VALUES
       (1, ST_Linestring('linestring EMPTY',0))

INSERT INTO sample_lines VALUES
       (2, ST_Linestring('linestring(10 10, 20 10, 20 20)' ,0))

INSERT INTO sample_lines VALUES
       (3, ST_Linestring('linestring(10 10, 20 10, 20 20, 10 10)' ,0))

INSERT INTO sample_lines VALUES
       (4, ST_Linestring('linestring m(10 10 1, 20 10 2, 20 20 3, 
        10 10 4)' ,0))

INSERT INTO sample_lines VALUES
       (5, ST_Linestring('linestring z(10 10 5, 20 10 6, 20 20 7, 
        10 10 8)' ,0))

SELECT id, ST_IsClosed(geometry)  Is_Closed
FROM sample_lines

Results:

ID          IS_CLOSED
----------- -----------
          1           0
          2           0
          3           1
          4           1
          5           0

  

Example 2

In this example, two multilinestrings are created. ST_IsClosed is used to determine if the multilinestrings are closed. The first one is not closed, even though all of the curves together form a complete closed loop. This is because each curve itself is not closed.

The second multilinestring is closed because each curve itself is closed.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_mlines (id INTEGER, geometry ST_MultiLinestring)
INSERT INTO sample_mlines VALUES
       (6, ST_MultiLinestring('multilinestring((10 10, 20 10, 20 20),
                                               (20 20, 30 20, 30 30),
                                               (30 30, 10 30, 10 10))',0))

INSERT INTO sample_mlines VALUES
       (7, ST_MultiLinestring('multilinestring((10 10, 20 10, 20 20, 10 10 ),
                                                (30 30, 50 30, 50 50, 
                                                 30 30 ))',0))

SELECT id, ST_IsClosed(geometry)  Is_Closed
FROM sample_mlines

Results:

ID          IS_CLOSED
----------- -----------
          6           0
          7           1