Unpack an org.postgresql.geometric.PGpoint

From: Sven Holcombe <sven(dot)holcombe(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Unpack an org.postgresql.geometric.PGpoint
Date: 2013-07-23 18:41:25
Message-ID: CADmUhuy2484iQrUEgBOraL9tz4nBUPtCN41OyFDua+bhpOS61g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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<http://jdbc.postgresql.org/documentation/publicapi/org/postgresql/geometric/PGpoint.html#PGpoint(java.lang.String)>
*(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.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message dmp 2013-07-24 18:24:54 Re: Website Redo Kick Off
Previous Message Chen Huajun 2013-07-23 06:23:21 Re: Fail-over PG server in connection string - syntax ?