ST_AsEWKT returns the Extended Well-Known Text (EWKT) representation of a geometry or geography object. Unlike ST_AsText, the output includes the spatial reference identifier (SRID) as a prefix.
Syntax
text ST_AsEWKT(geometry g1);
text ST_AsEWKT(geography g1);Parameters
| Parameter | Description |
|---|---|
g1 | The geometry or geography object to convert. |
Usage notes
Warning
WKT format may truncate floating-point coordinates. To preserve full precision, use ST_AsBinary or ST_AsEWKB instead.
Note
To get standard WKT output without an SRID prefix, use ST_AsText.
Supported geometry types: circular strings, curves, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.
Examples
Return a WKT string that includes an SRID.
SELECT ST_AsEWKT(ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))',4326));Output:
st_asewkt
------------------------------------------
SRID=4326;POLYGON((1 1,1 2,2 2,2 1,1 1))
(1 row)Return a WKT string without an SRID (when the geometry has no SRID assigned).
SELECT ST_AsEWKT(ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))'));Output:
st_asewkt
--------------------------------
POLYGON((1 1,1 2,2 2,2 1,1 1))
(1 row)