PostGISGeometry Accessors

ST_IsClosed

What is ST_IsClosed?

ST_IsClosed is a PostGIS function that returns true when a LINESTRING or MULTILINESTRING is closed — that is, its start and end points coincide exactly. For MULTILINESTRING, every component must be closed for the result to be true.

SQL
ST_IsClosed(geometry g)boolean

Also supported on POLYHEDRALSURFACE and TIN for surface-closed checks. Does not check ring validity — use ST_IsRing for the stricter test that combines closed with simple.

When would you use ST_IsClosed?

Use ST_IsClosed to validate input before building polygons from linestrings with ST_MakePolygon, or to separate closed loops from open paths in network datasets:

SQL
1SELECT id, geom
2FROM raw_linework
3WHERE NOT ST_IsClosed(geom);   -- open paths need review

It is also the standard test before treating a line as a conceptual ring in topological analyses.

FAQs

How strict is the equality?

Coordinate-exact. Near-closed rings with a tiny numeric gap return false. Close explicitly with ST_AddPoint(line, ST_StartPoint(line)) if your data has rounding drift.

Does ST_IsClosed accept polygons?

Polygons are implicitly closed — calling ST_IsClosed on a polygon typically returns true, but the semantically correct check for polygon rings is ST_IsValid.

What is the difference from ST_IsRing?

ST_IsRing is ST_IsClosed AND ST_IsSimple — a closed non-self-intersecting line. ST_IsClosed alone permits self-intersecting closed lines.

Are Z and M considered in the equality check?

Yes. The full coordinate tuple must match for the endpoints to count as coincident. A line that returns to the same X/Y but with a different Z is not closed.