ST_MakePolygon

更新时间:
复制 MD 格式

Constructs a polygon from a closed LineString that defines the exterior ring, with an optional array of closed LineStrings that define interior rings (holes).

Syntax

geometry ST_MakePolygon(geometry linestring);
geometry ST_MakePolygon(geometry outerlinestring, geometry[] interiorlinestrings);

Parameters

ParameterDescription
linestringThe closed LineString that defines the exterior ring of the polygon.
outerlinestringThe closed LineString that defines the exterior ring of the polygon.
interiorlinestringsAn array of closed LineStrings, each defining an interior ring (hole) of the polygon.

Usage notes

Both linestring and each element of interiorlinestrings must be a closed LineString — the start and end points must be identical.

Examples

Construct a polygon from a single closed LineString:

SELECT ST_AsText(ST_MakePolygon(ST_GeomFromText('LINESTRING(1 2,3 4,5 6,1 2)')));
         st_astext
----------------------------
 POLYGON((1 2,3 4,5 6,1 2))
(1 row)

Construct a polygon with an interior ring:

SELECT ST_AsText(ST_MakePolygon(ST_GeomFromText('LINESTRING(0 0,0 1,1 1,0 0)'),ARRAY[ST_GeomFromText('LINESTRING(-1 -1,-1 2,2 2,-1 -1)')]));
                     st_astext
---------------------------------------------------
 POLYGON((0 0,0 1,1 1,0 0),(-1 -1,-1 2,2 2,-1 -1))
(1 row)