ST_PolygonFromText

更新时间:
复制 MD 格式

Constructs a polygon geometry from a Well-Known Text (WKT) string and an optional spatial reference identifier (SRID).

If you know the WKT string represents a polygon, use ST_GeomFromText instead. ST_GeomFromText is faster because no unnecessary checks are required.

Syntax

geometry ST_PolygonFromText(text wKT);
geometry ST_PolygonFromText(text wKT, integer srid);

Parameters

ParameterTypeDescription
wKTtextThe WKT string representing the polygon.
sridintegerThe SRID of the polygon. Defaults to 0 if not specified.

Return behavior

  • Returns a geometry object if the WKT string represents a valid polygon.

  • Returns NULL if the WKT string does not represent a polygon (for example, a POINT or LINESTRING).

Examples

Construct a polygon with SRID 4326:

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