Returns the Well-Known Text (WKT) representation of a geometry or geography object. The returned string does not include Spatial Reference Identifier (SRID) metadata.
Syntax
text ST_AsText(geometry g1);
text ST_AsText(geometry g1, integer maxdecimaldigits);
text ST_AsText(geography g1);
text ST_AsText(geography g1, integer maxdecimaldigits);Parameters
| Parameter | Description |
|---|---|
g1 | The geometry or geography object to convert to WKT. |
maxdecimaldigits | The maximum number of decimal places to retain in the output. Default value: 15. |
Usage notes
To include SRID metadata in the output, use ST_AsEWKT instead.
WKT format does not guarantee full floating-point precision. To avoid truncation, use ST_AsBinary or ST_AsEWKB.
Examples
Return WKT with default precision
SELECT ST_AsText(ST_GeomFromText('POINT(116 40)',4326));
st_astext
---------------
POINT(116 40)
(1 row)Return WKT with a specified number of decimal places
SELECT ST_AsText(ST_GeomFromText('POINT(116.112 40.412)',4326),2);
st_astext
---------------------
POINT(116.11 40.41)
(1 row)该文章对您有帮助吗?