The ST_MAKEPOLYGON function constructs a polygon geography object from a specified shell and zero or more holes.
Syntax
GEOGRAPHY ST_MAKEPOLYGON(GEOGRAPHY <shell>[, ARRAY<GEOGRAPHY> <holes>])Parameters
shell: Required. A
linestringgeography object.holes: Optional. An
ARRAYoflinestringgeography objects.
You can use the ST_MAKELINE function to construct linestring geography objects. Note the following:
A
linestringmust contain at least three distinct vertices.A
linestringmust be closed, meaning its first and last vertex must be the same. If not, the function automatically closes thelinestringby adding a segment from the last vertex to the first.
Return value
Returns a polygon geography object. The following rules apply:
If any input argument is
NULLor the holes array contains aNULLelement, the function returnsNULL.If any input geography object is empty, the function returns an error.
The S2 Geometry Library's precision limitations may cause minor differences between the input and output.
Examples
-- Create a polygon from a shell without any holes
SELECT ST_MAKEPOLYGON(ST_GEOGFROMTEXT('LINESTRING(0 0, 1 0, 1 1)'));
-- Result:
+--------------------------------+
| _c0 |
+--------------------------------+
| POLYGON ((0 0, 1 0, 1 1, 0 0)) |
+--------------------------------+
-- Create a polygon with both a shell and a hole
SELECT ST_MAKEPOLYGON(ST_GEOGFROMTEXT('LINESTRING(0 0, 10 0, 10 10, 0 10, 0 0)'), ARRAY(ST_GEOGFROMTEXT('LINESTRING(2 2, 2 4, 4 4, 4 2, 2 2)')));
-- Result:
+--------------------------------------------------------------------+
| _c0 |
+--------------------------------------------------------------------+
| POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (4 2, 4 4, 2 4, 2 2, 4 2)) |
+--------------------------------------------------------------------+