ST_AsBinary

更新时间:
复制 MD 格式

Returns the Well-Known Binary (WKB) representation of a geometry or geography object. The output does not include spatial reference identifier (SRID) metadata.

Syntax

bytea ST_AsBinary(geometry g1);
bytea ST_AsBinary(geometry g1, text NDRorXDR);
bytea ST_AsBinary(geography g1);
bytea ST_AsBinary(geography g1, text NDRorXDR);

Parameters

ParameterDescription
g1The geometry or geography object to convert to WKB.
NDRorXDRThe byte order of the output. Valid values: NDR (little endian, default) and XDR (big endian).

Usage notes

  • Standard WKB does not include SRID metadata. To get a WKB representation with the SRID embedded, use ST_AsEWKB instead.

  • Supported geometry types include circular strings, curves, polyhedral surfaces, triangles, triangulated irregular network (TIN) surfaces, and 3D objects.

Examples

Return WKB with the default little endian byte order

SELECT ST_AsBinary(ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))',4326));
                          st_asbinary
---------------------------------------------------------------
 \x01030000000100000005000000000000000000f03f000000000000f03f0
.00000000000f03f0000000000000040000000000000004000000000000000
.400000000000000040000000000000f03f000000000000f03f00000000000
.0f03f
(1 row)

Return WKB with big endian byte order

SELECT ST_AsBinary(ST_GeomFromText('POLYGON((1 1,1 2,2 2,2 1,1 1))',4326),'XDR');
                          st_asbinary
---------------------------------------------------------------
 \x000000000300000001000000053ff00000000000003ff00000000000003
.ff00000000000004000000000000000400000000000000040000000000000
.0040000000000000003ff00000000000003ff00000000000003ff00000000
.00000
(1 row)

What's next

  • ST_AsEWKB — returns WKB with the SRID included