pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedUnpack an org.postgresql.geometric.PGpoint
2+ messages / 2 participants
[nested] [flat]
* Unpack an org.postgresql.geometric.PGpoint
@ 2013-07-23 18:41 Sven Holcombe <sven.holcombe@gmail.com>
2013-07-25 03:18 ` Re: Unpack an org.postgresql.geometric.PGpoint Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 2+ messages in thread
From: Sven Holcombe @ 2013-07-23 18:41 UTC (permalink / raw)
To: 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(jav...;
*(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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Unpack an org.postgresql.geometric.PGpoint
2013-07-23 18:41 Unpack an org.postgresql.geometric.PGpoint Sven Holcombe <sven.holcombe@gmail.com>
@ 2013-07-25 03:18 ` Kris Jurka <books@ejurka.com>
0 siblings, 0 replies; 2+ messages in thread
From: Kris Jurka @ 2013-07-25 03:18 UTC (permalink / raw)
To: Sven Holcombe <sven.holcombe@gmail.com>; +Cc: pgsql-jdbc
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
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2013-07-25 03:18 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-07-23 18:41 Unpack an org.postgresql.geometric.PGpoint Sven Holcombe <sven.holcombe@gmail.com>
2013-07-25 03:18 ` Kris Jurka <books@ejurka.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox