ST_ExteriorRing

Name

ST_ExteriorRing — Returns a LineString representing the exterior ring of a Polygon.

Synopsis

geometry ST_ExteriorRing ( geometry a_polygon ) ;

Description

Returns a LINESTRING representing the exterior ring (shell) of a POLYGON. Returns NULL if the geometry is not a polygon.

[Note]

This function does not support MULTIPOLYGONs. For MULTIPOLYGONs use in conjunction with ST_GeometryN or ST_Dump

This method implements the OGC Simple Features Implementation Specification for SQL 1.1.

2.1.5.1

This method implements the SQL/MM specification.

SQL-MM 3: 8.2.3, 8.3.3

This function supports 3d and will not drop the z-index.

Examples

--If you have a table of polygons
SELECT gid, ST_ExteriorRing(geom) AS ering
FROM sometable;

--If you have a table of MULTIPOLYGONs
--and want to return a MULTILINESTRING composed of the exterior rings of each polygon
SELECT gid, ST_Collect(ST_ExteriorRing(geom)) AS erings
	FROM (SELECT gid, (ST_Dump(geom)).geom As geom
			FROM sometable) As foo
GROUP BY gid;

--3d Example
SELECT ST_AsEWKT(
	ST_ExteriorRing(
	ST_GeomFromEWKT('POLYGON((0 0 1, 1 1 1, 1 2 1, 1 1 1, 0 0 1))')
	)
);

st_asewkt
---------
LINESTRING(0 0 1,1 1 1,1 2 1,1 1 1,0 0 1)