ST_PolygonN function

The ST_PolygonN function takes a multipolygon and an index as input parameters and returns the polygon that is identified by the index. The resulting polygon is represented in the spatial reference system of the given multipolygon.

If the given multipolygon is null or is empty, or if the index is smaller than 1 or larger than the number of polygons, then null is returned.

This function can also be called as a method.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_PolygonN(multipolygon,index )

Parameters

multipolygon
A value of type ST_MultiPolygon that represents the multipolygon from which the polygon that is identified by index is returned.
index
A value of type INTEGER that identifies the nth polygon that is to be returned from multipolygon.

Return type

db2gse.ST_Polygon

Example

In the following example, the lines of results have been reformatted for readability. The spacing in your results will vary according to your online display

This example illustrates the use of ST_PolygonN.
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_mpolys (id INTEGER, geometry ST_MultiPolygon)

INSERT INTO sample_mpolys
  VALUES (1, ST_Polygon ('multipolygon (((3 3, 4 6, 5 3, 3 3),
                                         (8 24, 9 25, 1 28, 8 24)
                                         (13 33, 7 36, 1 40, 10 43, 
                                          13 33)))', 1))

SELECT id, CAST ( ST_AsText (ST_PolygonN (geometry, 2) ) 
    AS VARCHAR(120) ) SECOND_INDEX
FROM sample_mpolys
Results:

ID        SECOND_INDEX
--------- -----------------------------------------------------------
        1 POLYGON (( 8.00000000 24.00000000, 9.00000000 25.00000000,
                     1.00000000 28.00000000, 8.00000000 24.00000000))