ST_GeomFromWKB

Name

ST_GeomFromWKB — Creates a geometry instance from a Well-Known Binary geometry representation (WKB) and optional SRID.

Synopsis

geometry ST_GeomFromWKB ( bytea geom ) ;

geometry ST_GeomFromWKB ( bytea geom , integer srid ) ;

Description

The ST_GeomFromWKB function, takes a well-known binary representation of a geometry and a Spatial Reference System ID ( SRID ) and creates an instance of the appropriate geometry type. This function plays the role of the Geometry Factory in SQL. This is an alternate name for ST_WKBToSQL.

If SRID is not specified, it defaults to 0 (Unknown).

This method implements the OGC Simple Features Implementation Specification for SQL 1.1. s3.2.7.2 - the optional SRID is from the conformance suite

This method implements the SQL/MM specification. SQL-MM 3: 5.1.41

This method supports Circular Strings and Curves.

Examples

Although bytea rep contains single \, these need to be escaped when inserting into a table. Unless standard_conforming_strings is set to on.

Code
SELECT ST_GeomFromWKB(E'\\001\\002\\000\\000\\000\\002\\000\\000\\000\\037\\205\\353Q\\270~\\\\\\300\\323Mb\\020X\\231C@\\020X9\\264\\310~\\\\\\300)\\\\\\217\\302\\365\\230C@', 4326);
Output
SRID=4326;LINESTRING(-113.98 39.198,-113.981 39.195)
Code
SELECT ST_GeomFromWKB(ST_AsEWKB('POINT(2 5)'::geometry)
  );
Output
POINT(2 5)

The PostgreSQL decode function converts a hexadecimal WKB string to the bytea value accepted by ST_GeomFromWKB .

Code
SELECT ST_AsEWKT(ST_GeomFromWKB(
    decode('0101000000e5d022dbf93e2e40dbf97e6abc743540', 'hex'),
    4326
)) AS geom;
Output
SRID=4326;POINT(15.123 21.456)