svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wmts / WMTSClient.java @ 40769
History | View | Annotate | Download (7.78 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.remoteclient.wmts; |
25 |
|
26 |
import java.io.File; |
27 |
import java.io.IOException; |
28 |
import java.net.ConnectException; |
29 |
import java.net.MalformedURLException; |
30 |
import java.net.URL; |
31 |
import java.util.ArrayList; |
32 |
|
33 |
import org.gvsig.compat.net.ICancellable; |
34 |
import org.gvsig.remoteclient.exceptions.ServerErrorException; |
35 |
import org.gvsig.remoteclient.wmts.exception.DownloadException; |
36 |
import org.gvsig.remoteclient.wmts.exception.WMTSException; |
37 |
import org.gvsig.remoteclient.wmts.struct.WMTSLayer; |
38 |
import org.gvsig.remoteclient.wmts.struct.WMTSServiceIdentification; |
39 |
import org.gvsig.remoteclient.wmts.struct.WMTSServiceProvider; |
40 |
import org.gvsig.remoteclient.wmts.struct.WMTSThemes; |
41 |
|
42 |
|
43 |
/**
|
44 |
* <p>Represents the class the with the necessary logic to connect to a OGCWMS and interpretate the data </p>
|
45 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
46 |
*/
|
47 |
public class WMTSClient extends org.gvsig.remoteclient.RasterClient { |
48 |
private org.gvsig.remoteclient.wmts.WMTSProtocolHandler handler = null; |
49 |
private WMTSServerDescription serverDescription = null; |
50 |
protected boolean forceLongitudeFirstAxisOrder = false; |
51 |
|
52 |
/**
|
53 |
* Constructor.
|
54 |
* the parameter host, indicates the WMS host to connect.
|
55 |
* */
|
56 |
public WMTSClient(String host) throws ConnectException, IOException { |
57 |
setHost(host); |
58 |
handler = WMTSProtocolHandlerFactory.negotiate(host); |
59 |
handler.setHost(host); |
60 |
} |
61 |
|
62 |
/**
|
63 |
* Sets longitude first in the axis order
|
64 |
* @param force
|
65 |
*/
|
66 |
public void setForceLongitudeFirstAxisOrder(boolean force) { |
67 |
this.forceLongitudeFirstAxisOrder = force;
|
68 |
if(handler != null) { |
69 |
handler.setForceLongitudeFirstAxisOrder(force); |
70 |
} |
71 |
} |
72 |
|
73 |
public String getVersion() { |
74 |
return handler.getVersion();
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* <p> Reads from the WMS Capabilities, the layers available in the service</p>
|
79 |
* @return a TreeMap with the available layers in the WMS
|
80 |
*/
|
81 |
public ArrayList getLayers() { |
82 |
if(serverDescription != null) |
83 |
return serverDescription.getLayerList();
|
84 |
return null; |
85 |
} |
86 |
|
87 |
/**
|
88 |
* <p>Reads from the WMS Capabilities the number if layers available in the service</p>
|
89 |
* @return, number of layers available
|
90 |
*/
|
91 |
public int getNumberOfLayers() { |
92 |
if(serverDescription != null) |
93 |
return serverDescription.getLayerList().size();
|
94 |
return 0; |
95 |
} |
96 |
|
97 |
public void close() { |
98 |
serverDescription = null;
|
99 |
handler = null;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* <p>Gets a tile downloading using a specific path and file.</p>
|
104 |
* @throws ServerErrorException
|
105 |
*/
|
106 |
public synchronized File getTile(WMTSStatus status, ICancellable cancel, File file) throws WMTSException, ServerErrorException { |
107 |
return handler.getTile(status, cancel, file);
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* <p>One of the three interfaces that OGC WMS defines. Request a map.</p>
|
112 |
* @throws ServerErrorException
|
113 |
*/
|
114 |
public synchronized File getTile(WMTSStatus status, ICancellable cancel) throws WMTSException, ServerErrorException { |
115 |
return handler.getTile(status, cancel);
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* Builds the URL to get a tile using a WMTSStatus object
|
120 |
* @throws ServerErrorException
|
121 |
*/
|
122 |
public synchronized URL getTileURL(WMTSStatus status) throws MalformedURLException { |
123 |
return handler.getTileURL(status);
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* Downloads a file
|
128 |
* @throws DownloadException
|
129 |
* @throws ServerErrorException
|
130 |
*/
|
131 |
public synchronized File downloadFile(URL url, ICancellable cancel) throws DownloadException { |
132 |
return handler.downloadFile(url, cancel);
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* <p>One of the three interfaces defined by OGC WMS, it gets the service capabilities</p>
|
137 |
* @param override, if true the previous downloaded data will be overridden
|
138 |
*/
|
139 |
public void getCapabilities(WMTSServerDescription serverDescription, boolean override, ICancellable cancel) { |
140 |
handler.getCapabilities(serverDescription, override, cancel); |
141 |
} |
142 |
|
143 |
/**
|
144 |
* <p>It will send a GetFeatureInfo request to the WMTS
|
145 |
* Parsing the response and redirecting the info to the WMTS client</p>
|
146 |
*/
|
147 |
public String getFeatureInfo(WMTSStatus status, int x, int y, ICancellable cancel) { |
148 |
return handler.getFeatureInfo(status, x, y, cancel);
|
149 |
} |
150 |
|
151 |
/*
|
152 |
* (non-Javadoc)
|
153 |
* @see org.gvsig.remoteclient.RemoteClient#connect(boolean, org.gvsig.compat.net.ICancellable)
|
154 |
*/
|
155 |
public boolean connect(boolean override, ICancellable cancel) { |
156 |
try {
|
157 |
if (handler == null) { |
158 |
if (getHost().trim().length() > 0) { |
159 |
handler = WMTSProtocolHandlerFactory.negotiate(getHost()); |
160 |
handler.setHost(getHost()); |
161 |
} else {
|
162 |
return false; |
163 |
} |
164 |
} |
165 |
if(serverDescription == null) { |
166 |
serverDescription = new WMTSServerDescription(handler.getVersion());
|
167 |
handler.setServerDescription(serverDescription); |
168 |
handler.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder); |
169 |
} |
170 |
getCapabilities(serverDescription, override, cancel); |
171 |
return true; |
172 |
|
173 |
} catch (Exception e) { |
174 |
e.printStackTrace(); |
175 |
return false; |
176 |
} |
177 |
} |
178 |
|
179 |
public boolean connect(ICancellable cancel) { |
180 |
return connect(false, cancel); |
181 |
} |
182 |
|
183 |
/**
|
184 |
* Gets the list of formats supported by a layer
|
185 |
* @param layerTitle
|
186 |
* @return
|
187 |
*/
|
188 |
public ArrayList getFormats(String layerTitle) { |
189 |
if(serverDescription != null) |
190 |
return serverDescription.getLayerByTitle(layerTitle).getFormat();
|
191 |
return null; |
192 |
} |
193 |
|
194 |
/**
|
195 |
* Gets the host description
|
196 |
* @return
|
197 |
*/
|
198 |
public WMTSServiceIdentification getServiceIdentification() {
|
199 |
if(serverDescription != null) |
200 |
return serverDescription.getServiceIdentification();
|
201 |
return null; |
202 |
} |
203 |
|
204 |
/**
|
205 |
* Gets the host description
|
206 |
* @return
|
207 |
*/
|
208 |
public WMTSServiceProvider getServiceProvider() {
|
209 |
if(serverDescription != null) |
210 |
return serverDescription.getServiceProvider();
|
211 |
return null; |
212 |
} |
213 |
|
214 |
/**
|
215 |
* Gets the list of themes
|
216 |
* @return
|
217 |
*/
|
218 |
public WMTSThemes getThemes() {
|
219 |
if(serverDescription != null) |
220 |
return serverDescription.getThemes();
|
221 |
return null; |
222 |
} |
223 |
|
224 |
/**
|
225 |
* Gets the set of tiles definition
|
226 |
* @return
|
227 |
*/
|
228 |
public ArrayList getTileMatrixSet() { |
229 |
if(serverDescription != null) |
230 |
return serverDescription.getTileMatrixSet();
|
231 |
return null; |
232 |
} |
233 |
|
234 |
/**
|
235 |
* Gets a layer
|
236 |
* @param layerName
|
237 |
* @return
|
238 |
*/
|
239 |
public WMTSLayer getLayer(String layerName) { |
240 |
if(serverDescription != null) { |
241 |
ArrayList list = serverDescription.getLayerList();
|
242 |
for (int i = 0; i < list.size(); i++) { |
243 |
WMTSLayer layer = (WMTSLayer)list.get(i); |
244 |
if(layer.getTitle().compareTo(layerName) == 0) { |
245 |
return layer;
|
246 |
} |
247 |
} |
248 |
} |
249 |
return null; |
250 |
} |
251 |
} |