wiki:FAQ

Version 10 (modified by robe, 15 years ago) ( diff )

--

PostGIS FAQ

Frequently Asked Questions about PostGIS extension.

PostgreSQL Can't install under Windows Vista

Refer to these instructions Issues with installing under Windows Vista

How to create geometry from hex-encoded Well-Known-Binary string using SQL?

This is two-steps operation which can be executed in single SQL statement. The steps include:

  • Convert Well-Known-Binary data in hexadecimal string form to raw binary using PostgreSQL function decode.
  • Construct geometry object from WKB in raw binary form.

Example:

=# SELECT ST_AsText(ST_GeomFromWKB(decode('0101000000e5d022dbf93e2e40dbf97e6abc743540', 'hex'), -1));
      st_astext       
----------------------
 POINT(15.123 21.456)

How to write geometry Well-Known-Binary to hex-encoded string?

First, query for geometry object in Well-Known-Binary format using ST_AsBinary function. Then, encode raw WKB to hex string.

Examples:

  • selecting geometry from table:
# SELECT encode(ST_AsBinary(the_geom), 'hex');
                   encode                   
--------------------------------------------
 0101000000e5d022dbf93e2e40dbf97e6abc743540
  • constructing geometry in-place from given Well-Known-Text:
# SELECT encode(ST_AsBinary(ST_GeomFromText('POINT(15.123 21.456)', -1)), 'hex');
                   encode                   
--------------------------------------------
 0101000000e5d022dbf93e2e40dbf97e6abc743540
Note: See TracWiki for help on using the wiki.