ST_GeomCollFromText

更新时间:
复制 MD 格式

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

Syntax

geometry ST_GeomCollFromText(text WKT, integer srid);
geometry ST_GeomCollFromText(text WKT);

Parameters

ParameterDescription
WKTThe WKT string to parse. Must represent a GeometryCollection.
sridThe SRID of the resulting geometry. Defaults to 0 if omitted.

Usage notes

  • If the WKT string does not represent a GeometryCollection, the function returns an error. If you cannot guarantee the input type, use ST_GeomFromText instead — it accepts any geometry type and skips the additional validation that makes this function slower.

Examples

SELECT ST_AsText(ST_GeomCollFromText('GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(3 4, 5 6))'));

Output:

                     st_astext
----------------------------------------------------
 GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(3 4,5 6))
(1 row)