Name

ST_AsBinary — Returns the well-known binary (WKB) representation of a Geometry object.

Synopsis

bytea ST_AsBinary(bytea Geometry);

bytea ST_AsBinary(bytea Geometry, varchar byteorder XDR/NDR);

Alias

AsBinary, ST_AsWKB, AsWKB

Description

Returns the well-known binary representation of a Geometry object.

The byteorder parameter may be either NDR or XDR. If no encoding is specified, the default value is NDR.

NDR indicates Network Data Representation, also known as little-endian encoding.

XDR represents External Data Representation, also known as big-endian encoding.

[Caution]

The WKB format, doesn't store the SRID. For that, use EWKB format

[Note]

The reverse function is ST_GeomFromEWKB

Coordinate Dimensions
2D3DM
Spatial Standards Support
OGC SFS for SQL. 1.1 (1999)OGC SFS for SQL. 1.1.0 (2005)OGC SFS for SQL. 1.2.0 (2006)SQL-MM Part 3
2.1.1.17.2.9.17.2.8.15.1.37

Examples

PostgreSQL
--Get the WKB
SELECT ST_AsBinary(ST_GeomFromText('POINT(5 5 10)',25830));

                                 st_asbinary
-----------------------------------------------------------------------------------
 \001\001\000\000\200\000\000\000\000\000\000\024@\000\000\000\000\000\000\024@\000\000\000\000\000\000$@
(1 row)

SELECT ST_AsBinary(ST_GeomFromText('POINT(5 5 10)'),'XDR');
                                               st_asbinary                                                
----------------------------------------------------------------------------------------------------------
 \000\200\000\000\001@\024\000\000\000\000\000\000@\024\000\000\000\000\000\000@$\000\000\000\000\000\000
(1 row)

SELECT ST_AsBinary(ST_GeomFromText('POINT(5 5 10)'),'NDR');
                                               st_asbinary                                                
----------------------------------------------------------------------------------------------------------
 \001\001\000\000\200\000\000\000\000\000\000\024@\000\000\000\000\000\000\024@\000\000\000\000\000\000$@
(1 row)
H2
SELECT ST_AsBinary(ST_GeomFromText('POINT(1 1 1)',25830));
0101000080000000000000f03f000000000000f03f000000000000f03f

SELECT ST_AsBinary(ST_GeomFromText('POINT(1 1 1)'),'XDR');
00800000013ff00000000000003ff00000000000003ff0000000000000

SELECT ST_AsBinary(ST_GeomFromText('POINT(1 1 1)'),'NDR');
0101000080000000000000f03f000000000000f03f000000000000f03f

Related functions

ST_AsEWKB, ST_GeomFromWKB