ST_Polygon

更新时间:
复制 MD 格式

Constructs a polygon from a LineString and a spatial reference identifier (SRID).

Syntax

geometry ST_Polygon(geometry aLineString, integer srid);

Parameters

ParameterDescription
aLineStringThe LineString object that you want to specify.
sridThe SRID to assign to the returned polygon.

Usage notes

ST_Polygon does not accept MultiLineString inputs. To build a polygon from a MultiLineString, use ST_LineMerge to merge it into a single LineString.
  • To construct a polygon with holes, use ST_MakePolygon instead.

  • ST_Polygon supports 3D geometries and preserves the Z coordinate of the input geometry.

Examples

Create a 2D polygon.

SELECT ST_AsEWKT(ST_Polygon(ST_GeomFromText('LINESTRING(1 2,3 4,5 6,1 2)'), 4326));

Output:

              st_asewkt
--------------------------------------
 SRID=4326;POLYGON((1 2,3 4,5 6,1 2))
(1 row)

See also

  • ST_AsEWKT — converts a geometry to EWKT format

  • ST_GeomFromText — constructs a geometry from a WKT string

  • ST_LineMerge — merges a MultiLineString into a single LineString

  • ST_MakePolygon — constructs a polygon with optional interior rings (holes)