ST_BdPolyFromText

更新时间:
复制 MD 格式

Constructs a polygon from one or more closed linestrings represented as a Well-Known Text (WKT) string.

Syntax

geometry ST_BdPolyFromText(text WKT, integer srid);

Parameters

ParameterDescription
WKTThe WKT string that you want to specify.
sridThe spatial reference identifier (SRID) of the resulting polygon.

Usage notes

Note: The WKT string must represent a MultiLineString. Passing any other geometry type returns an error.
Note: If the WKT string produces a MultiPolygon, the function returns an error. To build a MultiPolygon, use ST_BdMPolyFromText. For a more flexible approach that handles both single polygons and MultiPolygons, use ST_BuildArea.

Example

Convert a MultiLineString WKT string into a polygon.

SELECT ST_AsText(
  ST_BdPolyFromText(
    ST_AsText(ST_GeomFromText('MultiLineString((1 1,1 2),(2 2,1 1),(1 2,2 2))')),
    4326
  )
);

Output:

        st_astext
----------------------------
 POLYGON((1 1,1 2,2 2,1 1))
(1 row)