ST_TOMULTIPOLYGON scalar function
The ST_TOMULTIPOLYGON function takes a geometry as an input parameter and converts it to a multipolygon.
The specified geometry must be a polygon or a multipolygon.
If geometry is null, the result is the null value. An empty multipolygon is not supported.
- geometry
- A value of type ST_GEOMETRY or one of its subtypes that represents the geometry that is converted to a multipolygon.
The result of the function is ST_MULTIPOLYGON.
Example
This example creates several geometries and then uses ST_TOMULTIPOLYGON to return multipolygons.
CREATE TABLE sample_geometries (id INTEGER, geometry QSYS2.ST_GEOMETRY);
CREATE TABLE sample_multipolygons (id INTEGER, multipolygon QSYS2.ST_MULTIPOLYGON);
INSERT INTO sample_geometries
VALUES (1, QSYS2.ST_MULTIPOLYGON('multipolygon (((0 0, 0 4, 5 4, 5 0, 0 0)),
((10 10, 10 15, 13 17, 10 10)))')),
(2, QSYS2.ST_POLYGON('polygon ((0 0, 0 4, 5 4, 5 0, 0 0))'));
INSERT INTO sample_multipolygons
(SELECT ID, QSYS2.ST_TOMULTIPOLYGON(geometry)
FROM sample_geometries);
SELECT id, QSYS2.ST_ASTEXT(multipolygon) AS multipolygons FROM sample_multipolygons;
Results:
ID MULTIPOLYGONS
------- ------------------------------------------------------------------------
1 MULTIPOLYGON (((10.0 10.0, 13.0 17.0, 10.0 15.0, 10.0 10.0)),
((0.0 0.0, 5.0 0.0, 5.0 4.0, 0.0 4.0, 0.0 0.0)))
2 MULTIPOLYGON (((0.0 0.0, 5.0 0.0, 5.0 4.0, 0.0 4.0, 0.0 0.0)))