Thread: Unpack an org.postgresql.geometric.PGpoint

Unpack an org.postgresql.geometric.PGpoint

From
Sven Holcombe
Date:
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.

Re: Unpack an org.postgresql.geometric.PGpoint

From
Kris Jurka
Date:

On Tue, 23 Jul 2013, Sven Holcombe wrote:

> 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?
>

This is returning a postgis geometry option, not the builtin postgresql
point data type.  To access geometry objects you need to use the postgis
java wrapper:

http://postgis.net/docs/manual-2.0/ch06.html#id351597

Kris Jurka