The ST_Boundary() function

The ST_Boundary() function takes a geometry object and returns its combined boundary as a geometry object.

Syntax

ST_Boundary(g1 ST_Geometry)

Return type

ST_Geometry

Example

In this example the boundary_test table is created with two columns: geotype defined as a VARCHAR, and g1 defined as the superclass ST_Geometry. The INSERT statements that follow insert each one of the subclass geometries. The ST_Boundary() function retrieves the boundary of each subclass stored in the g1 geometry column. Note that the dimension of the resulting geometry is always one less than the input geometry. Points and multipoints always result in a boundary that is an empty geometry, dimension -1. Linestrings and multilinestrings return a multipoint boundary, dimension 0. A polygon or multipolygon always returns a multilinestring boundary, dimension 1:
CREATE TABLE boundary_test (geotype varchar(20),
                            g1      ST_Geometry);

INSERT INTO boundary_test VALUES( 
   'Point', ST_PointFromText('point (10.02 20.01)',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Linestring', 
   ST_LineFromText('linestring (10.02 20.01,10.32 23.98,11.92 25.64)',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Polygon', 
   ST_PolyFromText('polygon ((10.02 20.01,11.92 35.64,25.02 34.15,19.15
   33.94, 10.02 20.01))',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Multipoint', 
   ST_MPointFromText('multipoint (10.02 20.01,10.32 23.98,11.92 25.64)',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Multilinestring', 
   ST_MLineFromText('multilinestring ((10.02 20.01,10.32 23.98,11.92 25.64), 
   (9.55 23.75,15.36 30.11))',1000) 
);

INSERT INTO boundary_test VALUES( 
   'Multipolygon', 
   ST_MPolyFromText('multipolygon (((10.02 20.01,11.92 35.64,25.02
   34.15,19.15 33.94,10.02 20.01)),((51.71 21.73,73.36 27.04,71.52 32.87,52.43
   31.90,51.71 21.73)))',1000) 
);

SELECT geotype, ST_Boundary(g1)  
   FROM boundary_test;


geotype       Point
(expression)  1000 POINT EMPTY 

geotype       Linestring
(expression)  1000 MULTIPOINT (10.02 20.01, 11.92 25.64) 

geotype       Polygon
(expression)  1000 MULTILINESTRING ((10.02 20.01, 19.15 33.94, 25.02
   34.15, 11.92 35.64, 10.02 20.01)) 

geotype       Multipoint
(expression)  1000 POINT EMPTY 

geotype       Multilinestring
(expression)  1000 MULTIPOINT (9.55 23.75, 10.02 20.01, 11.92 25.64, 15.36 30.1
              1) 

geotype       Multipolygon
(expression)  1000 MULTILINESTRING ((10.02 20.01, 19.15 33.94, 25.02 34.15,
   11.92 35.64, 10.02 20.01),(51.71 21.73, 73.36 27.04, 71.52 32.87, 52.43
   31.9, 51.71 21.73))