Skip to main content
Last updated on

ST_ISCLOSED

SinceVersion dev

Description​

Determines whether a LINESTRING is closed. A LINESTRING is closed when its first and last points are exactly equal. This function does not use a distance tolerance.

Syntax​

ST_ISCLOSED( <shape> )

Parameters​

ParameterDescription
<shape>An encoded geometry value (VARCHAR) returned by a spatial constructor such as ST_GeometryFromText or ST_LineFromText. Raw WKT text must first be converted with a constructor.

Return Value​

Returns a BOOLEAN value:

  • true if the input is a valid LINESTRING whose first and last points are exactly equal.
  • false if the input is a valid LINESTRING whose first and last points are different.
  • NULL if the input is NULL, is not a LINESTRING, or cannot be decoded as a valid geometry.

In SQL output, true is displayed as 1 and false as 0.

Example​

Closed LineString

SELECT ST_IsClosed(
ST_GeometryFromText('LINESTRING(0 0, 1 1, 0 0)')
) AS is_closed;
+-----------+
| is_closed |
+-----------+
| 1 |
+-----------+

Open LineString

SELECT ST_IsClosed(
ST_GeometryFromText('LINESTRING(0 0, 1 1)')
) AS is_closed;
+-----------+
| is_closed |
+-----------+
| 0 |
+-----------+

NULL Input

SELECT ST_IsClosed(NULL) AS is_closed;
+-----------+
| is_closed |
+-----------+
| NULL |
+-----------+

Non-LineString Input

SELECT ST_IsClosed(ST_Point(0, 0)) AS is_closed;
+-----------+
| is_closed |
+-----------+
| NULL |
+-----------+