svn-gvsig-desktop / tags / v1_0_2_RELEASE / extensions / extWCS / src / com / iver / cit / gvsig / fmap / drivers / wcs / FMapWCSDriver.java @ 11432
History | View | Annotate | Download (9.54 KB)
1 | 1877 | luisw | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | 2012 | jaume | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 | 1877 | luisw | *
|
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program 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
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.fmap.drivers.wcs; |
||
42 | |||
43 | 2331 | jaume | import java.awt.geom.Point2D; |
44 | 1961 | jaume | import java.awt.geom.Rectangle2D; |
45 | import java.io.File; |
||
46 | 1877 | luisw | import java.io.IOException; |
47 | 4356 | jaume | import java.net.ConnectException; |
48 | import java.net.URL; |
||
49 | 1886 | luisw | import java.util.ArrayList; |
50 | 4356 | jaume | import java.util.Hashtable; |
51 | 1961 | jaume | import java.util.Iterator; |
52 | 4573 | jaume | import java.util.Set; |
53 | 1877 | luisw | |
54 | 4505 | jaume | import org.gvsig.remoteClient.exceptions.ServerErrorException; |
55 | 4573 | jaume | import org.gvsig.remoteClient.utils.BoundaryBox; |
56 | 4356 | jaume | import org.gvsig.remoteClient.wcs.WCSClient; |
57 | import org.gvsig.remoteClient.wcs.WCSCoverage; |
||
58 | import org.gvsig.remoteClient.wcs.WCSStatus; |
||
59 | 4573 | jaume | import org.gvsig.remoteClient.wcs.WCSCoverage.AxisDescription; |
60 | 5409 | jaume | import org.gvsig.remoteClient.wms.ICancellable; |
61 | 6042 | jaume | import org.gvsig.remoteClient.wms.WMSClient; |
62 | 4356 | jaume | |
63 | 2056 | luisw | import com.iver.cit.gvsig.fmap.DriverException; |
64 | 4573 | jaume | import com.iver.cit.gvsig.fmap.layers.FMapWCSParameter; |
65 | 4356 | jaume | import com.iver.cit.gvsig.fmap.layers.WCSLayer; |
66 | 1877 | luisw | |
67 | 4398 | jaume | |
68 | |||
69 | 1877 | luisw | /**
|
70 | 2097 | jaume | * Driver between the FMap and WCSClient
|
71 | 6042 | jaume | *
|
72 | 2097 | jaume | * Controlador entre FMap y WCSClient
|
73 | 6042 | jaume | *
|
74 | 1877 | luisw | * @author jaume
|
75 | *
|
||
76 | */
|
||
77 | 5409 | jaume | public class FMapWCSDriver { |
78 | 4356 | jaume | private WCSClient client = null; |
79 | private Hashtable coverages; |
||
80 | private WCSLayer[] layerList; |
||
81 | 6042 | jaume | |
82 | 5409 | jaume | |
83 | 9048 | jaume | |
84 | 5409 | jaume | /**
|
85 | * Obtains the host name.
|
||
86 | 6042 | jaume | *
|
87 | 5409 | jaume | * Devuelve el nombre del host.
|
88 | */
|
||
89 | public String getHost() { |
||
90 | 8579 | jaume | return client.getHost();
|
91 | 5409 | jaume | } |
92 | 6042 | jaume | |
93 | private FMapWCSDriver() {}
|
||
94 | 6442 | jaume | |
95 | 6042 | jaume | protected FMapWCSDriver(URL url) throws ConnectException, IOException { |
96 | client = new WCSClient(url.toString());
|
||
97 | } |
||
98 | 5409 | jaume | |
99 | 2064 | jaume | /**
|
100 | 2097 | jaume | * Returns the string "WCSDriver", which is the driver's name.
|
101 | 6042 | jaume | *
|
102 | 2064 | jaume | * Devuelve "WCSDriver", el nombre del driver.
|
103 | 6042 | jaume | * @return String
|
104 | 2064 | jaume | */
|
105 | 6042 | jaume | public String getName() { return "WCSDriver"; } |
106 | |||
107 | 1886 | luisw | /**
|
108 | 2097 | jaume | * Sets the server that we want to connect to.
|
109 | 6042 | jaume | *
|
110 | 2097 | jaume | * Establece el servidor al que se quiere conectar.
|
111 | 6042 | jaume | *
|
112 | 1886 | luisw | * @param host
|
113 | 6042 | jaume | * @throws IOException
|
114 | 1886 | luisw | */
|
115 | 4356 | jaume | public void setHost(String host) throws IOException{ |
116 | client = new WCSClient(host);
|
||
117 | 1877 | luisw | } |
118 | 6042 | jaume | |
119 | |||
120 | 1886 | luisw | /**
|
121 | 2097 | jaume | * Returns a human-readable string containing the server's name.
|
122 | 6042 | jaume | *
|
123 | 1886 | luisw | * Devuelve el nombre legible del servidor devuelto por ?ste.
|
124 | 6042 | jaume | *
|
125 | 1886 | luisw | * @return String
|
126 | 6042 | jaume | */
|
127 | 4356 | jaume | public String getLabel() { |
128 | return client.getServiceTitle();
|
||
129 | 1877 | luisw | } |
130 | 6042 | jaume | |
131 | 1886 | luisw | /**
|
132 | 2097 | jaume | * Returns a string containing the server's WCS version number.
|
133 | 6042 | jaume | *
|
134 | 1886 | luisw | * Devuelve el n?mero de versi?n WCS del servidor
|
135 | 6042 | jaume | *
|
136 | 1886 | luisw | * @return String
|
137 | */
|
||
138 | 1877 | luisw | public String getVersion(){ |
139 | 4356 | jaume | return client.getVersion();
|
140 | 1877 | luisw | } |
141 | 6042 | jaume | |
142 | 1886 | luisw | /**
|
143 | 4356 | jaume | * <p>
|
144 | 2097 | jaume | * Returns name and description of the server. It is supposed to be used
|
145 | * as the source of the abstract field in your application's interface.
|
||
146 | 4356 | jaume | * </p>
|
147 | * <p>
|
||
148 | 1886 | luisw | * Devuelve nombre y descripci?n (abstract) del servidor.
|
149 | 4356 | jaume | * </p>
|
150 | 1886 | luisw | * @return String
|
151 | */
|
||
152 | 1877 | luisw | public String getDescription(){ |
153 | 4356 | jaume | return client.getDescription();
|
154 | 1877 | luisw | } |
155 | 6042 | jaume | |
156 | 1886 | luisw | /**
|
157 | 4718 | jaume | * Returns the layer descriptor for a given coverage name.
|
158 | * @param layerName
|
||
159 | * @return WCSLayer
|
||
160 | 1886 | luisw | */
|
161 | 4627 | jaume | public WCSLayer getLayer(String layerName) { |
162 | 8570 | jorpiell | getLayerList(); |
163 | 4718 | jaume | return (WCSLayer) coverages.get(layerName);
|
164 | 4627 | jaume | } |
165 | 6042 | jaume | |
166 | 4718 | jaume | /**
|
167 | * Returns an array of WCSLayer's with the descriptors of all coverages
|
||
168 | * @return WCSLayer[]
|
||
169 | */
|
||
170 | 4356 | jaume | public WCSLayer[] getLayerList(){ |
171 | 7013 | jaume | if (coverages == null || coverages.isEmpty()) { |
172 | 4356 | jaume | // the WCSLayer collection will be built
|
173 | coverages = new Hashtable(); |
||
174 | Hashtable wcsCoverages = client.getCoverageList();
|
||
175 | int sz = wcsCoverages.size();
|
||
176 | 6042 | jaume | |
177 | 4356 | jaume | // Create an array with the WCSCoverages
|
178 | WCSCoverage[] coverageList = new WCSCoverage[sz]; |
||
179 | Iterator it = wcsCoverages.keySet().iterator();
|
||
180 | int i = 0; |
||
181 | while (it.hasNext()) {
|
||
182 | 4398 | jaume | coverageList[i] = (WCSCoverage) wcsCoverages.get(it.next()); |
183 | 4356 | jaume | i++; |
184 | } |
||
185 | 6042 | jaume | |
186 | 4356 | jaume | // Create a WCSLayer array from the previous WCSCoverage array
|
187 | layerList = new WCSLayer[sz];
|
||
188 | 4398 | jaume | for (int j = 0; j < layerList.length; j++) { |
189 | 4356 | jaume | WCSLayer lyr = new WCSLayer();
|
190 | 4398 | jaume | WCSCoverage cov = coverageList[j]; |
191 | 4573 | jaume | // name
|
192 | 4356 | jaume | lyr.setName(cov.getName()); |
193 | 6042 | jaume | |
194 | 4573 | jaume | // title
|
195 | 4414 | jaume | lyr.setTitle(cov.getTitle()); |
196 | 6042 | jaume | |
197 | 4573 | jaume | // description
|
198 | 4414 | jaume | lyr.setDescription(cov.getAbstract()); |
199 | 6042 | jaume | |
200 | 4573 | jaume | // srs
|
201 | 4356 | jaume | lyr.addAllSrs(cov.getAllSrs()); |
202 | 6042 | jaume | |
203 | 4573 | jaume | // native srs
|
204 | 4356 | jaume | lyr.setNativeSRS(cov.getNativeSRS()); |
205 | 6042 | jaume | |
206 | 4573 | jaume | // extents
|
207 | Set k = cov.getBBoxes().keySet();
|
||
208 | if (!k.isEmpty()) {
|
||
209 | it = k.iterator(); |
||
210 | while (it.hasNext()) {
|
||
211 | String srs = (String) it.next(); |
||
212 | BoundaryBox bBox = cov.getBbox(srs); |
||
213 | Rectangle2D r = new Rectangle2D.Double( |
||
214 | bBox.getXmin(), |
||
215 | 6042 | jaume | bBox.getYmin(), |
216 | bBox.getXmax()-bBox.getXmin(), |
||
217 | 4573 | jaume | bBox.getYmax()-bBox.getYmin() |
218 | ); |
||
219 | lyr.addExtent(srs, r); |
||
220 | } |
||
221 | } |
||
222 | 6042 | jaume | |
223 | 4573 | jaume | // formats
|
224 | 4356 | jaume | lyr.setFormats(cov.getFormats()); |
225 | 6042 | jaume | |
226 | 4573 | jaume | // time positions
|
227 | 4414 | jaume | lyr.setTimePositions(cov.getTimePositions()); |
228 | 6042 | jaume | |
229 | 4573 | jaume | // max res
|
230 | 4356 | jaume | lyr.setMaxRes(new Point2D.Double(cov.getResX(), cov.getResY())); |
231 | 6042 | jaume | |
232 | 4573 | jaume | // interpolations
|
233 | lyr.setInterpolationMethods(cov.getInterpolationMethods()); |
||
234 | 6042 | jaume | |
235 | 4573 | jaume | // parameters
|
236 | k = cov.axisPool.keySet(); |
||
237 | if (!k.isEmpty()) {
|
||
238 | it = k.iterator(); |
||
239 | while (it.hasNext()) {
|
||
240 | AxisDescription ad = (AxisDescription) cov.axisPool.get(it.next()); |
||
241 | FMapWCSParameter p = new FMapWCSParameter();
|
||
242 | p.setName(ad.getName()); |
||
243 | p.setLabel(ad.getLabel()); |
||
244 | p.setType(ad.getInterval()==null? FMapWCSParameter.VALUE_LIST : FMapWCSParameter.INTERVAL);
|
||
245 | 6042 | jaume | if (p.getType()==FMapWCSParameter.VALUE_LIST)
|
246 | 4573 | jaume | p.setValueList(ad.getSingleValues()); |
247 | else
|
||
248 | p.setInterval(ad.getInterval()); |
||
249 | lyr.addParameter(p); |
||
250 | } |
||
251 | } |
||
252 | 4356 | jaume | layerList[j] = lyr; |
253 | coverages.put(lyr.getName(), lyr); |
||
254 | } |
||
255 | } |
||
256 | return layerList;
|
||
257 | 1877 | luisw | } |
258 | 6042 | jaume | |
259 | 1886 | luisw | /**
|
260 | 2097 | jaume | * Establishes the connection to the WCS server. Connecting to a WCS is
|
261 | 4718 | jaume | * an abstraction.<br>
|
262 | * <p>
|
||
263 | * Actually, it sends a GetCapabilities and a general DescribeCoverage
|
||
264 | * request (not a coverage-specific DescribeCoverage request) to read the
|
||
265 | * necessary data for building further GetCoverage requests.
|
||
266 | * </p>
|
||
267 | 9048 | jaume | * @param override
|
268 | 2064 | jaume | * @throws IOException, DriverException.
|
269 | */
|
||
270 | 9048 | jaume | public boolean connect(boolean override, ICancellable cancel) throws IOException, DriverException { |
271 | coverages = null;
|
||
272 | 4614 | jaume | setHost(client.getHost()); |
273 | 9048 | jaume | return client.connect(override, cancel);
|
274 | 1877 | luisw | } |
275 | 4356 | jaume | |
276 | 2097 | jaume | /**
|
277 | * No close operation is needed since WCS service it is a non-session based
|
||
278 | 4718 | jaume | * protocol. So, this does nothing and you can omit it.<br>
|
279 | 2097 | jaume | */
|
280 | 1877 | luisw | public void close() { |
281 | 8765 | jjdelcerro | // connected = false;
|
282 | 1877 | luisw | } |
283 | 1961 | jaume | |
284 | /**
|
||
285 | 2097 | jaume | * Returns the label of an specific coverage given by the coverage name
|
286 | 4718 | jaume | * @param coverage name (string)
|
287 | 2048 | jaume | * @return string
|
288 | */
|
||
289 | public String getLabel(String coverageName) { |
||
290 | 4356 | jaume | return client.getLabel(coverageName);
|
291 | 2048 | jaume | } |
292 | |||
293 | 2064 | jaume | /**
|
294 | 2097 | jaume | * Returns the coverage's MAX extent from the server.
|
295 | 2064 | jaume | * @return Rectangle2D
|
296 | 2069 | jaume | * @throws DriverException
|
297 | * @throws IOException
|
||
298 | 2048 | jaume | */
|
299 | 2069 | jaume | public Rectangle2D getFullExtent(String coverageName, String srs) throws IOException, DriverException { |
300 | 4356 | jaume | return client.getExtent(coverageName, srs);
|
301 | 2048 | jaume | } |
302 | 6042 | jaume | |
303 | 2048 | jaume | /**
|
304 | 2097 | jaume | * Returns the max resolution of a specific coverage given by the coverage's name.
|
305 | 4718 | jaume | * @param coverage name (string)
|
306 | 2048 | jaume | * @return double
|
307 | */
|
||
308 | 2331 | jaume | public Point2D getMaxResolution(String coverageName) { |
309 | 4505 | jaume | if (coverages.containsKey(coverageName)) {
|
310 | return ((WCSLayer) coverages.get(coverageName)).getMaxRes();
|
||
311 | } |
||
312 | 4356 | jaume | return null; |
313 | 2048 | jaume | } |
314 | |||
315 | 2331 | jaume | |
316 | 2048 | jaume | /**
|
317 | 2097 | jaume | * Returns an ArrayList containing a set of Strings with the coverage's SRSs.
|
318 | 4718 | jaume | * @param coverage name (string)
|
319 | 2048 | jaume | * @return ArrayList
|
320 | */
|
||
321 | 6042 | jaume | public ArrayList getSRSs(String coverageName) { |
322 | 4505 | jaume | if (coverages.containsKey(coverageName)) {
|
323 | return ((WCSLayer) coverages.get(coverageName)).getSRSs();
|
||
324 | } |
||
325 | 4356 | jaume | return null; |
326 | 2048 | jaume | } |
327 | |||
328 | /**
|
||
329 | 2097 | jaume | * Returns a String containing a description of an specific coverage.
|
330 | 4718 | jaume | * @param coverage name (string)
|
331 | 2048 | jaume | * @return string
|
332 | */
|
||
333 | public String getCoverageDescription(String coverageName) { |
||
334 | 4505 | jaume | if (coverages.containsKey(coverageName)) {
|
335 | return ((WCSLayer) coverages.get(coverageName)).getDescription();
|
||
336 | } |
||
337 | 4356 | jaume | return null; |
338 | 2048 | jaume | } |
339 | |||
340 | /**
|
||
341 | 2097 | jaume | * Returns an ArrayList containing strings for the time positions of an
|
342 | * specific coverage given by the coverage's name.
|
||
343 | 4718 | jaume | * @param coverage name (string)
|
344 | 2048 | jaume | * @return ArrayList
|
345 | */
|
||
346 | public ArrayList getTimes(String coverageName) { |
||
347 | 4505 | jaume | if (coverages.containsKey(coverageName)) {
|
348 | return ((WCSLayer) coverages.get(coverageName)).getTimePositions();
|
||
349 | } |
||
350 | 2048 | jaume | return null; |
351 | 4356 | jaume | } |
352 | |||
353 | 4718 | jaume | /**
|
354 | * Sends a GetCoverage request to the client.
|
||
355 | * @param status
|
||
356 | * @return
|
||
357 | * @throws WCSException
|
||
358 | */
|
||
359 | 5409 | jaume | public File getCoverage(WCSStatus status, ICancellable cancel) throws WCSException { |
360 | 4505 | jaume | try {
|
361 | 5409 | jaume | return client.getCoverage(status, cancel);
|
362 | 4505 | jaume | } catch (ServerErrorException e) {
|
363 | throw new WCSException("WCS Unexpected server error."+e.getMessage()); |
||
364 | } catch (org.gvsig.remoteClient.exceptions.WCSException e) {
|
||
365 | throw new WCSException(e.getMessage()); |
||
366 | } |
||
367 | 4356 | jaume | } |
368 | 1877 | luisw | } |