Changes between Version 7 and Version 8 of FAQ
- Timestamp:
- 04/17/09 18:38:21 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
FAQ
v7 v8 5 5 [[TOC(depth=2, noheading, inline)]] 6 6 7 == How to create geometry from hex-encoded W KBusing SQL? ==7 == How to create geometry from hex-encoded Well-Known-Binary string using SQL? == 8 8 9 This is two-steps operation which can be executed in single SQLstatement. The steps include:10 1. Convert WKBdata in hexadecimal string form to raw binary using PostgreSQL function [http://www.postgresql.org/docs/8.3/static/functions-binarystring.html decode].11 2.Construct geometry object from WKB in raw binary form.9 This is two-steps operation which can be executed in single [http://www.postgresql.org/docs/8.3/static/sql-commands.html SQL] statement. The steps include: 10 * Convert [http://postgis.refractions.net/documentation/manual-svn/ch04.html Well-Known-Binary] data in hexadecimal string form to raw binary using PostgreSQL function [http://www.postgresql.org/docs/8.3/static/functions-binarystring.html decode]. 11 * Construct geometry object from WKB in raw binary form. 12 12 13 13 Example: … … 15 15 {{{ 16 16 #!sql 17 =# SELECT ST_AsText(ST_GeomFromWKB(decode('0101000000e5d022dbf93e2e40dbf97e6abc743540', 'hex'), 4326));17 =# SELECT ST_AsText(ST_GeomFromWKB(decode('0101000000e5d022dbf93e2e40dbf97e6abc743540', 'hex'), -1)); 18 18 st_astext 19 19 ---------------------- 20 20 POINT(15.123 21.456) 21 21 }}} 22 23 == How to write geometry Well-Known-Binary to hex-encoded string? == 24 25 First, query for geometry object in [http://postgis.refractions.net/documentation/manual-svn/ch04.html Well-Known-Binary] format using [http://postgis.refractions.net/documentation/manual-svn/ST_AsBinary.html ST_AsBinary] function. Then, [http://www.postgresql.org/docs/8.3/static/functions-binarystring.html encode] raw WKB to hex string. 26 27 Examples: 28 29 * selecting geometry from table: 30 31 {{{ 32 #!sql 33 # SELECT encode(ST_AsBinary(the_geom), 'hex'); 34 encode 35 -------------------------------------------- 36 0101000000e5d022dbf93e2e40dbf97e6abc743540 37 }}} 38 39 * constructing geometry in-place from given Well-Known-Text: 40 41 {{{ 42 #!sql 43 # SELECT encode(ST_AsBinary(ST_GeomFromText('POINT(15.123 21.456)', -1)), 'hex'); 44 encode 45 -------------------------------------------- 46 0101000000e5d022dbf93e2e40dbf97e6abc743540 47 }}}