ST_IsRing function
The ST_IsRing function takes a curve as an input parameter and returns 1 if it is a ring. Otherwise, 0 (zero) is returned. A curve is a ring if it is simple and closed.
If the specified curve is empty, then 0 (zero) is returned. If it is null, then null is returned.
Syntax
Parameter
- curve
- A value of type ST_Curve or one of its subtypes that represents the curve to be tested.
Return type
INTEGER
Examples
In this example, four linestrings
are created. ST_IsRing is used to check if they are rings. The last
one is not considered a ring even though it is closed because the
path crosses over itself.
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(10 10, 20 10, 10 20, 20 20, 10 10)' ,0))
SELECT id, ST_IsClosed(geometry) Is_Closed, ST_IsRing(geometry) Is_Ring
FROM sample_lines
Results:
ID IS_CLOSED IS_RING
----------- ----------- -----------
1 0 0
2 0 0
3 1 1
4 1 0