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
| Parameter | Type | Description |
|---|---|---|
wKT | text | The WKT string representing the polygon. |
srid | integer | The 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
NULLif the WKT string does not represent a polygon (for example, aPOINTorLINESTRING).
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)该文章对您有帮助吗?