ST_MPolyFromText

更新时间:
复制 MD 格式

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

Syntax

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

Parameters

ParameterDescription
wKTThe WKT string representing a MultiPolygon geometry.
sridThe SRID of the MultiPolygon object. If omitted, defaults to 0.

Usage notes

  • If the WKT string does not represent a MultiPolygon, the function returns NULL.

  • If you know the input is valid MultiPolygon data, use ST_GeomFromText instead. It constructs a geometry object without the extra type-check overhead, so it runs faster.

Examples

Construct a MultiPolygon from a WKT string and return its text representation:

SELECT ST_AsText(ST_MPolyFromText('MULTIPOLYGON(((0 0,1 0,1 1,0 0),(1 1,2 1,2 2,1 1)))'));

Output:

                      st_astext
-----------------------------------------------------
 MULTIPOLYGON(((0 0,1 0,1 1,0 0),(1 1,2 1,2 2,1 1)))
(1 row)