[postgis-users] how to get point, polygon value in postgis JDBC?
Maria Arias de Reyna
marias at emergya.com
Fri Nov 4 00:35:56 PDT 2011
El Viernes, 4 de Noviembre de 2011, LeeHyung Joo - Kevin escribió:
> Hi all.
>
> I have a big problem on my work.
>
> First of all, the version based on my work is PostgreSQL : 8.1.11, PostGIS
> : 1.5.2.
>
> The problem is I can not get the value of Point and Polygon.
>
> The code is below :
>
> blah blah
> --------------------------------------------------------------------------
> ------ public Test find(String Id) throws DAOException,
> ClassNotFoundException, SQLException {
> Class.forName("org.postgresql.Driver");
> String url = "jdbc:postgresql://localhost:8080/testdao";
> Connection conn = DriverManager.getConnection(url, admin, apple);
> PreparedStatement ps = conn.prepareStatement("select name, addr,
> ST_AsText(position) from listFriend where id=?"); ps.setString(1, Id);
>
> ResultSet rs = ps.executeQuery();
>
> //
> ((org.postgresql.PGConnection)conn).addDataType("point",Class.forName("org
> .postgis.Point"));
>
> while(rs.next()) {
> test = new Test();
> p = new Point();
>
> test.setName(rs.getString(1));
> test.setAddr(rs.getString(2));
> test.setPosition(p);
> // System.out.println(rs.getString(3));
> ---------------------------------------------------------------------------
> ---------------
>
> If I run the sentence, "System.out.println(rs.getString(3));, it works. It
> prints right output like "Point(13.123 11.123)".
>
> But I don't know how to fix test.setPosition(p);
>
> any helps will be thank.
>
>
> P.S. is it possible to be reason why the low or high version of PostgreSQL
> and PostGIS?
>
>
> Best Regards
> Kevin Lee.
Maybe you are looking for a WKT Parser? Like this one:
http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/io/WKTReader.html
If you are using the postGIS driver you should be able to use the geometry
directly on your query, instead of using as_text.
--
María Arias de Reyna Domínguez
Área de Operaciones
Emergya Consultoría
Tfno: +34 954 51 75 77 / +34 607 43 74 27
Fax: +34 954 51 64 73
www.emergya.com
More information about the postgis-users
mailing list