gvsig-gazetteer / org.gvsig.gazetteer / trunk / org.gvsig.gazetteer / org.gvsig.gazetteer.lib / src / main / java / org / gvsig / gazetteer / geonames / GeonamesServiceDriver.java @ 103
History | View | Annotate | Download (3.75 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.fmap.geom.Geometry.SUBTYPES; |
41 |
import org.gvsig.fmap.geom.GeometryLocator; |
42 |
import org.gvsig.fmap.geom.GeometryManager; |
43 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
44 |
import org.gvsig.gazetteer.drivers.AbstractGazetteerServiceDriver; |
45 |
import org.gvsig.gazetteer.drivers.GazetteerCapabilities; |
46 |
import org.gvsig.gazetteer.querys.Feature; |
47 |
import org.gvsig.gazetteer.querys.GazetteerQuery; |
48 |
import org.gvsig.utils.swing.jcomboServer.ServerData; |
49 |
|
50 |
|
51 |
|
52 |
public class GeonamesServiceDriver extends AbstractGazetteerServiceDriver { |
53 |
|
54 |
|
55 |
public GeonamesServiceDriver() {
|
56 |
super();
|
57 |
setProjection("EPSG:4326");
|
58 |
} |
59 |
|
60 |
/*
|
61 |
* (non-Javadoc)
|
62 |
* @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getFeature(java.net.URI, es.gva.cit.gazetteer.querys.GazetteerQuery)
|
63 |
*/
|
64 |
public Feature[] getFeature(URI uri, GazetteerQuery query) throws Exception { |
65 |
WebService.setUserName(getUsername()); |
66 |
ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria();
|
67 |
searchCriteria.setQ(query.getName()); |
68 |
ToponymSearchResult searchResult = WebService.search(searchCriteria); |
69 |
List toponims = searchResult.getToponyms();
|
70 |
Feature[] features = new Feature[toponims.size()]; |
71 |
for (int i=0 ; i<toponims.size() ; i++){ |
72 |
features[i] = converToponym((Toponym)toponims.get(i)); |
73 |
} |
74 |
return features;
|
75 |
} |
76 |
|
77 |
private Feature converToponym(Toponym toponym) throws CreateGeometryException { |
78 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
79 |
Feature feature = new Feature(toponym.getFeatureCode(),
|
80 |
toponym.getName(), |
81 |
toponym.getName(), |
82 |
geomManager.createPoint(toponym.getLongitude(), toponym.getLatitude(), SUBTYPES.GEOM2D)); |
83 |
|
84 |
return feature;
|
85 |
} |
86 |
|
87 |
/*
|
88 |
* (non-Javadoc)
|
89 |
* @see es.gva.cit.catalog.drivers.IDiscoveryServiceDriver#getCapabilities(java.net.URI)
|
90 |
*/
|
91 |
public DiscoveryServiceCapabilities getCapabilities(URI uri) |
92 |
throws NotSupportedVersionException {
|
93 |
GazetteerCapabilities capabilities = new GazetteerCapabilities();
|
94 |
return capabilities;
|
95 |
} |
96 |
|
97 |
/*
|
98 |
* (non-Javadoc)
|
99 |
* @see es.gva.cit.catalog.drivers.IDiscoveryServiceDriver#getServiceName()
|
100 |
*/
|
101 |
public String getServiceName() { |
102 |
return "Geonames"; |
103 |
} |
104 |
|
105 |
/*
|
106 |
* (non-Javadoc)
|
107 |
* @see es.gva.cit.catalog.drivers.AbstractDiscoveryServiceDriver#getOneServer()
|
108 |
*/
|
109 |
public ServerData getOneServer() {
|
110 |
return new ServerData("www.geonames.org", "GEONAMES"); |
111 |
} |
112 |
|
113 |
@Override
|
114 |
public boolean needsUsername(String protocol) { |
115 |
return true; |
116 |
} |
117 |
} |