Returns a LineString representing the exterior ring of a polygon.
Syntax
geometry ST_ExteriorRing(geometry aPolygon);Parameters
| Parameter | Description |
|---|---|
aPolygon | The input polygon geometry. |
Return type
geometry of subtype LineString.
If
aPolygonis not specified, the function returns NULL.Z coordinates are preserved. The function supports 3D geometries.
Examples
Basic example
Extract the exterior ring from a polygon with a hole:
SELECT ST_AsText(ST_ExteriorRing('POLYGON((1 0,3 0,0 3,1 0),(1 0,2 0,0 2,1 0))'::geometry));Output:
st_astext
-----------------------------
LINESTRING(1 0,3 0,0 3,1 0)
(1 row)The inner ring (hole) is ignored. Only the outer boundary is returned.
Query a table of polygons
SELECT gid, ST_ExteriorRing(geom) AS exterior_ring
FROM my_polygons;3D polygon
Z coordinates are retained in the output:
SELECT ST_AsEWKT(
ST_ExteriorRing(
'POLYGON((0 0 1,1 1 1,1 2 1,0 0 1))'::geometry
)
);Output:
st_asewkt
-------------------------------------
LINESTRING(0 0 1,1 1 1,1 2 1,0 0 1)
(1 row)