[postgis-users] JAVA and post GIS

Fatemeh Abbasinejad fabbasinejad at yahoo.com
Mon Jan 30 13:47:35 PST 2006


AsBinary() and AsText() require a "geometry object as input. My object is of type "Point" and will non execute the query.I tried executing the query alone.Am I doing something wrong? Do you know how I can convert Point or types "circle" into binary?
  I am also using postgis_1.1.0.jar.
   
  

"Gilbert, Antoine" <AGilbert at korem.com> wrote:
                Yes
   
  I’m not a postgis expert, but I think in your case it should be 
   
  ResultSet rs = s.executeQuery("select (AsBinary(center(geometry)))) as mycenter from land");
   
  You have to convert the geometry in the binary format
   
  You can use AsText too and use new PGgeometry(rs.getString(1)) or something like that I think
   
  I’m using postgis_1_0_0.jar
   
      
---------------------------------
  
  From: Fatemeh Abbasinejad [mailto:fabbasinejad at yahoo.com] 
Sent: January 30, 2006 3:19 PM
To: PostGIS Users Discussion
Subject: RE: [postgis-users] JAVA and post GIS

   
    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.

_______________________________________________
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/709de59f/attachment.html>


More information about the postgis-users mailing list