Returns the Well-Known Text (WKT) representation of a geometry or geography object. The output does not include spatial reference identifier (SRID) metadata.
To parse a WKT string back into a geometry object, use ST_GeomFromText.
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 in the output. Default value: 15. |
Usage notes
The returned WKT string does not include the SRID. To include SRID metadata in the output, use ST_AsEWKT.
Warning
WKT does not guarantee floating-point precision. To preserve full precision for storage or transport, use ST_AsBinary or ST_AsEWKB.
Examples
Use the default precision
SELECT ST_AsText(ST_GeomFromText('POINT(116 40)',4326)); st_astext
---------------
POINT(116 40)
(1 row)Limit decimal places
Pass a value for maxdecimaldigits to round coordinates to the 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)What's next
ST_AsEWKT — returns WKT with SRID metadata
ST_AsBinary — returns WKB without SRID
ST_AsEWKB — returns WKB with SRID