Constructs a geometry object from a Well-Known Text (WKT) string, with an optional spatial reference identifier (SRID).
Syntax
geometry ST_GeomFromText(text WKT);
geometry ST_GeomFromText(text WKT, integer srid);Parameters
| Parameter | Type | Description |
|---|---|---|
WKT | text | A WKT string representing the geometry to construct. |
srid | integer | The SRID to assign to the geometry object. |
Description
ST_GeomFromText has two variants:
Without SRID: Returns a geometry object with no spatial reference system assigned.
With SRID: Returns a geometry object with the specified SRID embedded in its metadata.
The function supports circular strings and curves.
Examples
Construct a point without an SRID
SELECT ST_GeomFromText('POINT(116 40)');Output:
st_geomfromtext
--------------------------------------------
01010000000000000000005D400000000000004440
(1 row)Construct a point with an SRID
SELECT ST_GeomFromText('POINT(116 40)', 4326);Output:
st_geomfromtext
----------------------------------------------------
0101000020E61000000000000000005D400000000000004440
(1 row)该文章对您有帮助吗?