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
| Parameter | Description |
|---|---|
linestring | The closed LineString that defines the exterior ring of the polygon. |
outerlinestring | The closed LineString that defines the exterior ring of the polygon. |
interiorlinestrings | An 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)该文章对您有帮助吗?