View Javadoc
1 /* 2 * WKB4J - WKB reader for geographical mapping toolkits 3 * (C) 2002,2003, David Garnier, dgarnier@users.sourceforge.net 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation, 8 * version 2.1 of the License. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * or visit the web to http://www.gnu.org. 19 * 20 */ 21 package org.wkb4j.examples; 22 23 import java.sql.Connection; 24 import java.sql.DriverManager; 25 import java.util.List; 26 27 import org.apache.log4j.BasicConfigurator; 28 import org.apache.log4j.Logger; 29 import org.postgis.Geometry; 30 import org.wkb4j.jts.JTSGetter; 31 import org.wkb4j.postgis.PostgisGetter; 32 33 /*** 34 * Showcase how to use WKB4J using a WKBGetter. 35 * <br/>Creation date: 29 oct. 2002 10:07:36 36 * @author David Garnier 37 * @version $Revision: 1.1 $ $Date: 2003/07/03 22:26:36 $ 38 */ 39 public class SampleGetter { 40 protected static Logger Log = Logger.getLogger(SampleGetter.class); 41 public static void main(String[] args) { 42 try { 43 /* Configure the logger so it will not complain and will be useful.*/ 44 BasicConfigurator.configure(); 45 46 /* Opens a connection to the PostGIS server.*/ 47 Class.forName("org.postgresql.Driver"); 48 String url = "jdbc:postgresql://localhost/testdb"; 49 Connection conn = 50 DriverManager.getConnection(url, "postgres", "nothing"); 51 52 /* Use a Getter to fetch the geometries from the database.*/ 53 54 PostgisGetter getter = new PostgisGetter(); 55 List geomlist = getter.getData(conn, "usa", "the_geom", "gid !=0"); 56 /* Log the result to the console.*/ 57 Log.debug("Geometries: " + geomlist.size()); 58 for (int i = 0; i < geomlist.size(); ++i) { 59 Geometry geom = (Geometry) geomlist.get(i); 60 if (Log.isDebugEnabled()) { 61 Log.debug("Geometry " + i + " : " + geom.toString()); 62 } 63 } 64 65 } catch (Exception e) { 66 e.printStackTrace(); 67 } 68 } 69 }

This page was automatically generated by Maven