[postgis-users] JAVA and post GIS
Fatemeh Abbasinejad
fabbasinejad at yahoo.com
Mon Jan 30 13:08:47 PST 2006
Hi.
I sae the code and tried to execute it on my own tables.Ther were some problems:
First when trying to add data types it would give me a warning that the method addDataType has been deprecated.
Also when I tried to cast to PGeometry it would throw "ClassCastException".Here is my code:
((PGConnection)conn).addDataType("geometry","org.postgis.PGgeometry");
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("select center(geometry)as mycenter from land");
while( r.next() )
{
PGgeometry mycenter = (PGgeometry)r.getObject(1);
System.out.println(mycenter.toString());
}
I have a table called "land" which has an attribute "geometry" of type Circle.I want to retreive the center of the circle which is of type "Point".
Have I casted wrong? I also tried casting to "Point" but it would give the same exception. What should I do?
Emily Gouge <egouge at refractions.net> wrote:
Hi,
There is some documentation and an example on connecting to PostGIS using Java. See:
http://postgis.refractions.net/docs/ch04.html#id2789526
You can add a datatype to the postgres connection and then the getObject() call will return a
PGGeometry object:
((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
Additionally you can also check out the postgis_jts jar, which provides the ability to return a
JtsGeometry object (and subsequently to convert this object to a JTS Geometry object).
Emily
Fatemeh Abbasinejad wrote:
> I am new to PostGIS. Does anyone know how we can retrieve our defined data types
> (like point,circle,...) from a ResultSet in java. I used getObject but it didn't work.
> -fatemeh
>
>
> ---------------------------------
> Bring words and photos together (easily) with
> PhotoMail - it's free and works with Yahoo! Mail.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
---------------------------------
What are the most popular cars? Find out at Yahoo! Autos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20060130/5441fbaa/attachment.html>
More information about the postgis-users
mailing list