Unpack an org.postgresql.geometric.PGpoint - Mailing list pgsql-jdbc

From Sven Holcombe
Subject Unpack an org.postgresql.geometric.PGpoint
Date
Msg-id CADmUhuy2484iQrUEgBOraL9tz4nBUPtCN41OyFDua+bhpOS61g@mail.gmail.com
Whole thread Raw
Responses Re: Unpack an org.postgresql.geometric.PGpoint  (Kris Jurka <books@ejurka.com>)
List pgsql-jdbc
I can get an org.postgresql.util.PGobject object into my application (MATLAB) via a database connection:

D = fetch(conn,'SELECT ST_GeomFromText(''POINT(-10 5)'')')
class(D{1})    % Returns 'org.postgresql.util.PGobject'
D{1}.getValue  % Returns the java.lang.String '010100000000000000000024C00000000000001440'

But I want to unpack this object to get at its contents (ie, the coordinates -10 and 5). Can someone describe how to do this?


For some context, I can attack the problem from another direction and create a org.postgresql.geometric.PGpoint object directly in MATLAB as follows:
pt = javaObject('org.postgresql.geometric.PGpoint',3,4)

This returns an 'org.postgresql.geometric.PGpoint' object with nice convenient methods pt.x and pt.y, which return my coordinates (pt.x=3,pt.y=4). My guess is that in order to get similar functionality from the PGobject returned above, I need to convert this org.postgresql.util.PGobject object into a org.postgresql.geometric.PGpoint object. However, the one constructor signature of PGpoint that seems to do this <PGpoint(java.lang.String value)> hits an exception when I try to use it:


newPt = javaObject('org.postgresql.geometric.PGpoint',D{1}.getValue)
Java exception occurred:
org.postgresql.util.PSQLException: Conversion to type point failed: 010100000000000000000024C00000000000001440.

at org.postgresql.geometric.PGpoint.setValue(PGpoint.java:85)

at org.postgresql.geometric.PGpoint.<init>(PGpoint.java:60)

Caused by: java.lang.NumberFormatException: For input string: "010100000000000000000024C00000000000001440"

at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)

at java.lang.Double.valueOf(Unknown Source)

at org.postgresql.geometric.PGpoint.setValue(PGpoint.java:80)

... 1 more



Is there something I am missing? If you had an 'org.postgresql.util.PGobject' object in java, how would you recommend to go about unpacking it?

For reference:
- Win 7
- 'postgresql-9.1-901.jdbc4.jar' on java path


Thanks,
Sven.

pgsql-jdbc by date:

Previous
From: Chen Huajun
Date:
Subject: Re: Fail-over PG server in connection string - syntax ?
Next
From: dmp
Date:
Subject: Re: Website Redo Kick Off