[postgis-users] JAVA and post GIS

Fatemeh Abbasinejad fabbasinejad at yahoo.com
Mon Jan 30 12:18:31 PST 2006


Hi
   I tried what you did but the program wouln't even compile. I have a table named "land" which has an attribute"geometry" of type "circle". I want to retrieve the center of the circle which is of type "point" as defined by postGIS.Here is my Program
   
  import java.sql.*;
import org.postgis.*;
  public class JavaGIS3 { 
  public static void main(String[] args) 
  { 
    java.sql.Connection conn; 
    try 
    { 
      Class.forName("org.postgresql.Driver"); 
      String url = "jdbc:postgresql://localhost:5432/dcmms"; 
      conn = DriverManager.getConnection(url, "postgres", "abcde"); 
      Statement s = conn.createStatement(); 
      ResultSet rs = s.executeQuery("select (center(geometry))as mycenter from land"); 
      ResultSetMetaData rsmd = rs.getMetaData();
      for(int i=0;rs.next();i++){
       Geometry geometry = new BinaryParser().parse(rs.getBytes(1));
          if(geometry.getType()==geometry.POINT){
           System.out.println("Finally retrieved geometry object!")
          }
      }
      s.close(); 
      conn.close(); 
    } 
    catch( Exception e ) 
    { 
      e.printStackTrace(); 
    }
  }
}
   
   
  I did what you had said in your email but it would give an error:
  BinaryParser cannot be resolved to a type
   
  What should I do? Did you compile your program?
  
"Gilbert, Antoine" <AGilbert at korem.com> wrote:
                Hi
   
  Here is my example using postgis_1_0_0.jar
   
  Connection connection = TestUtils.getTestConnection();
          Statement stmt = connection.createStatement();
          ResultSet rs = stmt.executeQuery("select AsBinary(geom) as geom from \"rue_test_polyline\"");
          ResultSetMetaData rsmd = rs.getMetaData();
          for(int i=0;rs.next();i++){
              Geometry geometry = new BinaryParser().parse(rs.getBytes(1));
              if(geometry.getType()==geometry.MULTILINESTRING){
                  MultiLineString multiline = ((MultiLineString)geometry);
                  System.out.println(multiline.toString());
                  System.out.println("ligne "+i+" contient "+multiline.numLines()+" segment(s)");
                  for(int j=0;j<multiline.numLines();j++)
                      System.out.println("    segment "+j+":"+multiline.getLine(j).numPoints()+" points");
              }
          }
          stmt.close();
          connection.close();
   
      
---------------------------------
  
  From: Fatemeh Abbasinejad [mailto:fabbasinejad at yahoo.com] 
Sent: January 30, 2006 3:43 AM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] JAVA and post GIS

   
    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
  


			
---------------------------------
 Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20060130/b4aebc9d/attachment.html>


More information about the postgis-users mailing list