[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgis-users
Subject:    Re: [postgis-users] JAVA and post GIS
From:       Emily Gouge <egouge () refractions ! net>
Date:       2006-01-31 16:42:20
Message-ID: 43DF936C.3030707 () refractions ! net
[Download RAW message or body]


rs.getObject() will return a PGgeometry , so you can cast this to a PGgeometry.  \
There are some  examples at the bottom of this page:
http://postgis.refractions.net/docs/ch04.html#id2789526

If you know the PGgeometry is a point, then you can do the following:
PGgeometry g = (PGgeometry)rs.getObject(1);
Point p  = (Point) g.getGeometry();
System.out.println(p.x + ":" + p.y );



Fatemeh Abbasinejad wrote:
> Thanks a loooooooot.This helped.How can I retreive the data inside my database \
> though( the coordinates of my point). With getObject (besides getClass) there \
> aren't a lot of methods? Are we able to cast the object we retreive fron postgis to \
> say " Point" so we can use the getX () and getY() methods? 
> Emily Gouge <egouge@refractions.net> wrote:  Fatemeh,
> 
> If you are using an attribute type of Circle you are not using the PostgreSQL data \
> types and not the  PostGIS geometry objects. So if you want to use the PostGIS \
> geometry functions you need to create  PostGIS Geometry objects using the \
> AddGeometryColumns() function. 
> For further information see: \
> http://postgis.refractions.net/docs/ch04.html#id2787299 
> 
> The following code will return PGGeometries; however you must have the postgis.jar, \
>  postgresql-7.4.1-jdbc3.jar on your class path. If you are using postgres 8.1 then \
> you can have the  postgres81 jar in replace of the 7.4.1 jar, however you will note \
> that the addDataType function will  be depreciated (the newer version takes a class \
> instead of a String). 
> Class.forName("org.postgresql.Driver");
> Connection c= DriverManager.getConnection("jdbc:postgresql://turtle:5432/cwb_devel","egouge", \
> "" ); ((PGConnection) c).addDataType("geometry", "org.postgis.PGgeometry" ); //for \
> 8.1 change to  addDataType("geometry", org.postgis.PGgeometry.class );
> 
> ResultSet rs = c.createStatement().executeQuery("SELECT the_geom from table_name");
> while(rs.next()){
> System.out.println(rs.getObject(1).getClass());
> }
> 
> 
> -Emily
> 
> Fatemeh Abbasinejad wrote:
> > 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 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@postgis.refractions.net
> > > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users@postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> > 
> > 
> > 
> > 
> > ---------------------------------
> > 
> > What are the most popular cars? Find out at Yahoo! Autos 
> > 
> > 
> > ------------------------------------------------------------------------
> > 
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users@postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
> 
> 
> 
> 		
> ---------------------------------
> 
> What are the most popular cars? Find out at Yahoo! Autos 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> postgis-users mailing list
> postgis-users@postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic