PostGIS

ST_Polygon

Prev

8.3. Geometry Constructors

Next

Name

ST_Polygon — Creates a Polygon from a LineString with a specified SRID.

Synopsis

geometry +`*`+ST_Polygon*(`geometry `lineString, integer srid`)`;

Description

Returns a polygon built from the given LineString and sets the spatial reference system from the srid.

ST_Polygon is similar to ST_MakePolygon Variant 1 with the addition of setting the SRID.

To create polygons with holes use ST_MakePolygon Variant 2 and then ST_SetSRID.

Note

This function does not accept MultiLineStrings. Use ST_LineMerge to generate a LineString, or ST_Dump to extract LineStrings.

[.inlinemediaobject]check This method implements the OGC Simple Features Implementation Specification for SQL 1.1.

check This method implements the SQL/MM specification. SQL-MM 3: 8.3.2

check This function supports 3d and will not drop the z-index.

Examples

Create a 2D polygon.

SELECT ST_AsText( ST_Polygon('LINESTRING(75 29, 77 29, 77 29, 75 29)'::geometry, 4326) );

-- result --
POLYGON((75 29, 77 29, 77 29, 75 29))

Create a 3D polygon.

SELECT ST_AsEWKT( ST_Polygon( ST_GeomFromEWKT('LINESTRING(75 29 1, 77 29 2, 77 29 3, 75 29 1)'), 4326) );

-- result --
SRID=4326;POLYGON((75 29 1, 77 29 2, 77 29 3, 75 29 1))