ST_IsRing
Tests whether a LineString is a ring - closed and simple (no self-intersections).
Syntax
ST_IsRing(geometry)
Parameters
| Parameter | Type | Description |
|---|---|---|
| geometry | Geometry | LineString to test |
Returns
| Type | Description |
|---|---|
| Boolean | True if geometry is a ring, false otherwise |
Examples
Valid Ring
SELECT ST_IsRing(ST_GeomFromText('LINESTRING(0 0, 4 0, 4 4, 0 4, 0 0)'));
-- Returns: true
Not Closed (Not a Ring)
SELECT ST_IsRing(ST_GeomFromText('LINESTRING(0 0, 4 0, 4 4)'));
-- Returns: false (not closed)
Self-Intersecting (Not a Ring)
SELECT ST_IsRing(ST_GeomFromText('LINESTRING(0 0, 2 2, 2 0, 0 2, 0 0)'));
-- Returns: false (self-intersects)
Find Valid Polygon Candidates
SELECT id FROM line_features
WHERE ST_IsRing(geom);
Notes
- A ring is a LineString that is both closed AND simple
- ST_IsRing = ST_IsClosed AND ST_IsSimple
- Rings can be used to construct valid polygons
- Only applies to LineStrings
See Also
- ST_IsClosed - Test if LineString is closed
- ST_IsSimple - Test if geometry is simple
- ST_Boundary - Get boundary of geometry