ST_IsClosed function

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

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

If the given curve or multicurve is empty, then 0 (zero) is returned. If it is null, then null is returned.

This function can also be called as a method.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_IsClosed(curve)

Parameter

curve
A value of type ST_Curve or ST_MultiCurve or one of their subtypes that represent the curve or multicurve 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