Skip to main content

ST_IsRing

Tests whether a LineString is a ring - closed and simple (no self-intersections).

Syntax

ST_IsRing(geometry)

Parameters

ParameterTypeDescription
geometryGeometryLineString to test

Returns

TypeDescription
BooleanTrue 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