/* * PostGISDataSource.java * * Created on 01 December 2001, 00:15 */ package uk.ac.leeds.ccg.sfsql; import java.sql.*; import org.postgis.*; import uk.ac.leeds.ccg.geotools.*; /** * * @author James Macgill * @version */ public class PostGISDataSource { Connection connection; /** Creates new PostGISDataSource */ public PostGISDataSource() { } public void connect(String server,String database,String user,String passwd) throws SQLException{ try { System.out.println("Loading driver"); Driver drv = new org.postgresql.Driver(); // Class.forName("org.postgresql.Driver"); } catch(Exception e) { // System.err.print("DaS->ClassNotFoundException: "); System.err.println("DaS->"+e.getMessage()); } connection = DriverManager.getConnection("jdbc:postgresql://"+server+"/"+database,user,passwd); ((org.postgresql.Connection)connection).addDataType("geometry","org.postgis.PGgeometry"); ((org.postgresql.Connection)connection).addDataType("box3d","org.postgis.PGbox3d"); } public MixedLayer getFeatures(GeoRectangle bounds) throws SQLException{ MixedLayer l = new MixedLayer(); addFeatures(l,bounds); return l; } public void addFeatures(MixedLayer l,GeoRectangle bounds)throws SQLException{ Statement s = connection.createStatement(); //PGbox3d box3d = new PGbox3d(new org.postgis.Point(400000,400000),new org.postgis.Point(410000,410000)); StringBuffer box3d = new StringBuffer("BOX3D ("); box3d.append(bounds.x); box3d.append(" "); box3d.append(bounds.y); box3d.append(","); box3d.append(bounds.x+bounds.width); box3d.append(" "); box3d.append(bounds.y+bounds.height); int notNeeded[] = l.getIDs(bounds,SelectionManager.CROSSES); StringBuffer idList = new StringBuffer(); if(notNeeded.length>0){ idList.append("and oid not in ("); idList.append(notNeeded[0]); for(int i=1;i