ST_ToPolygon takes a geometry as an input parameter and converts it to a polygon. The resulting polygon is represented in the spatial reference system of the given geometry.
The given geometry must be empty or a polygon. If the given geometry is null, then null is returned.
This function can also be called as a method.
A geometry can be converted to a polygon if it is empty or a polygon. If the conversion cannot be performed, then an exception condition is raised (SQLSTATE 38SUD).
db2gse.ST_Polygon
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
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 ('multipolygon empty', 1) )
In the following SELECT statement, the ST_ToPolygon function
is used to return polygons converted to ST_Polygon from the static
type of ST_Geometry. SELECT CAST( ST_AsText( ST_ToPolygon(geometry) ) AS VARCHAR(130) ) POLYGONS
FROM sample_geometries
Results: POLYGONS
-------------------------------------------------------------------------------
POLYGON (( 0.00000000 0.00000000, 5.00000000 0.00000000,
5.00000000 4.00000000,0.00000000 4.00000000,
0.00000000 0.00000000))
POLYGON EMPTY
POLYGON EMPTY