[postgis] How to interpret geometry from binary cursor?

Dave Blasby dblasby at refractions.net
Mon Oct 29 09:21:21 PST 2001


"Petri J. Riipinen" wrote:
> What is the format of the binary buffer, if I use binary cursor to retrieve
> the value from 'the_geom'-field?

You can request it in WKB (see the OGIS spec for its description):

SELECT asbinary(the_geom,'XDR') FROM <table>;
SELECT asbinary(the_geom,'NDR') FROM <table>;
SELECT asbinary(the_geom) FROM <table>;

(The first two specify what endian you want the data in, the last gives
it to you in the endian of the postgresql server)


If you are using normal text cursors, you will get a HEX version of the
WKB.  By that I mean each byte in the WKB will be represented by a 2
character hexidecimal number.  For example, the 5 byte binary string
0-0-255-1-0 would be "0000FF0100".

If you access it as a binary cursor, you call the libpq function
"PQgetlength()" to find out how many bytes are in the WKB.  You can then
access the WKB as a chuck of memory.

If you do this SQL with a binary cursor:

SELECT the_geom FROM <table>;

You still call the "PQgetlength()" to find the length of the object. 
The actual object will be a GEOMETRY, as defined in postgis.h.  There is
documentation on the website for this structure, but note that it has
changed a bit since I wrote it.
NOTE: the GEOMETRY structure will be in the endian of the postgresql
server.

If you do this SQL with a normal (Text) cursor:

SELECT the_geom FROM <Table>;

You'll get the cannonical form in text form:
SRID=<srid>;<WKT>

If you do a:

SELECT astext(the_geom) FROM <table>;

You'll get a just the WKT in text form.


dave

To unsubscribe from this group, send an email to:
postgis-unsubscribe at yahoogroups.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 





More information about the postgis-users mailing list