01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.data.wfs.demo;
17:
18: import java.io.IOException;
19: import java.net.URL;
20: import java.util.HashMap;
21: import java.util.Map;
22: import java.util.NoSuchElementException;
23:
24: import org.geotools.data.DataStore;
25: import org.geotools.data.DefaultQuery;
26: import org.geotools.data.FeatureReader;
27: import org.geotools.data.Query;
28: import org.geotools.data.Transaction;
29: import org.geotools.data.wfs.WFSDataStoreFactory;
30: import org.geotools.feature.IllegalAttributeException;
31:
32: /**
33: * <p>
34: * An example use of the WFS data store
35: * </p>
36: * @author dzwiers Refractions Research
37: *
38: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wfs/src/test/java/org/geotools/data/wfs/demo/WFSDemo.java $
39: */
40: public class WFSDemo {
41: public static void main(String[] args) {
42: System.out.println("WFS Demo");
43: try {
44: // URL url = new URL("http://www2.dmsolutions.ca/cgi-bin/mswfs_gmap?version=1.0.0&request=getcapabilities&service=wfs");
45: URL url = new URL(
46: "http://www.refractions.net:8080/geoserver/wfs?REQUEST=GetCapabilities");
47:
48: Map m = new HashMap();
49: m.put(WFSDataStoreFactory.URL.key, url);
50: m.put(WFSDataStoreFactory.TIMEOUT.key, new Integer(10000));
51: m.put(WFSDataStoreFactory.PROTOCOL.key, Boolean.FALSE);
52:
53: DataStore wfs = (new WFSDataStoreFactory())
54: .createNewDataStore(m);
55: Query query = new DefaultQuery(wfs.getTypeNames()[1]);
56: FeatureReader ft = wfs.getFeatureReader(query,
57: Transaction.AUTO_COMMIT);
58: int count = 0;
59: while (ft.hasNext())
60: if (ft.next() != null)
61: count++;
62: System.out.println("Found " + count + " features");
63: } catch (IOException e) {
64: e.printStackTrace();
65: } catch (NoSuchElementException e) {
66: e.printStackTrace();
67: } catch (IllegalAttributeException e) {
68: e.printStackTrace();
69: }
70: }
71: }
|