|
From: James M. <jma...@us...> - 2001-12-04 09:25:10
|
Update of /cvsroot/geotools/geotools/src/uk/ac/leeds/ccg/sfsql
In directory usw-pr-cvs1:/tmp/cvs-serv6456
Modified Files:
PostGISTester.java
Log Message:
Updated to use new PostGISDataSource.java
Index: PostGISTester.java
===================================================================
RCS file: /cvsroot/geotools/geotools/src/uk/ac/leeds/ccg/sfsql/PostGISTester.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -w -C2 -d -r1.2 -r1.3
*** PostGISTester.java 2001/11/04 13:45:03 1.2
--- PostGISTester.java 2001/12/04 09:25:07 1.3
***************
*** 10,13 ****
--- 10,14 ----
import org.postgis.*;
import uk.ac.leeds.ccg.geotools.*;
+ import uk.ac.leeds.ccg.widgets.*;
import java.awt.*;
/**
***************
*** 20,130 ****
/** Creates new Tester */
public PostGISTester() throws Exception {
! //jdbc:oracle:thin:@feathers.leeds.ac.uk:1521:pfoss
! String url = "jdbc:postgresql://feathers.leeds.ac.uk/postgis";
! try {
! Class.forName("org.postgresql.Driver");
!
! } catch(java.lang.ClassNotFoundException e) {
! System.err.print("DaS->ClassNotFoundException: ");
! System.err.println("DaS->"+e.getMessage());
! }
! java.sql.Connection conn = DriverManager.getConnection(url,"postgis","postgis");
! //DataSource data = new DataSource(con);
! ((org.postgresql.Connection)conn).addDataType("geometry","org.postgis.PGgeometry");
! ((org.postgresql.Connection)conn).addDataType("box3d","org.postgis.PGbox3d");
!
! /*
! * Create a statement and execute a select query.
! */
! // WHERE geo_value && 'BOX3D(400000 400000 0,500000 500000 0)'::box3d
! PGbox3d box3d = new PGbox3d(new org.postgis.Point(400000,400000),new org.postgis.Point(410000,410000));
! Statement s = conn.createStatement();
! System.out.println(box3d);
! ResultSet size = s.executeQuery("select count (*) from yh_eds where geo_value && '"+box3d+"'::box3d");
! while(size.next()){
! System.out.println(size.getString(1));
! }
Frame f = new Frame();
f.setSize(500,500);
Viewer view = new Viewer();
f.add(view,"Center");
! MixedLayer l = new MixedLayer();
! //pl.setScaleBuffer(false);
! ResultSet r = s.executeQuery("select geo_value from yh_eds where geo_value && '"+box3d+"'::box3d");
! while( r.next() ) {
! /*
! * Retrieve the geometry as an object then cast it to the geometry type.
! * Print things out.
! */
! PGgeometry geom = (PGgeometry)r.getObject(1);
! //int id = r.getInt(2);
! //System.out.println("Row " + id + ":");
!
!
! //System.out.println(geom.getGeoType());
! switch (geom.getGeoType()){
! case Geometry.POINT:
! case Geometry.MULTIPOINT:
! case Geometry.GEOMETRYCOLLECTION:
! case Geometry.LINESTRING:
! case Geometry.MULTILINESTRING:
! System.out.println("Geometry type not supported");
! break;
! case Geometry.POLYGON:
! System.out.println("A polygon!");
! break;
! case Geometry.MULTIPOLYGON:
! GeoPolygon poly = convertMultiPolygon((MultiPolygon)geom.getGeometry());
! System.out.println("poly bounds "+poly.getBounds());
! l.addGeoPolygon(poly,false);
!
! //System.out.println("multipolygon converted");
!
! break;
! default :
! System.out.println("Unkown geom type");
! }
!
! //System.out.println(geom.toString());
!
! }
! Theme t = new Theme(l);
//f.add(new uk.ac.leeds.ccg.widgets.ToolBar(view),"South");
f.setVisible(true);
view.addTheme(t);
-
-
-
-
}
- public GeoPolygon convertMultiPolygon(MultiPolygon p){
- GeoPolygon gp=null;
- GeoPolygon part;
- int count = p.numPolygons();
-
- for(int i=0;i<count;i++){
- org.postgis.Polygon poly = p.getPolygon(i);
- int rings = poly.numRings();
- for(int j=0;j<rings;j++){
- LinearRing ring = poly.getRing(j);
- double x[] = new double[ring.points.length];
- double y[] = new double[ring.points.length];
- for(int k=0;k<x.length;k++){
- x[k] = ring.points[k].x;
- y[k] = ring.points[k].y;
- }
- part = new GeoPolygon(x,y,x.length);
- if(i==0 && j==0){
- gp = part;
- }
- else{
- gp.addSubPart(part);
- }
- }
- }
- return gp;
- }
--- 21,41 ----
/** Creates new Tester */
public PostGISTester() throws Exception {
! GeoRectangle bounds = new GeoRectangle(400000,400000,10000,10000);
! PostGISDataSource server = new PostGISDataSource();
! server.connect("feathers.leeds.ac.uk","postgis","postgis","postgis");
Frame f = new Frame();
f.setSize(500,500);
Viewer view = new Viewer();
f.add(view,"Center");
! f.add(new ToolBar(view),"South");
! //MixedLayer l = server.getFeatures(bounds);
! PostGISLayer pgl = new PostGISLayer(server,bounds);
! Theme t = new Theme(pgl);
//f.add(new uk.ac.leeds.ccg.widgets.ToolBar(view),"South");
f.setVisible(true);
view.addTheme(t);
}
|