[postgis-users] wkb problem

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Mon Aug 13 00:00:19 PDT 2007


On Mon, 2007-08-13 at 09:32 +0800, caij at lreis.ac.cn wrote:
> Hi,
>    Yesterday,i used the c+libpq to get the wkb_geometry field in the form of WKB,and i can get it successfully,but when i tried to read the Z value of the points,the result is it is not 3d data,which in fact it is 3d.
>    My postgis is 1.1.3 and when i used the 1.0.3 version,there was no this problem.
>    and this is my query sentence:
>    DECLARE mycursor2 BINARY CURSOR FOR select asbinary(wkb_geometry,'ndr') from mytable;
> 
>    Anyone can tell me the reason?Have u ever come across this problem before?

This one is fairly easy to solve if you start experimenting with typing
your queries into psql (otherwise unless you check your logs or
explicitly check for warnings in your code, you will not see the WARNING
message):

postgis=# select astext(geomfromtext('POINT(0 0 0)'));
WARNING:  OGC WKT expected, EWKT provided - use GeomFromEWKT() for this
CONTEXT:  SQL function "geomfromtext" statement 1
   astext
------------
 POINT(0 0)

In other words, the OGC spec doesn't define 3D coordinates and so to be
spec-compliant, PostGIS converts its data to 2D using the asbinary()
function. If you want to see details such as 3D coordinates and the SRID
then you need to use PostGIS' EWKB (Extended Well-Known Binary) format
which extends the OGC formats to contain this extra information, e.g.

DECLARE mycursor2 BINARY CURSOR FOR select asewkb(wkb_geometry,'ndr')
from mytable;


HTH,

Mark.

-- 
ILande - Open Source Consultancy
http://www.ilande.co.uk





More information about the postgis-users mailing list