ST_ExteriorRing function
The ST_ExteriorRing function takes a polygon as an input parameter and returns its exterior ring as a curve. The resulting curve is represented in the spatial reference system of the specified polygon.
If the specified polygon is null or is empty, then null is returned. If the polygon does not have any interior rings, the returned exterior ring is identical to the boundary of the polygon.
Syntax
Parameter
- polygon
- A value of type ST_Polygon that represents the polygon for which the exterior ring is to be returned.
Return type
ST_Curve
Example
In the following examples, the lines of results have been reformatted for readability. The spacing in your results will vary according to your online display.
This
example creates two polygons, one with two interior rings and one
with no interior rings, then it determines their exterior rings.
CREATE TABLE sample_polys (id INTEGER, geometry ST_Polygon)
INSERT INTO sample_polys VALUES
(1, ST_Polygon('polygon((40 120, 90 120, 90 150, 40 150, 40 120),
(50 130, 60 130, 60 140, 50 140, 50 130),
(70 130, 80 130, 80 140, 70 140, 70 130))' ,0))
INSERT INTO sample_polys VALUES
(2, ST_Polygon('polygon((10 10, 50 10, 10 30, 10 10))' ,0))
SELECT id, CAST(ST_AsText(ST_ExteriorRing(geometry))
AS VARCHAR(100)) Exterior_Ring
FROM sample_polys
Results:
ID EXTERIOR_RING
----------- ----------------------------------------------------------------
1 LINESTRING (40 120, 90 120, 90 150, 40 150, 40 120)
2 LINESTRING (10 10, 50 10, 10 30, 10 10)