Functions / PostGIS / ST_IsRing
PostGISGeometry Accessors

ST_IsRing

What is ST_IsRing?

ST_IsRing is a PostGIS function that returns true if a LINESTRING is both closed (start point equals end point) and simple (no self-intersections other than the closing coincidence).

SQL
ST_IsRing(geometry line)boolean

Combines ST_IsClosed and ST_IsSimple into a single ring-validity predicate. Input must be a LINESTRING; other types return NULL.

When would you use ST_IsRing?

Use ST_IsRing to validate linestrings before using them as polygon boundaries in ST_MakePolygon or ST_Polygon:

SQL
1SELECT id, geom
2FROM boundaries
3WHERE ST_IsRing(geom);   -- safe to use as a polygon shell

If the check fails, the input is either open or self-intersecting — the two common reasons ST_MakePolygon would later raise an error or produce invalid geometry.

FAQs

What is the difference from ST_IsClosed?

ST_IsClosed only checks that start and end points coincide. ST_IsRing additionally requires the line to be simple (no self-intersections). A figure-eight is closed but not a ring.

Can ST_IsRing be used on polygons?

No — input must be a LINESTRING. For polygons, check ST_IsValid on the polygon directly; rings are extracted with ST_ExteriorRing or ST_InteriorRingN.

What happens on a MultiLineString?

Returns NULL. Unpack with ST_GeometryN first.

Is ST_IsSimple fast?

ST_IsSimple (the component of ST_IsRing) runs O(n log n) on vertex count. Cheap for most normal data; can be noticeable on very high-vertex lines.