Statistics
| Revision:

gvsig-gazetteer / org.gvsig.gazetteer / trunk / org.gvsig.gazetteer / org.gvsig.gazetteer.lib / src / main / java / org / gvsig / gazetteer / geonames / GeonamesServiceDriver.java @ 102

History | View | Annotate | Download (3.43 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program 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
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2009 Iver T.I.  {{Task}}
26
 */
27

    
28
package org.gvsig.gazetteer.geonames;
29

    
30
import java.awt.geom.Point2D;
31
import java.net.URI;
32
import java.util.List;
33

    
34
import org.geonames.Toponym;
35
import org.geonames.ToponymSearchCriteria;
36
import org.geonames.ToponymSearchResult;
37
import org.geonames.WebService;
38
import org.gvsig.catalog.drivers.DiscoveryServiceCapabilities;
39
import org.gvsig.catalog.exceptions.NotSupportedVersionException;
40
import org.gvsig.gazetteer.drivers.AbstractGazetteerServiceDriver;
41
import org.gvsig.gazetteer.drivers.GazetteerCapabilities;
42
import org.gvsig.gazetteer.querys.Feature;
43
import org.gvsig.gazetteer.querys.GazetteerQuery;
44
import org.gvsig.utils.swing.jcomboServer.ServerData;
45

    
46

    
47

    
48
public class GeonamesServiceDriver extends AbstractGazetteerServiceDriver {
49

    
50

    
51
        public GeonamesServiceDriver() {
52
                super();
53
                setProjection("EPSG:4326");
54
        }
55

    
56
        /*
57
         * (non-Javadoc)
58
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getFeature(java.net.URI, es.gva.cit.gazetteer.querys.GazetteerQuery)
59
         */
60
        public Feature[] getFeature(URI uri, GazetteerQuery query) throws Exception {
61
            WebService.setUserName(getUsername());
62
                ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria();
63
                searchCriteria.setQ(query.getName());
64
                ToponymSearchResult searchResult = WebService.search(searchCriteria);
65
                List toponims = searchResult.getToponyms();
66
                Feature[] features = new Feature[toponims.size()];
67
                for (int i=0 ; i<toponims.size() ; i++){
68
                        features[i] = converToponym((Toponym)toponims.get(i));
69
                }
70
                return features;
71
        }
72

    
73
        private Feature converToponym(Toponym toponym) {
74
                Feature feature = new Feature(toponym.getFeatureCode(),
75
                                toponym.getName(),
76
                                toponym.getName(),
77
                                new Point2D.Double(toponym.getLongitude(), toponym.getLatitude()));
78

    
79
                return feature;
80
        }
81

    
82
        /*
83
         * (non-Javadoc)
84
         * @see es.gva.cit.catalog.drivers.IDiscoveryServiceDriver#getCapabilities(java.net.URI)
85
         */
86
        public DiscoveryServiceCapabilities getCapabilities(URI uri)
87
        throws NotSupportedVersionException {
88
                GazetteerCapabilities capabilities = new GazetteerCapabilities();
89
                return capabilities;
90
        }
91

    
92
        /*
93
         * (non-Javadoc)
94
         * @see es.gva.cit.catalog.drivers.IDiscoveryServiceDriver#getServiceName()
95
         */
96
        public String getServiceName() {
97
                return "Geonames";
98
        }
99

    
100
        /*
101
         * (non-Javadoc)
102
         * @see es.gva.cit.catalog.drivers.AbstractDiscoveryServiceDriver#getOneServer()
103
         */
104
        public ServerData getOneServer() {
105
                return new ServerData("www.geonames.org", "GEONAMES");
106
        }
107

    
108
    @Override
109
    public boolean needsUsername(String protocol) {
110
        return true;
111
    }
112
}