This topic describes the ST_AsText function. This function returns the Well-Known Text (WKT) string that represents a geometry object or a geography object. The WKT string that is returned does not contain 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 object or geography object whose WKT representation you want to obtain.
maxdecimaldigits The maximum number of decimal places that you want to retain. Default value: 15.

Description

  • If you want to obtain a WKT string that contains an SRID, we recommend that you use the ST_AsEWKT function.
  • The WKT format cannot ensure precision. If you want to prevent floating-point numbers of a specific decision from being truncated, we recommend that you use the ST_AsBinary function or the ST_AsEWKB function.

Examples

  • Obtain a WKT string with the default parameter settings retained.
    SELECT ST_AsText(ST_GeomFromText('POINT(116 40)',4326));
       st_astext
    ---------------
     POINT(116 40)
    (1 row)
  • Obtain a WKT string with the number of decimal places specified.
    SELECT ST_AsText(ST_GeomFromText('POINT(116.112 40.412)',4326),2);
          st_astext
    ---------------------
     POINT(116.11 40.41)
    (1 row)