Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / drivers / wcs / FMapWCSDriver.java @ 4573

History | View | Annotate | Download (10.2 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
*
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
import java.awt.geom.Point2D;
44
import java.awt.geom.Rectangle2D;
45
import java.io.File;
46
import java.io.IOException;
47
import java.net.ConnectException;
48
import java.net.URL;
49
import java.util.ArrayList;
50
import java.util.Hashtable;
51
import java.util.Iterator;
52
import java.util.Set;
53

    
54
import org.gvsig.remoteClient.exceptions.ServerErrorException;
55
import org.gvsig.remoteClient.utils.BoundaryBox;
56
import org.gvsig.remoteClient.wcs.WCSClient;
57
import org.gvsig.remoteClient.wcs.WCSCoverage;
58
import org.gvsig.remoteClient.wcs.WCSStatus;
59
import org.gvsig.remoteClient.wcs.WCSCoverage.AxisDescription;
60

    
61
import com.iver.cit.gvsig.fmap.DriverException;
62
import com.iver.cit.gvsig.fmap.drivers.RemoteServiceDriver;
63
import com.iver.cit.gvsig.fmap.drivers.WCSException;
64
import com.iver.cit.gvsig.fmap.layers.FMapWCSParameter;
65
import com.iver.cit.gvsig.fmap.layers.WCSLayer;
66

    
67

    
68

    
69
/**
70
 * Driver between the FMap and WCSClient
71
 * 
72
 * Controlador entre FMap y WCSClient
73
 * 
74
 * @author jaume
75
 *
76
 */
77
public class FMapWCSDriver extends RemoteServiceDriver {
78
        private WCSClient client = null;
79
        private Hashtable coverages;
80
        private WCSLayer[] layerList;
81
        
82
        
83
        /**
84
         * Returns the string "WCSDriver", which is the driver's name.
85
         * 
86
         * Devuelve "WCSDriver", el nombre del driver.
87
         * @return String 
88
         */
89
        public String getName() { return "WCSDriver"; } 
90
        
91
        /**
92
         * Sets the server that we want to connect to.
93
         * 
94
         * Establece el servidor al que se quiere conectar.
95
         * 
96
         * @param host
97
         * @throws IOException 
98
         */
99
        public void setHost(String host) throws IOException{
100
                super.setHost(host);
101
                setServiceName("WCS"); 
102
                client = new WCSClient(host);
103
        }
104
        
105
        
106
        /**
107
         * Returns a human-readable string containing the server's name.
108
         * 
109
         * Devuelve el nombre legible del servidor devuelto por ?ste.
110
         * 
111
         * @return String
112
         */ 
113
        public String getLabel() {
114
                return client.getServiceTitle();
115
        }
116
        
117
        /**
118
         * Returns a string containing the server's WCS version number.
119
         * 
120
         * Devuelve el n?mero de versi?n WCS del servidor
121
         * 
122
         * @return String
123
         */
124
        public String getVersion(){
125
                return client.getVersion();
126
        }
127
        
128
        /**
129
         * <p>
130
         * Returns name and description of the server. It is supposed to be used
131
         * as the source of the abstract field in your application's interface.
132
         * </p>
133
         * <p>
134
         * Devuelve nombre y descripci?n (abstract) del servidor.
135
         * </p>
136
         * @return String
137
         */
138
        public String getDescription(){
139
                return client.getDescription();
140
        }
141
        
142
        
143
        /**
144
         * Returns a list containing the formats supported by the coverage
145
         * 
146
         * Devuelve una lista de formatos soportados por la cobertura.
147
         * 
148
         * @param coverage
149
         * @return ArrayList
150
         */
151
        public ArrayList getFormats(String coverage){
152
                return client.getFormats();
153
        }
154
        
155
        
156
        public WCSLayer[] getLayerList(){
157
                if (coverages == null) {
158
                        // the WCSLayer collection will be built
159
                        coverages = new Hashtable();
160
                        Hashtable wcsCoverages  = client.getCoverageList();
161
                        int sz = wcsCoverages.size();
162
                        
163
                        // Create an array with the WCSCoverages
164
                        WCSCoverage[] coverageList = new WCSCoverage[sz];
165
                        Iterator it = wcsCoverages.keySet().iterator();
166
                        int i = 0;
167
                        while (it.hasNext()) {
168
                                coverageList[i] = (WCSCoverage) wcsCoverages.get(it.next());
169
                                i++;
170
                        }
171
                        
172
                        // Create a WCSLayer array from the previous WCSCoverage array
173
                        layerList = new WCSLayer[sz];
174
                        for (int j = 0; j < layerList.length; j++) {
175
                                WCSLayer lyr = new WCSLayer();
176
                                WCSCoverage cov = coverageList[j];
177
                                // name
178
                                lyr.setName(cov.getName());
179
                                
180
                                // title
181
                                lyr.setTitle(cov.getTitle());
182
                                
183
                                // description
184
                                lyr.setDescription(cov.getAbstract());
185
                                
186
                                // srs
187
                                lyr.addAllSrs(cov.getAllSrs());
188
                                
189
                                // native srs
190
                                lyr.setNativeSRS(cov.getNativeSRS());
191
                                
192
                                // extents
193
                                Set k = cov.getBBoxes().keySet();
194
                                if (!k.isEmpty()) {
195
                                        it = k.iterator();
196
                                        while (it.hasNext()) {
197
                                                String srs = (String) it.next();
198
                                                BoundaryBox bBox = cov.getBbox(srs);
199
                                                Rectangle2D r = new Rectangle2D.Double(
200
                                                                                                bBox.getXmin(),
201
                                                                                                bBox.getYmin(), 
202
                                                                                                bBox.getXmax()-bBox.getXmin(), 
203
                                                                                                bBox.getYmax()-bBox.getYmin()
204
                                                                                                );
205
                                                lyr.addExtent(srs, r);
206
                                                }
207
                                }
208
                                
209
                                // formats
210
                                lyr.setFormats(cov.getFormats());
211
                                
212
                                // time positions
213
                                lyr.setTimePositions(cov.getTimePositions());
214
                                
215
                                // max res
216
                                lyr.setMaxRes(new Point2D.Double(cov.getResX(), cov.getResY()));
217
                                
218
                                // interpolations
219
                                lyr.setInterpolationMethods(cov.getInterpolationMethods());
220
                                
221
                                // parameters
222
                                k = cov.axisPool.keySet();
223
                                if (!k.isEmpty()) {
224
                                        it = k.iterator();
225
                                        while (it.hasNext()) {
226
                                                AxisDescription ad = (AxisDescription) cov.axisPool.get(it.next());
227
                                                FMapWCSParameter p = new FMapWCSParameter();
228
                                                p.setName(ad.getName());
229
                                                p.setLabel(ad.getLabel());
230
                                                p.setType(ad.getInterval()==null? FMapWCSParameter.VALUE_LIST : FMapWCSParameter.INTERVAL);
231
                                                if (p.getType()==FMapWCSParameter.VALUE_LIST) 
232
                                                        p.setValueList(ad.getSingleValues());
233
                                                else
234
                                                        p.setInterval(ad.getInterval());
235
                                                lyr.addParameter(p);
236
                                        }
237
                                }
238
                                layerList[j] = lyr;
239
                                coverages.put(lyr.getName(), lyr);
240
                        }
241
                }
242
                
243
                return layerList;
244
        }
245
        
246
        /**
247
         * Establishes the connection to the WCS server. Connecting to a WCS is
248
         * an abstraction, it actually sends a GetCapabilities and a general 
249
         * DescribeCoverage request (not a coverage-specific DescribeCoverage request)
250
         * to read the necessary data for building further GetCoverage requests.
251
         * 
252
         * 
253
         * La conexi?n a un servidor WCS es una abstracci?n de dos operaciones:
254
         * GetCapabilities y DescribeCoverage. Con ellas, se obtienen los datos
255
         * necesarios para poder operar con el servidor.
256
         * 
257
         * 
258
         * @throws IOException, DriverException.
259
         */
260
        public boolean connect() throws IOException, DriverException {
261
                return client.connect();
262
        }
263

    
264
        /**
265
         * No close operation is needed since WCS service it is a non-session based
266
         * protocol. So, this does nothing and you can omit it.
267
         * 
268
         * La operaci?n close no es necesaria en un servicio WCS ya que este se implementa
269
         * sobre un protocolo no orientado a sesiones. As? que esto no hace nada y puede
270
         * ser omitido.
271
         * 
272
         */
273
        public void close() {
274
                setConnected(false);
275
        }
276

    
277
        /**
278
         * Returns the label of an specific coverage given by the coverage name
279
         * 
280
         * Obtiene la etiqueta de una cobertura espec?fica
281
         * 
282
         * @param nombre de la cobertura (string)
283
         * @return string
284
         */
285
        public String getLabel(String coverageName) {
286
                return client.getLabel(coverageName);
287
        }
288

    
289
        /**
290
         * Returns the coverage's MAX extent from the server.
291
         * 
292
         * Obtiene la M?XIMA extensi?n de la cobertura de el servidor.
293
         * @return Rectangle2D
294
         * @throws DriverException
295
         * @throws IOException
296
         */
297
        public Rectangle2D getFullExtent(String coverageName, String srs) throws IOException, DriverException {
298
                return client.getExtent(coverageName, srs);
299
        }
300
        
301
        /**
302
         * Returns the max resolution of a specific coverage given by the coverage's name.
303
         * 
304
         * Obtiene la resoluci?n m?xima de una cobertura espec?fica
305
         * @param nombre de la cobertura (string)
306
         * @return double
307
         */
308
        public Point2D getMaxResolution(String coverageName) {
309
                if (coverages.containsKey(coverageName)) {
310
                        return ((WCSLayer) coverages.get(coverageName)).getMaxRes();
311
                }
312
                return null;
313
        }
314

    
315

    
316
        /**
317
         * Returns an ArrayList containing a set of Strings with the coverage's SRSs.
318
         * 
319
         * Obtiene un ArrayList con los SRS de una cobertura espec?fica
320
         * @param Nombre de la cobertura (string)
321
         * @return ArrayList
322
         */
323
        public ArrayList getSRSs(String coverageName) {        
324
                if (coverages.containsKey(coverageName)) {
325
                        return ((WCSLayer) coverages.get(coverageName)).getSRSs();
326
                }
327
                return null;
328
        }
329

    
330
        /**
331
         * Returns a String containing a description of an specific coverage.
332
         * 
333
         * Obtiene la descripci?n de una cobertura espec?fica
334
         * @param Nombre de la cobertura (string)
335
         * @return string
336
         */
337
        public String getCoverageDescription(String coverageName) {
338
                if (coverages.containsKey(coverageName)) {
339
                        return ((WCSLayer) coverages.get(coverageName)).getDescription();
340
                }
341
                return null;
342
        }
343

    
344
        /**
345
         * Returns an ArrayList containing strings for the time positions of an
346
         * specific coverage given by the coverage's name.
347
         * 
348
         * Obtiene la lista de tiempos de una cobertura espec?fica
349
         * @param nombre de la cobertura (string)
350
         * @return ArrayList
351
         */
352
        public ArrayList getTimes(String coverageName) {
353
                if (coverages.containsKey(coverageName)) {
354
                        return ((WCSLayer) coverages.get(coverageName)).getTimePositions();
355
                }
356
                return null;
357
        }
358

    
359
        public File getCoverage(WCSStatus status) throws WCSException {
360
                try {
361
                        return client.getCoverage(status);
362
                } 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
        }
368

    
369
        /**
370
     * Creates a new instance of a WCSClient.
371
     * @param host
372
     * @throws IOException 
373
     * @throws ConnectException 
374
     */
375
        public void createClient(URL host) throws ConnectException, IOException{
376
                client = new WCSClient(host.toString());
377
        } 
378
}