Statistics
| Revision:

root / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / drivers / wcs / FMapWCSDriver.java @ 2003

History | View | Annotate | Download (6.98 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 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.Rectangle2D;
44
import java.io.File;
45
import java.io.IOException;
46
import java.util.ArrayList;
47
import java.util.Iterator;
48

    
49
import com.iver.cit.gvsig.fmap.drivers.RemoteServiceDriver;
50
import com.iver.cit.gvsig.fmap.drivers.WCSDriver;
51

    
52
import es.uji.lsi.wcs.XmlWcsParsing.CoverageOffering;
53
import es.uji.lsi.wcs.XmlWcsParsing.GMLEnvelopeWithTimePeriod;
54
import es.uji.lsi.wcs.client.ServerErrorResponseException;
55
import es.uji.lsi.wcs.client.ServerOutOfOrderException;
56
import es.uji.lsi.wcs.client.WCSClient;
57

    
58
/**
59
 * @author jaume
60
 *
61
 */
62
public class FMapWCSDriver implements RemoteServiceDriver, WCSDriver {
63
        private String service_name;
64
        private WCSClient wcs = null;
65
        private String host = null;
66
        
67
        public String getName() { return "WCSDriver"; }
68
        
69
        /**
70
         * Establece el servidor al que se quiere conectar
71
         * 
72
         * @param host
73
         */
74
        public void setHost(String host){
75
                setRemoteServiceName("WCS"); 
76
                this.host = host;
77
                wcs = new WCSClient(host);
78
        }
79
        
80
        public String getHost() { return host; }
81
        
82
        /**
83
         * Env?a la operaci?n GetCapabilities al servidor
84
         * @throws ServerOutOfOrderException
85
         * 
86
         */
87
        public void getCapabilities() throws ServerOutOfOrderException{
88
                wcs.getCapabilities(); 
89
        }
90

    
91
        /**
92
         * Env?a la operaci?n DescribeCoverage
93
         * 
94
         */
95
        public void describeCoverage(){
96
                wcs.describeCoverage();
97
        }
98
        
99
        /**
100
         * Env?a la operaci?n GetCoverage
101
         * 
102
         */
103
        public File getCoverage() throws ServerErrorResponseException{
104
                return wcs.getCoverage();
105
                
106
        }
107

    
108
        /**
109
         * Devuelve el nombre del servidor devuelto por ?ste.
110
         * 
111
         * @return String
112
         */
113
        public String getServerName(){
114
                return wcs.getTheCapabilities().getServiceName();
115
        }
116
        
117
        /**
118
         * Devuelve el nombre legible del servidor devuelto por ?ste.
119
         * 
120
         * @return String
121
         */
122
        public String getLabel(){
123
                return wcs.getTheCapabilities().getServiceLabel();
124
        }
125
        
126
        /**
127
         * Devuelve el n?mero de versi?n WCS del servidor
128
         * 
129
         * @return String
130
         */
131
        public String getVersion(){
132
                return wcs.getTheCapabilities().getVersion();
133
        }
134
        
135
        /**
136
         * Devuelve nombre y descripci?n (abstract) del servidor.
137
         * 
138
         * @return String
139
         */
140
        public String getDescription(){
141
                String name = wcs.getTheCapabilities().getServiceName();
142
                String description = wcs.getTheCapabilities().getServiceDescription();
143
                
144
                if ( (name == null) && (description == null) ) return "Sin descripci?n";
145
                else if ( (name != null) && (description == null) ) return name;
146
                else if ( (name == null) && (description != null) ) return description;
147
                else if ( (name != null) && (description != null) ) return name+"\n\n"+description;
148
                else return null;
149
        }
150
        
151
        /**
152
         * Devuelve el valor de update sequence del servidor
153
         * 
154
         * @return String
155
         */
156
        public String getUpdateSequence(){
157
                return wcs.getTheCapabilities().getUpdateSequence();
158
        }
159
        
160
        /**
161
         * Devuelve una lista de formatos soportados por la capa.
162
         * 
163
         * @param coverage
164
         * @return ArrayList
165
         */
166
        public ArrayList getFormats(String coverage){
167
                return wcs.getCoverageDescription(coverage).getSupportedFormats().getFormats();
168
        }
169
        
170
        /**
171
         * Devuelve el enlace a los metadatos
172
         * 
173
         * @return String
174
         */
175
        public String getMetadataLink(){
176
                return wcs.getTheCapabilities().getServiceMetadatalink();
177
        }
178
        
179
        /**
180
         * Devuelve el valor para responsible party
181
         * 
182
         * @return String
183
         */
184
        public String getResponsibleParty(){
185
                return wcs.getTheCapabilities().getServiceResponsibleParty();
186
        }
187
        
188
        /**
189
         * Devuelve una lista de nombres de coberturas
190
         * 
191
         * @return String[]
192
         */
193
        public String[] getCoverageNames(){
194
                return wcs.getTheCapabilities().getCoverageNames();
195
        }
196
        
197
        /**
198
         * Devuelve el numero de coberturas en el servidor
199
         * 
200
         * @return int
201
         */
202
        public int getNumOfCoverages(){
203
                return getCoverageNames().length;
204
        }
205

    
206
        /** Devuelve los detalles de la cobertura en CoverageOffering
207
         * 
208
         * @param nomCobertura
209
         * @return CoverageOffering (es.uji.lsi.wcs.XmlParsing.CoverageOffering)
210
         */
211
        public CoverageOffering getCoverageDetails(String nomCobertura){
212
                return wcs.getCoverageDescription(nomCobertura);
213
        }
214
        
215
        
216
        public final void setRemoteServiceName(String name) {
217
                service_name = name;
218
        }
219

    
220
        public String getRemoteServiceName() {
221
                return service_name;
222
        }
223

    
224
        public void connect() throws IOException, ServerOutOfOrderException {
225
                // System.out.println("FMapWCSDriver>>> GetCapabilities");
226
                getCapabilities();
227
                // System.out.println("FMapWCSDriver>>> GetCapabilities, done");
228
                // System.out.println("FMapWCSDriver>>> DescribeCoverage (all coverages)");
229
                describeCoverage();
230
                // System.out.println("FMapWCSDriver>>> DescribeCoverage, done");
231
        }
232
        
233
        public void close() {
234
                // No fa res, tal volta this= null?
235
        }
236

    
237
        /**
238
         * @param coverageName
239
         * @param srs
240
         */
241
        public Rectangle2D getBoundingBoxExtensionMaxima(String coverageName, String srs) {
242
                // TODO Has de considerar el cas per a quan el SRS no vinga als RequestResponse 
243
                // ni cap altre...
244
                // IDEA: agafar  algun dels de CoverageOfferingBrief i aplicar la transformaci?.
245
                CoverageOffering co = wcs.getCoverageDescription(coverageName);
246
                if (co.getDomainSet() != null) {
247
                        if (co.getDomainSet().getSpatialDomain() != null){
248
                                ArrayList gewtpList = co.getDomainSet().getSpatialDomain().getGMLEnvelopeWithTimePeriodList();
249
                                Iterator it = gewtpList.iterator();
250
                                while (it.hasNext()){
251
                                        GMLEnvelopeWithTimePeriod gewtp = (GMLEnvelopeWithTimePeriod) it.next();
252
                                        if (gewtp.getSRSName().equals(srs)) {
253
                                                return new Rectangle2D.Double(
254
                                                                gewtp.getMinX(),
255
                                                                gewtp.getMinY(),
256
                                                                gewtp.getMaxX()-gewtp.getMinX(),
257
                                                                gewtp.getMaxY()-gewtp.getMinY());
258
                                        }
259
                                }
260
                        }
261
                }
262
                
263
                // Si llego aqu? es porque no ha habido ninguno. Tengo que transformar de las del BoundingBox.
264
                
265
                return null;
266
        }
267

    
268
        /**
269
         * Env?a los valores de la consulta GetCoverage en forma cadena de pares 
270
         * 'nombre=valor' separados por '&'.
271
         */
272
        public void setGetCoverageParams(String query) {
273
                wcs.setGetCoverageParams(query);
274
                
275
        }
276
}