ST_ToMultiPolygon function

The ST_ToMultiPolygon function takes a geometry as an input parameter and converts it to a multipolygon. The resulting multipolygon is represented in the spatial reference system of the given geometry.

The given geometry must be empty, a polygon, or a multipolygon. If the given geometry is null, then null is returned.

This function can also be called as a method.

Syntax

Read syntax diagramSkip visual syntax diagramdb2gse.ST_ToMultiPolygon(geometry)

Parameter

geometry
A value of type ST_Geometry or one of its subtypes that represents the geometry that is converted to a multipolygon.

A geometry can be converted to a multipolygon if it is empty, a polygon, or a multipolygon. If the conversion cannot be performed, then an exception condition is raised (SQLSTATE 38SUD).

Return type

db2gse.ST_MultiPolygon

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 creates several geometries and then uses ST_ToMultiPolygon to return multipolygons.

SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_geometries (id INTEGER, geometry ST_Geometry)

INSERT INTO sample_geometries
  VALUES (1, ST_Geometry ('polygon ((0 0, 0 4, 5 4, 5 0, 0 0))', 1)),
         (2, ST_Geometry ('point empty', 1)),
         (3, ST_Geometry ('multipoint empty', 1))
In the following SELECT statement, the ST_ToMultiPolygon function is used to return multipolygons converted to ST_MultiPolygon from the static type of ST_Geometry.

SELECT CAST( ST_AsText( ST_ToMultiPolygon(geometry) ) 
  AS VARCHAR(130) ) POLYGONS
  FROM sample_geometries
Results:

POLYGONS
------------------------------------------------------------------------
MULTIPOLYGON (( 0.00000000 0.00000000, 5.00000000 0.00000000,
                5.00000000 4.00000000, 0.00000000 4.00000000,
                 0.00000000 0.00000000))

MULTIPOLYGON EMPTY

MULTIPOLYGON EMPTY