Name

ST_Polygon — Creates a Polygon from a closed LineString and SRID.

Synopsis

geometry ST_Polygon(varchar LineString, integer SRID);

Alias

Polygon

Description

Creates a Polygon from a closed LineString given the Spatial Reference System ID (SRID).

If the incoming object is not a LineString or it is not closed throws an error.

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
---8.3.2

Examples

--Return 
SELECT ST_Asewkt(ST_Polygon(ST_GeomFromText('LINESTRING (0 0, 0 150, 150 150, 150 0, 0 0)'),-1));

--Result
POLYGON ((0 0, 0 150, 150 150, 150 0, 0 0))

--Not a closed LineString
SELECT ST_Asewkt(ST_Polygon(ST_GeomFromText('LINESTRING (0 0, 0 150, 150 0, 15 0)'),-1));

--Result, throws an error
ERROR:  java.lang.IllegalArgumentException: Points of LinearRing do not form a closed linestring

Related functions

ST_MakePolygon