ST_GeomFromWKB — Construct a geometric object given its Well-known Binary Representation
geometry ST_GeomFromWKB(bytea WKB, integer
SRID);
geometry ST_GeomFromWKB(bytea WKB);
The GeomFromWKB function takes a well-known binary representation of geometry and a Spatial Reference System ID (SRID) and creates an instance of the appropriate Geometry Type. If the SRID is not provides it defaults to -1.
The return type of the GeomFromText function is the Geometry supertype. For construction of a geometric object to be stored in columns restricted to a particular subtype, use the type-specific construction function.
![]() | |
ST_AsBinary is the reverse of ST_GeomFromWKB. |
| 2D | 3D | M |
|---|---|---|
![]() | ![]() | ![]() |
| 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 |
|---|---|---|---|
| 3.2.7.2 | 7.2.7.1 | - | 5.1.41 |
--Get the WKB
SELECT ST_AsBinary(ST_GeomFromText('POINT(5 5)',25830));
st_asbinary
--------------------------------------------------------------------------------
\001\001\000\000\000\000\000\000\000\000\000\024@\000\000\000\000\000\000\024@
(1 row)
--By setting the value "standard_conforming_strings" to on, we can use exactly the WKB representation
SET standard_conforming_strings = On;
SELECT st_astext(ST_GeomFromWKB('\001\001\000\000\000\000\000\000\000\000\000\024@\000\000\000\000\000\000\024@'));
st_astext
-------------
POINT (5 5)
(1 row)
--Get the WKB
SELECT ST_AsEWKB(ST_GeomFromText('POINT(5 5)'));
010100000000000000000014400000000000001440
--Return the Geometry
SELECT ST_GeomFromWKB('010100000000000000000014400000000000001440');
--As EWKT
SELECT ST_AsEWKT(ST_GeomFromWKB('010100000000000000000014400000000000001440'));
POINT (5 5)