[postgis-users] Buffering with JDBC
shojka at web.de
shojka at web.de
Fri May 11 07:45:24 PDT 2007
import java.sql.*; import java.util.*; import java.lang.*; import org.postgis.*;
public class JavaGIS { public static void main(String[] args)
{
java.sql.Connection conn;
try
{
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432/database"; conn = DriverManager.getConnection(url, "postgres", "");
((org.postgresql.jdbc2.Jdbc2Connection)conn).addDataType("Geometry","org.postgis.PGgeometry");
((org.postgresql.jdbc2.Jdbc2Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("SELECT Buffer(GeometryFromText('POINT(10000 20000)',-1),20)");
while( r.next() )
{
PGgeometry geom= (PGgeometry)r.getObject(1);
if( geom.getType() = Geometry.POLYGON )
{
Polygon pl = (Polygon)geom.getGeometry();
for( int r = 0; r < pl.numRings(); r++ )
{
LinearRing rng = pl.getRing(r);
System.out.println("Ring: " + r);
for( int p = 0; p < rng.numPoints(); p++ )
{
Point pt = rng.getPoint(p);
System.out.println("Point: " + p);
System.out.println(pt.toString());
}
}
}
}
s.close();
conn.close();
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
Dear PostGis users,
I want to use buffer function from POSTGIS but I simply cannot convert the result of query in a PGgeometry object. The line:
PGgeometry geom= (PGgeometry)r.getObject(1);
results always in:
java.lang.ClassCastException: org.postgresql.util.PGobject
I got result as a strine when i insert in qery function Astext(), but when I want to work with geometry I am helpless. Has anyone an idea how this problem could be solved?
Thanking in advance
Erweitern Sie FreeMail zu einem noch leistungsstärkeren E-Mail-Postfach!
Mehr Infos unter *http://produkte.web.de/club/?mc=021131* [http://produkte.web.de/club/?mc=021131]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070511/61df742a/attachment.html>
More information about the postgis-users
mailing list