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.ArrayList;
26
27 import org.apache.log4j.BasicConfigurator;
28 import org.apache.log4j.Logger;
29 import org.postgis.Geometry;
30 import org.wkb4j.engine.WKBParser;
31 import org.wkb4j.engine.WKBReader;
32 import org.wkb4j.postgis.PostGISFactory;
33
34 /***
35 * Showcase how to use WKB4J.
36 * <br/>Creation date: 29 oct. 2002 10:07:36
37 * @author David Garnier
38 * @version $Revision: 1.3 $ $Date: 2003/06/23 20:53:58 $
39 */
40 public class SampleCode {
41 protected static Logger Log = Logger.getLogger(SampleCode.class);
42 public static void main(String[] args) {
43 try {
44 /* Configure the logger so it will not complain and will be usefull.*/
45 BasicConfigurator.configure();
46
47 /* Opens a connection to the PostGIS server.*/
48 Class.forName("org.postgresql.Driver");
49 String url = "jdbc:postgresql://localhost/wkb4j";
50 Connection conn =
51 DriverManager.getConnection(url, "postgres", "nothing");
52
53 /* Create the WKBReader.*/
54 WKBReader reader = new WKBReader();
55
56 /* For this demo we will be using the PostGISFactory.*/
57 PostGISFactory factory = new PostGISFactory();
58
59 /* Create the WKBParser.*/
60 WKBParser parser = new WKBParser(factory);
61
62 /* You can complement this query with your own code.*/
63 reader.readDataWithPartialQuery(
64 conn,
65 "the_geom",
66 "from points",
67 parser);
68
69 /* In the PostGISFactory, completed Geometries are stored internally
70 * and can be returned through this method.*/
71 ArrayList geomlist = factory.getGeometries();
72
73 /* Log the result to the console.*/
74 Log.debug("Geometries: " + geomlist.size());
75 for (int i = 0; i < geomlist.size(); ++i) {
76 Geometry geom = (Geometry) geomlist.get(i);
77 if (Log.isDebugEnabled()) {
78 Log.debug("Geometry " + i + " : " + geom.toString());
79 }
80 }
81
82 } catch (Exception e) {
83 e.printStackTrace();
84 }
85 }
86 }
This page was automatically generated by Maven