ST_InteriorRingN function

The ST_InteriorRingN function takes a polygon and an index as input parameters and returns the interior ring identified by the specified index as a linestring. The interior rings are organized according to the rules defined by the internal geometry verification routines.

If the specified polygon is null or is empty, or if it does not have any interior rings, then null is returned. If the index is smaller than 1 or larger than the number of interior rings in the polygon, then null is returned and a warning condition is raised (1HS1).

Syntax

Read syntax diagramSkip visual syntax diagramST_InteriorRingN(polygon,index )

Parameter

polygon
A value of type ST_Polygon that represents the geometry from which the interior ring identified by index is returned.
index
A value of type INTEGER that identifies the nthe interior ring that is returned. If there is no interior ring identified by index, then a warning condition is raised (01HS1).

Return type

ST_Curve

Example

In this example, a polygon is created with two interior rings. The ST_InteriorRingN call is then used to retrieve the second interior ring.

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))

SELECT id, CAST(ST_AsText(ST_InteriorRingN(geometry, 2)) as VARCHAR(100))  
       Interior_Ring
FROM sample_polys

Results:

ID          INTERIOR_RING
----------- ------------------------------------------------------------------
          1 LINESTRING (50 130, 50 140, 60 140, 60 130, 50 130) 
 

Note that in this example, the verification routines have changed the sequence of the rings during the insert operation.


SELECT id, SUBSTR(ST_AsText(geometry),1,180) as POLYGON
FROM sample_polys

ID          POLYGON
----------- ------------------------------------------------------------------
          1 POLYGON ((40 120, 90 120, 90 150, 40 150, 40 120),
                    (70 130, 70 140, 80 140, 80 130, 70 130),
                    (50 130, 50 140, 60 140, 60 130, 50 130))