ST_AsBinary — Return the Well-Known Binary (WKB) representation of the geometry without SRID meta data.
bytea ST_AsBinary(
geometry g1)
;
bytea ST_AsBinary(
geometry g1, text NDR_or_XDR)
;
Returns the Well-Known Binary representation of the geometry. There are 2 variants of the function. The first variant takes no endian encoding paramater and defaults to little endian. The second variant takes a second argument denoting the encoding - using little-endian ('NDR') or big-endian ('XDR') encoding.
This is useful in binary cursors to pull data out of the database without converting it to a string representation.
The WKB spec does not include the SRID. To get the OGC WKB with SRID format use ST_AsEWKB |
ST_AsBinary is the reverse of ST_GeomFromWKB. Use ST_GeomFromWKB to convert to a postgis geometry from ST_AsBinary representation. |
This method implements the OpenGIS Simple Features Implementation Specification for SQL. OGC SPEC s2.1.1.1
This method implements the SQL/MM specification: SQL-MM 3: 5.1.37
SELECT ST_AsBinary(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326)); st_asbinary -------------------------------- \001\003\000\000\000\001\000\000\000\005 \000\000\000\000\000\000\000\000\000\000 \000\000\000\000\000\000\000\000\000\000 \000\000\000\000\000\000\000\000\000\000 \000\000\000\360?\000\000\000\000\000\000 \360?\000\000\000\000\000\000\360?\000\000 \000\000\000\000\360?\000\000\000\000\000 \000\000\000\000\000\000\000\000\000\000\000 \000\000\000\000\000\000\000\000 (1 row)
SELECT ST_AsBinary(ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))',4326), 'XDR'); st_asbinary -------------------------------- \000\000\000\000\003\000\000\000\001\000\000\000\005\000\000\000\000\000 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000 \000?\360\000\000\000\000\000\000?\360\000\000\000\000\000\000?\360\000\000 \000\000\000\000?\360\000\000\000\000\000\000\000\000\000\000\000\000\000\000 \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000 (1 row)