Returns the Well-Known Binary (WKB) string that represents a geometry or geography object. Unlike standard WKB, the output includes the spatial reference identifier (SRID).
Syntax
bytea ST_AsEWKB(geometry g1);
bytea ST_AsEWKB(geometry g1, text NDRorXDR);
bytea ST_AsEWKB(geography g1);
bytea ST_AsEWKB(geography g1, text NDRorXDR);Parameters
| Parameter | Description |
|---|---|
g1 | The geometry or geography object to convert. |
NDRorXDR | The byte order of the output. Valid values: XDR (big endian), NDR (little endian). Default value: NDR. |
Usage notes
The WKB specification does not include SRIDs in standard WKB output. Use
ST_AsEWKBwhen you need a binary representation that embeds the SRID.Supports circular strings, curves, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.
Examples
Return EWKB with the default little endian (NDR) byte order:
SELECT ST_AsEWKB(ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))',4326));Output:
st_asewkb
---------------------------------------------------------------
\x0103000020e61000000100000005000000000000000000f03f000000000.
.000f03f000000000000f03f00000000000000400000000000000040000000.
.00000000400000000000000040000000000000f03f000000000000f03f000.
.000000000f03f
(1 row)Return EWKB with big endian (XDR) byte order:
SELECT ST_AsEWKB(ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))',4326),'XDR');Output:
st_asewkb
---------------------------------------------------------------
\x0020000003000010e600000001000000053ff00000000000003ff000000.
.00000003ff000000000000040000000000000004000000000000000400000.
.000000000040000000000000003ff00000000000003ff00000000000003ff.
.0000000000000
(1 row)