Fork me on GitHub

ST_ExteriorRing

Signature

LINEARRING ST_ExteriorRing(GEOMETRY geom);

Description

Returns the exterior ring of geom as a LINEARRING, or NULL if geom is not a POLYGON.

This function does not work on MULTIPOLYGONs.
Implements the OpenGIS Simple Features Implementation Specification for SQL version 1.2.1.

Examples

SELECT ST_ExteriorRing('POLYGON((0 -1, 0 2, 3 2, 3 -1, 0 -1))');
-- Answer: LINEARRING(0 -1, 0 2, 3 2, 3 -1, 0 -1)

SELECT ST_ExteriorRing('MULTIPOLYGON(((0 0, 10 0, 5 5, 0 0)),
                                      ((10 0, 5 5, 10 10, 10 0)))');
-- Answer: NULL

SELECT ST_ExteriorRing('POINT(1 2)');
-- Answer: NULL
Comparison with ST_InteriorRingN
SELECT ST_ExteriorRing('POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),
                                (1 1, 2 1, 2 5, 1 5, 1 1),
                                (8 5, 8 4, 9 4, 9 5, 8 5))') ER,
       ST_InteriorRingN('POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),
                                (1 1, 2 1, 2 5, 1 5, 1 1),
                                (8 5, 8 4, 9 4, 9 5, 8 5))', 2) IRN;

-- Answer:
-- |             ER              |            IRN               |
-- |-----------------------------|------------------------------|
-- | LINEARRING(0 0, 10 0, 10 6, |   LINEARRING(8 5, 8 4, 9 4,  |
-- |            0 6, 0 0)        |              9 5, 8 5)       |

Comparison with ST_Boundary
SELECT ST_ExteriorRing('POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),
                                (1 1, 2 1, 2 5, 1 5, 1 1))') ER,
       ST_Boundary('POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),
                             (1 1, 2 1, 2 5, 1 5, 1 1))') BDRY;
-- Answer:
-- |              ER             |            BDRY              |
-- |-----------------------------|------------------------------|
-- | LINEARRING(0 0, 10 0, 10 6, | MULTILINESTRING(             |
-- |            0 6, 0 0)        | (0 0, 10 0, 10 6, 0 6, 0 0), |
-- |                             | (1 1, 2 1, 2 5, 1 5, 1 1))   |

See also