[postgis-users] postgis with jdbc
Gilbert, Antoine
AGilbert at korem.com
Fri Jan 6 07:08:08 PST 2006
Here is more info on my first problem
The string returned for a geom for my first record is :
MULTIPOINT((789444.623460155 318585.591332341,789394.500542818
318553.011436071,789335.188423968 318522.659225017))
This causing a parsing error when using new PGgeometry(string)
If I modify the string to remove extra braquets to have this :
MULTIPOINT(789444.623460155 318585.591332341,789394.500542818
318553.011436071,789335.188423968 318522.659225017)
It works.... Does I'm using wrong jar ? I am using
postgresql-8.1-404.jdbc2.jar
ResultSet rs = stmt.executeQuery("select \"STREET\",
AsText(geom) as geom from rue_test");
ResultSetMetaData rsmd = rs.getMetaData();
while(rs.next()){
String street = rs.getString(1);
System.out.println(rs.getString(2));
PGgeometry geometry = new PGgeometry(rs.getString(2));
}
java.sql.SQLException: Error parsing Point:
java.lang.NumberFormatException: For input string:
"318585.591332341,789394.500542818"
at org.postgis.Point.<init>(Point.java:168)
at
org.postgis.PointComposedGeom.createSubGeomInstance(PointComposedGeom.ja
va:57)
at org.postgis.ComposedGeom.<init>(ComposedGeom.java:100)
at
org.postgis.PointComposedGeom.<init>(PointComposedGeom.java:53)
at org.postgis.MultiPoint.<init>(MultiPoint.java:48)
at org.postgis.PGgeometry.geomFromString(PGgeometry.java:101)
at org.postgis.PGgeometry.geomFromString(PGgeometry.java:73)
at org.postgis.PGgeometry.setValue(PGgeometry.java:56)
at org.postgis.PGgeometry.<init>(PGgeometry.java:52)
_____
From: Gilbert, Antoine
Sent: January 6, 2006 8:59 AM
To: postgis-users at postgis.refractions.net
Cc: Vachon, Patrick
Subject: [postgis-users] postgis with jdbc
Hi
I just installed PostgreSQL 8.1, supposed to be packaged with postgis
1.0.4
So far I have 2 questions
The jdbc example provided by the documentation dosen't work for me.
Given these 2 statements :
((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PG
geometry");
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox
3d");
This object doesn't exists : org.postgresql.Connection, I tried with
org.postgresql.PGConnection, but I keep getting class cast exceptions
when doing rs.getObject().. (if I do getString(2) all ok)
Here is my complete test code :
((PGConnection)connection).addDataType("geometry","org.postgis.PGgeometr
y");
((PGConnection)connection).addDataType("box3d","
org.postgis.PGgeometry");
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select \"STREET\",
AsText(\"geom\") as geom from rue_test");
ResultSetMetaData rsmd = rs.getMetaData();
for(int i=0;i<rsmd.getColumnCount();i++)
System.out.println("column"+(i+1)+":"+rsmd.getColumnName(i+1));
while(rs.next()){
String street = rs.getString(1);
//System.out.println(rs.getObject(2).getClass().getName()+":"+rs.getStri
ng(2));
PGgeometry geometry = (PGgeometry)rs.getObject(2);
}
Second question. I loaded some line objects on my postgressql database
with FME, and the objects are flagged as MULTIPOINT, I would have
expected these objects to be of type LINE or MULTILINE instead.
Neverlesss, when I use some viewers to see these objects they show as
lines (FME viewer). Where I can find real explanations about all
geometry types used by postgis. (sorry but the postgis doc doesn't help)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20060106/b2651280/attachment.html>
More information about the postgis-users
mailing list