PostGISGeometry Accessors

ST_Boundary

What is ST_Boundary?

ST_Boundary is a PostGIS function that returns the OGC-defined boundary of a geometry — the set of points that separate the interior from the exterior, always one topological dimension lower than the input.

SQL
ST_Boundary(geometry g)geometry

For a polygon the boundary is a (multi)linestring around the rings. For a linestring it is a multipoint of its endpoints. For a point the boundary is an empty geometry. The SRID of the input is preserved.

When would you use ST_Boundary?

Use ST_Boundary when you need the ring(s) of a polygon as a line geometry — for rendering outlines, computing perimeter length, or performing line-based spatial joins against polygon features:

SQL
1SELECT id, ST_Length(ST_Boundary(geom)) AS perimeter_m
2FROM parcels;

It is also handy for extracting the endpoints of a linestring in one call (ST_Boundary(line) returns a MULTIPOINT with both endpoints), and for constructing rings that can be clipped, buffered, or intersected.

FAQs

What does ST_Boundary return for a closed linestring?

The boundary of a closed linestring is empty — because the start and end points coincide, there is no topological boundary. Use ST_StartPoint/ST_EndPoint if you still need the coordinate pair.

How is ST_Boundary different from ST_ExteriorRing?

ST_ExteriorRing returns only the outer ring of a polygon as a LINESTRING. ST_Boundary returns all rings (exterior plus interior holes) as a MULTILINESTRING for polygons with holes.

Can ST_Boundary be used on a MultiPolygon?

Yes. The boundary of a multipolygon is a multilinestring containing the rings of every component polygon, including holes.

Does ST_Boundary preserve Z and M values?

Yes, Z and M values on vertices are preserved. The boundary of a 3D polygon is a 3D linestring tracing its rings.