[postgis-users] ClassCastException

Tore Halset halset at pvv.ntnu.no
Fri Jun 4 01:34:19 PDT 2004


On Jun 2, 2004, at 13:43, Tore Halset wrote:

> Hello.
>
> I am new to postgis and have just installed postgresql-7.4.2 with 
> postgis-0.8.1. I installed postgis with proj and geos. I have created 
> a postgis database and loaded in some data using ogr2ogr. Then over to 
> the java world..
>
> I have followed the example at http://www.postgis.org/docs/x655.html 
> but it does not work... I had to switch from org.postgresql.Connection 
> to PGConnection.
>
> I add inn the additional types:
>             ((PGConnection) conn).addDataType("geometry", 
> "org.postgis.PGgeometry");
>             ((PGConnection) conn).addDataType("box3d", 
> "org.postgis.PGbox3d");
>
> r.getObject(1) does return a String instead of a PGgeometry so I get a 
> ClassCastException. Switching from
>                 PGgeometry geom = (PGgeometry) r.getObject(1);
> to
>                 PGgeometry geom = new PGgeometry(r.getString(1));
> fixes the problem.
>
> Is this a faq? What am I doing wrong?

Looks like the sql should be
select geom as geom,id from geomtable
instead of
select AsText(geom) as geom,id from geomtable

  - Tore.




More information about the postgis-users mailing list