ST_Polygon
If the geometry-expression is of type ST_Polygon, returns the geometry-expression.
If the geometry-expression is of type ST_CurvePolygon, returns geometry-expression.ST_CurvePolyToPoly().
If the geometry-expression is a geometry collection with a single element of type ST_CurvePolygon, returns that element.
If the geometry-expression is the empty set, returns an empty set of type ST_Polygon.
Otherwise, raises an exception condition.
The spatial reference system identifier of the result is the same as the spatial reference system of the geometry-expression.
Convert the geometry to a polygon.
The logic is equivalent to that used for CAST(geometry-expressionAS ST_Polygon ).
If the geometry-expression is a curve polygon, it is approximated using ST_CurvePolyToPoly().
If geometry-expression is already known to be an ST_Polygon value, it is more
efficient to use TREAT( geometry-expression AS ST_Polygon ) than the
ST_ToPolygon method.
The following example returns the result Polygon EMPTY.
SELECT NEW ST_GeomCollection().ST_ToPolygon().ST_AsText()
The following returns an error because the Shape column is of type
ST_Geometry and ST_Geometry does not support the ST_Area method.
SELECT Shape.ST_Area()
FROM SpatialShapes WHERE ShapeID = 22
The following uses ST_ToPolygon to change the type
of the Shape column expression to ST_Polygon. ST_Area returns the result 12.5.
SELECT Shape.ST_ToPolygon().ST_Area()
FROM SpatialShapes WHERE ShapeID = 22
In this case, the value of the Shape column is known be of type
ST_Polygon, so TREAT can be used to efficiently change the type
of the expression. ST_Area returns the result 12.5.
SELECT TREAT( Shape AS ST_Polygon ).ST_Area()
FROM SpatialShapes WHERE ShapeID = 22