[postgis-users] JAVA and post GIS

Gilbert, Antoine AGilbert at korem.com
Mon Jan 30 12:28:18 PST 2006


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
<http://us.rd.yahoo.com/mail_us/taglines/PMHM3/*http:/photomail.mail.yah
oo.com> - 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
<http://us.rd.yahoo.com/evt=38381/%20ylc=X3oDMTEzcGlrdGY5BF9TAzk3MTA3MDc
2BHNlYwNtYWlsdGFncwRzbGsDMWF1dG9z/*http:/autos.yahoo.com/index.html%20>
. 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/5a70fab1/attachment.html>


More information about the postgis-users mailing list