JDBC get object - (Geometry Postgis)
JDBC get object - (Geometry Postgis)
Greetings,
I'm trying to get a geometry (object) from the database through JDBC. I
read the postgis documentation but I think it's not actualized - there
isn't any org.postgresql.Connection object but a
org.postgresql.PGConnection that hasn't any such method as
adddataType().
Example from POSGIS documentation:
---
...
((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("select AsText(geom) as geom,id from
geomtable");
while( r.next() ) {
PGgeometry geom = (PGgeometry)r.getObject(1);
...
---
How could I retrieve a geometry object from a postgresql (7.3.2)
database with postgis 0.7.4? How do I make a mapping or something like
that? I believe that AsText() delivers a text and not an object...
thanks,
Pedro Salazar.
P.S.- If this email is too much postgis than postgresql, I apologize for
the off-topic message.
--
PS
pedro-b-salazar@ptinovacao.pt
PGP:0E129E31D803BC61
Re: JDBC get object - (Geometry Postgis)
Pedro,
The geometry types are in the driver as
org.postgresql.geometric.PGcircle,PGline ....
Dave
On Tue, 2003-04-08 at 11:09, Pedro Salazar wrote:
> Greetings,
>
> I'm trying to get a geometry (object) from the database through JDBC. I
> read the postgis documentation but I think it's not actualized - there
> isn't any org.postgresql.Connection object but a
> org.postgresql.PGConnection that hasn't any such method as
> adddataType().
>
> Example from POSGIS documentation:
> ---
> ...
> ((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
> ((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
>
> Statement s = conn.createStatement();
> ResultSet r = s.executeQuery("select AsText(geom) as geom,id from
> geomtable");
> while( r.next() ) {
> PGgeometry geom = (PGgeometry)r.getObject(1);
> ...
> ---
>
> How could I retrieve a geometry object from a postgresql (7.3.2)
> database with postgis 0.7.4? How do I make a mapping or something like
> that? I believe that AsText() delivers a text and not an object...
>
> thanks,
> Pedro Salazar.
>
> P.S.- If this email is too much postgis than postgresql, I apologize for
> the off-topic message.
--
Dave Cramer
Re: JDBC get object - (Geometry Postgis)
On Tue, 2003-04-08 at 15:25, Dave Cramer wrote: > Pedro, > > The geometry types are in the driver as > > org.postgresql.geometric.PGcircle,PGline .... > > Dave Hi Dave, Those objects are defined as well in the postgresql database as data types, but how could I map them to postgis objects? Are them related or compatible? Or should I transform/convert in a postgres function? And, to retrieve a geometry object, is it enough to do a simple getObject(N) and after that cast it to the respective postgresql object? thanks, Pedro Salazar. -- PS pedro-b-salazar@ptinovacao.pt PGP:0E129E31D803BC61
Re: JDBC get object - (Geometry Postgis)
Pedro, I think we have to put the code back which allows you to add types. I'm not sure where it went, but it appears to be gone?? Dave On Tue, 2003-04-08 at 11:38, Pedro Salazar wrote: > On Tue, 2003-04-08 at 15:25, Dave Cramer wrote: > > Pedro, > > > > The geometry types are in the driver as > > > > org.postgresql.geometric.PGcircle,PGline .... > > > > Dave > > Hi Dave, > > Those objects are defined as well in the postgresql database as data > types, but how could I map them to postgis objects? Are them related or > compatible? Or should I transform/convert in a postgres function? > > And, to retrieve a geometry object, is it enough to do a simple > getObject(N) and after that cast it to the respective postgresql object? > > thanks, > Pedro Salazar. -- Dave Cramer
Re: JDBC get object - (Geometry Postgis)
Pedro, Sorry I was too quick, the code is still there the name of the connection is different now cast it to org.postgresql.PGConnection, then call addDataType here are the comments for it /* * This allows client code to add a handler for one of org.postgresql's * more unique data types. * *NOTE: This is not part of JDBC, but an extension. * *
The best way to use this is as follows: * *
* ... * ((org.postgresql.Connection)myconn).addDataType("mytype","my.class.name"); * ... ** *where myconn is an open Connection to org.postgresql. * *
The handling class must extend org.postgresql.util.PGobject * * @see org.postgresql.util.PGobject */ public void addDataType(String type, String name) { objectTypes.put(type, name); } by default the following are defined, so you can overwrite them as long as you use the same keys. private static final String defaultObjectTypes[][] = { {"box", "org.postgresql.geometric.PGbox"}, {"circle", "org.postgresql.geometric.PGcircle"}, {"line", "org.postgresql.geometric.PGline"}, {"lseg", "org.postgresql.geometric.PGlseg"}, {"path", "org.postgresql.geometric.PGpath"}, {"point", "org.postgresql.geometric.PGpoint"}, {"polygon", "org.postgresql.geometric.PGpolygon"}, {"money", "org.postgresql.util.PGmoney"} }; Dave On Tue, 2003-04-08 at 10:51, Dave Cramer wrote: > Pedro, > > I think we have to put the code back which allows you to add types. > > I'm not sure where it went, but it appears to be gone?? > > Dave > On Tue, 2003-04-08 at 11:38, Pedro Salazar wrote: > > On Tue, 2003-04-08 at 15:25, Dave Cramer wrote: > > > Pedro, > > > > > > The geometry types are in the driver as > > > > > > org.postgresql.geometric.PGcircle,PGline .... > > > > > > Dave > > > > Hi Dave, > > > > Those objects are defined as well in the postgresql database as data > > types, but how could I map them to postgis objects? Are them related or > > compatible? Or should I transform/convert in a postgres function? > > > > And, to retrieve a geometry object, is it enough to do a simple > > getObject(N) and after that cast it to the respective postgresql object? > > > > thanks, > > Pedro Salazar. -- Dave Cramer