ST_AsText

更新时间:
复制 MD 格式

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

ParameterDescription
g1The geometry or geography object to convert to WKT.
maxdecimaldigitsThe 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)