Statistics
| Revision:

root / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / layers / FLyrWCS.java @ 2869

History | View | Annotate | Download (23.4 KB)

1 1877 luisw
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2 1979 jaume
 *
3 2017 igbrotru
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4 1979 jaume
 *
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 1877 luisw
package com.iver.cit.gvsig.fmap.layers;
42
43 2420 jaume
import java.awt.Component;
44 1877 luisw
import java.awt.Graphics2D;
45 2623 nacho
import java.awt.Point;
46 2330 jaume
import java.awt.geom.Point2D;
47 1877 luisw
import java.awt.geom.Rectangle2D;
48
import java.awt.image.BufferedImage;
49 1986 jaume
import java.io.IOException;
50 2623 nacho
import java.lang.reflect.Constructor;
51
import java.lang.reflect.InvocationTargetException;
52
import java.util.ArrayList;
53 2648 jaume
import java.util.Hashtable;
54 2071 luisw
import java.util.TreeMap;
55 1877 luisw
56 1961 jaume
import javax.swing.JOptionPane;
57
58 2623 nacho
import org.cresques.io.GeoRasterFile;
59
import org.cresques.io.raster.RasterFilterStack;
60
61 2420 jaume
import com.iver.andami.PluginServices;
62 1877 luisw
import com.iver.cit.gvsig.fmap.DriverException;
63
import com.iver.cit.gvsig.fmap.ViewPort;
64 1979 jaume
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
65 1961 jaume
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver;
66 1877 luisw
import com.iver.cit.gvsig.fmap.operations.Cancellable;
67 2071 luisw
import com.iver.cit.gvsig.fmap.services.OGCWCSService;
68 1979 jaume
import com.iver.utiles.StringUtilities;
69
import com.iver.utiles.XMLEntity;
70 1877 luisw
71 2420 jaume
import es.uji.lsi.wcs.client.ServerErrorResponseException;
72
73 1877 luisw
/**
74 2097 jaume
 * Class for the WCS layer.
75
 *
76 1961 jaume
 * Capa para el WCS.
77 1979 jaume
 *
78 1877 luisw
 * @author jaume - jaume.dominguez@iver.es
79
 */
80 2646 jaume
public class FLyrWCS extends FLyrDefault implements RasterOperations{
81 2644 jaume
        private FMapWCSAdapter wcs = null;
82 2420 jaume
83 2623 nacho
        private String                                                 label;
84
        private StatusRasterInterface                status = null;
85 2651 nacho
        private int                                                 posX = 0, posY = 0;
86
        private double                                                 posXWC = 0, posYWC = 0;
87
        private int                                                 r = 0, g = 0, b = 0;
88 2641 nacho
89 1877 luisw
90 1979 jaume
        /**
91 2094 jaume
         * Returns the XMLEntity containing the necessary info for reproduce
92
         * the layer.
93 1979 jaume
         *
94 2094 jaume
         * Devuelve el XMLEntity con la informaci?n necesaria para reproducir
95
         * la capa.
96
         *
97 1979 jaume
         * @return XMLEntity.
98
         * @throws XMLException
99 1877 luisw
         */
100 1979 jaume
        public XMLEntity getXMLEntity() throws XMLException {
101
                XMLEntity xml = super.getXMLEntity();
102
103 2003 jaume
                xml.putProperty("wcs.host", getHost());
104 2069 jaume
                try {
105
            xml.putProperty("wcs.fullExtent",
106
                    StringUtilities.rect2String(wcs.getFullExtent()));
107
        } catch (IOException e) {
108
        } catch (DriverException e) {
109
        }
110 2003 jaume
                xml.putProperty("wcs.layerQuery", wcs.getCoverageQuery());
111
                xml.putProperty("wcs.format", getFormat());
112
                xml.putProperty("wcs.srs", getSRS());
113
                xml.putProperty("wcs.time", getTime());
114
                xml.putProperty("wcs.parameter", getParameter());
115 1979 jaume
                xml.putProperty("wcs.label", label);
116 2003 jaume
                xml.putProperty("wcs.coverageName", getCoverageName());
117 2330 jaume
                xml.putProperty("wcs.maxResX", getMaxResolution().getX());
118
                xml.putProperty("wcs.maxResY", getMaxResolution().getY());
119 2646 jaume
                if (status!=null)
120 2623 nacho
                        status.getXMLEntity(xml, true, this);
121 2764 nacho
                else{
122
                        status = new StatusLayerRaster();
123
                        status.getXMLEntity(xml, true, this);
124
                }
125 1979 jaume
                return xml;
126
        }
127
128
        /**
129 2094 jaume
         * Reproduces the layer from an XMLEntity.
130
         *
131 1979 jaume
         * A partir del XMLEntity reproduce la capa.
132
         *
133
          * @param xml XMLEntity
134
         *
135
         * @throws XMLException
136
         * @throws DriverException
137
         * @throws DriverIOException
138
         */
139
        public void setXMLEntity(XMLEntity xml) throws XMLException {
140
                super.setXMLEntity(xml);
141 2026 luisw
                //System.out.println(" Cargo la capa WCS. ... o no ;-)");
142 2003 jaume
                setHost(xml.getStringProperty("wcs.host"));
143
                setFullExtent(StringUtilities.string2Rect(
144
                        xml.getStringProperty("wcs.fullExtent")));
145
                wcs.setCoverageQuery(xml.getStringProperty("wcs.layerQuery"));
146
                setFormat(xml.getStringProperty("wcs.format"));
147
                setSRS(xml.getStringProperty("wcs.srs"));
148
                setTime(xml.getStringProperty("wcs.time"));
149
                setParameter(xml.getStringProperty("wcs.parameter"));
150 1979 jaume
                label = xml.getStringProperty("wcs.label");
151 2003 jaume
                setCoverageName(xml.getStringProperty("wcs.coverageName"));
152 2330 jaume
                if (xml.contains("wcs.maxRes"))
153
                        setMaxResolution(new Point2D.Double(xml.getDoubleProperty("wcs.maxRes"), xml.getDoubleProperty("wcs.maxRes")));
154
                else if (xml.contains("wcs.maxResX") && xml.contains("wcs.maxResY"))
155
                        setMaxResolution(new Point2D.Double(xml.getDoubleProperty("wcs.maxResX"), xml.getDoubleProperty("wcs.maxResY")));
156 2644 jaume
157 2330 jaume
158 2623 nacho
                String claseStr = null;
159
                if (xml.contains("raster.class")) {
160
                        claseStr = xml.getStringProperty("raster.class");
161
                }
162
                if(status!=null)
163
                        status.setXMLEntity(xml, this);
164
                else{
165
166
                        //Cuando cargamos un proyecto
167
168
                        if(claseStr!=null && !claseStr.equals("")){
169
                                try{
170
                                        Class clase = Class.forName(claseStr);
171
                                        Constructor constr = clase.getConstructor(null);
172
                                        status = (StatusRasterInterface)constr.newInstance(null);
173
                                        if(status!=null)
174
                                                status.setXMLEntity(xml, this);
175
                                }catch(ClassNotFoundException exc){
176
                                        exc.printStackTrace();
177
                                }catch(InstantiationException exc){
178
                                        exc.printStackTrace();
179
                                }catch(IllegalAccessException exc){
180
                                        exc.printStackTrace();
181
                                }catch(NoSuchMethodException exc){
182
                                        exc.printStackTrace();
183
                                }catch(InvocationTargetException exc){
184
                                        exc.printStackTrace();
185
                                }
186
                        }
187
                }
188 2641 nacho
                wcs.firstLoad = true;
189 1979 jaume
        }
190
191
        /**
192 2094 jaume
         * The full extent of the layer.
193 1979 jaume
         *
194 2094 jaume
         * La extensi?n completa de la layer.
195
         *
196 1979 jaume
         * @return Rectangle2D
197
         */
198 2069 jaume
        public Rectangle2D getFullExtent(){// throws DriverException {
199
                try {
200
            return getWCSAdaptor().getFullExtent();
201
        } catch (IOException e) {
202 2644 jaume
            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
203
                            "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE);
204 2069 jaume
        } catch (DriverException e) {
205 2644 jaume
            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
206
                            "servidor_wcs_no_responde", "Error", JOptionPane.ERROR_MESSAGE);
207 2069 jaume
        }
208
        return null;
209 1877 luisw
        }
210
211 1979 jaume
        /**
212 2094 jaume
         * Draws the layer on the ViewPort using PxRaster.
213
         *
214
         * Dibuja la capa en el ViewPort con PxRaster.
215 1877 luisw
         */
216 2644 jaume
        public void draw(BufferedImage image, Graphics2D g,
217 2533 luisw2
                        ViewPort viewPort, Cancellable cancel, double scale) throws DriverException {
218 2420 jaume
                /* This try loop I've moved here is for show an alert window when it is not
219
                 * possible to download the coverage.
220
                 */
221
                        try {
222 2534 jaume
                                if (!isWithinScale(scale))
223
                                        return;
224 2623 nacho
225 2641 nacho
                                if(status!=null && wcs.firstLoad){
226 2623 nacho
                                        wcs.draw(image, g, viewPort, cancel);
227
                                        status.applyStatus(this);
228 2641 nacho
                                        wcs.firstLoad = false;
229 2623 nacho
                                }
230
231 2420 jaume
                                wcs.draw(image, g, viewPort, cancel);
232
                        } catch (ServerErrorResponseException e) {
233
                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage(), "Error",
234
                                                JOptionPane.ERROR_MESSAGE);
235
                        }
236 1961 jaume
        }
237 2094 jaume
        /**
238
         * Prints the layer.
239
         *
240
         * Imprime la cobertura.
241
         */
242 2533 luisw2
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale)
243 1877 luisw
                        throws DriverException {
244 2534 jaume
                draw(null, g, viewPort, cancel, scale);
245 1877 luisw
        }
246 1979 jaume
247 1961 jaume
        /**
248 2094 jaume
         * Sets the layer's label. That what is going to be used at the TOC.
249 1979 jaume
         *
250 2094 jaume
         * Establece la etiqueta de la cobertura. La que se usar? en el TOC.
251
         *
252 1979 jaume
         * @param lbl
253
         */
254
        public void setLabel(String lbl) {
255 1961 jaume
                label = lbl;
256
        }
257 1979 jaume
258 2094 jaume
        /**
259
         * Sets the layer's full extent.
260
         *
261
         * Establece la extensi?n m?xima de la capa.
262
         *
263
         * @param rect
264
         */
265 1979 jaume
        public void setFullExtent(Rectangle2D rect) {
266 2003 jaume
                wcs.setFullExtent(rect);
267 1961 jaume
        }
268 1979 jaume
269 1963 jaume
        /**
270 2094 jaume
         * Recovers the name of the layer shown on the TOC. The text used for the name
271
         * is not the actual coverage's name but that what appears in the wizard's text
272
         * field which initially correponds with the "label" specified by the server for
273
         * the coverage and may be edited by the user for choose whatever she/he wants.
274
         *
275 1979 jaume
         * Recupera el nom de la capa mostrada al TOC. El text per al nom no ?s el
276 2644 jaume
         * nom de la cobertura sin? el text que apareix al camp de text del wizard,
277 1979 jaume
         * que es correspon amb la "label" que el servidor especifica per a la
278
         * covertura, i pot ser modificat per l'usuari al wizard per a gastar el que
279
         * dessitge.
280 1961 jaume
         *
281
         * @return String
282
         */
283 1979 jaume
        public String getLabel() {
284 1961 jaume
                return this.label;
285
        }
286 1979 jaume
287 2644 jaume
//        /**
288
//         * Sets TabbedPane shown when WCS_Properties is clicked within the TOC.
289
//         *
290
//         * Establece el TabbedPane mostrado cuando se clica en WCS_Properties dentro del TOC.
291
//         *
292
//         * @param panel
293
//         */
294
//        public void setToc(WCSParamsPanel panel) {
295
//                toc = panel;
296
//        }
297 1979 jaume
298 2644 jaume
        public Hashtable getWCSProperties(){
299
                Hashtable info = new Hashtable();
300
                info.put("name", getCoverageName());
301
                info.put("host", getHost());
302
                info.put("crs", wcs.getSRS());
303
                info.put("format", wcs.getFormat());
304
                String str = wcs.getTime();
305
                if (str==null)
306
                        str = "";
307
                info.put("time", str);
308
                str = wcs.getParameter();
309
                if (str==null)
310
                        str = "";
311
                info.put("parameter", str);
312
313
                return info;
314 1979 jaume
        }
315 2644 jaume
316 2048 jaume
317 2064 jaume
        /**
318 2094 jaume
         * Returns the coverage name.
319
         *
320
         * Obtiene el nombre de la cobertura.
321 2064 jaume
         * @return String
322
         */
323 2003 jaume
        public String getCoverageName() {
324
                return wcs.getCoverageName();
325
        }
326 2048 jaume
327 2064 jaume
        /**
328 2094 jaume
         * Returns the coverage format.
329
         *
330
         * Obtiene el formato en que la cobertura est? codificado.
331 2064 jaume
         * @return String
332
         */
333 2003 jaume
        public String getFormat() {
334
                return wcs.getFormat();
335
        }
336 2048 jaume
337 2064 jaume
        /**
338 2094 jaume
         * Returns the WCS server URL.
339
         *
340 2064 jaume
         * Obtiene la direcci?n URL del servidor WCS
341
         *
342
         * @return String
343
         */
344 2003 jaume
        public String getHost() {
345
                return wcs.getHost();
346
        }
347 2048 jaume
348 2064 jaume
        /**
349 2094 jaume
         * Returns the parameter value.
350
         *
351
         * Obtiene el valor del par?metro.
352 2064 jaume
         * @return String
353
         */
354 2003 jaume
        public String getParameter() {
355
                return wcs.getParameter();
356
        }
357 2048 jaume
358 2064 jaume
        /**
359 2094 jaume
         * Returns the current SRS.
360
         *
361
         * Obtiene el SRS actual de la cobertura.
362 2064 jaume
         * @return String
363
         */
364 2003 jaume
        public String getSRS() {
365
                return wcs.getSRS();
366
        }
367 2048 jaume
368 2094 jaume
        /**
369
         * Returns the TIME value in the WCS query.
370
         *
371
         * Obtiene el valor para TIME en la consulta WCS.
372
         * @return String
373
         */
374 2003 jaume
        public String getTime() {
375
                return wcs.getTime();
376
        }
377 2048 jaume
378 2064 jaume
        /**
379 2094 jaume
         * Sets the FORMAT parameter that we are requesting the WCS coverage.
380
         *
381
         * Establece el par?metro FORMAT en que se pide la cobertura WCS
382 2064 jaume
         * @param format
383
         */
384 2003 jaume
        public void setFormat(String format) {
385
                wcs.setFormat(format);
386
        }
387 2048 jaume
388 2064 jaume
        /**
389 2094 jaume
         * Sets the server's URL.
390
         *
391 2064 jaume
         * Establece la direcci?n URL del servidor WCS
392
         * @param host
393
         */
394 2003 jaume
        public void setHost(String host) {
395
                if (wcs == null) {
396 2644 jaume
                        wcs = new FMapWCSAdapter();
397 2048 jaume
                        wcs.setDriver(new FMapWCSDriver());
398 2003 jaume
                }
399
                wcs.setHost(host);
400
        }
401 2064 jaume
402
        /**
403 2094 jaume
         * Sets the parameter. It is defined by a name-value pair and the value is
404
         * a comma-separated list of values.
405
         *
406 2064 jaume
         * Establece el nombre y el valor (lista de valores separados por comas)
407
         * del par?metro de la consulta WCS
408
         * @param parameter
409
         */
410 2003 jaume
        public void setParameter(String parameter) {
411
                wcs.setParameter(parameter);
412
        }
413 2064 jaume
414
        /**
415 2094 jaume
         * Sets the SRS parameter within the WCS query.
416
         *
417
         * Establece el SRS de la consulta WCS.
418 2064 jaume
         * @param srs
419
         */
420 2003 jaume
        public void setSRS(String srs) {
421
                wcs.setSRS(srs);
422
        }
423 2064 jaume
424
        /**
425 2094 jaume
         * Sets the TIME parameter within the WCS query.
426
         *
427
         * Establece el par?metro TIME de la consulta WCS.
428 2064 jaume
         * @param time
429
         */
430 2003 jaume
        public void setTime(String time) {
431 2644 jaume
                 wcs.setTime(time);
432 2003 jaume
        }
433 2064 jaume
434
        /**
435 2094 jaume
         * Sets the COVERAGE parameter within the WCS query.
436
         *
437
         * Establece el par?metro COVERAGE de la consulta WCS.
438 2064 jaume
         * @param coverageName
439
         */
440 2003 jaume
        public void setCoverageName(String coverageName) {
441
                wcs.setCoverageName(coverageName);
442
        }
443
444 2064 jaume
        /**
445 2094 jaume
         * Gets the max resolution allowed by the coverage. Requesting a higher resolution
446
         * than this value does not cause any error, but the info responsed is just an
447
         * interpolation.
448
         *
449
         * In exchange for obtaining a greater file and without additional information,
450
         * we can easily connect it at the View.
451
         *
452
         *
453 2064 jaume
         * Obtiene la resoluci?n m?xima soportada por la cobertura. La petici?n
454
         * de una resoluci?n superior a la soportada no provoca ning?n error, aunque
455
         * la informaci?n obtenida s?lo es una mera interpolaci?n de informaci?n.
456
         *
457
         * A cambio de obtener un archivo mayor y sin informaci?n adicional, podemos
458
         * f?cilmente acoplarlo a la vista.
459
         *
460
         * @return double
461
         */
462 2330 jaume
        public Point2D getMaxResolution() {
463 2005 jaume
                return wcs.getMaxResolution();
464
        }
465
466 2064 jaume
        /**
467 2094 jaume
         * Sets the MAX resolution supported by the coverage.
468
         *
469
         * The max resolution is given by the server within the DescribeCoverage document
470
         * in the SpationDomain section.
471
         *
472
         * Use this method only to load this value from there (the DescribeCoverage document)
473
         * of from an already saved project because an incorrect value will bring
474
         * computing errors when doing "zoom to raster resolution".
475
         *
476
         *
477
         *
478 2064 jaume
         * Establece la resoluci?n M?XIMA que soporta la cobertura.
479
         *
480
         * La resoluci?n m?xima viene fijada por el servidor dentro documento
481
         * DescribeCoverage en la secci?n SpatialDomain.
482
         *
483
         * Use este m?todo ?nicamente para cargar el valor para la resoluci?n m?xima
484
         * desde all? o desde un proyecto guardado en anterioridad, puesto que un
485
         * valor incorrecto reportar? (conllevar?) errores de c?lculo cuando se haga
486
         * un "zoom a la resoluci?n del r?ster".
487
         *
488
         * @param res
489
         */
490 2330 jaume
        //public void setMaxResolution(double res){
491
        public void setMaxResolution(Point2D res){
492 2005 jaume
                wcs.setMaxResolution(res);
493
        }
494
495 2017 igbrotru
        /**
496 2094 jaume
         * Returns the adaptor.
497
         *
498
         * Obtiene el adaptor.
499
         */
500 2644 jaume
        public FMapWCSAdapter getWCSAdaptor(){
501 2067 jaume
            return wcs;
502 2017 igbrotru
        }
503
504 2064 jaume
        /**
505 2094 jaume
         * Sets the adaptor.
506
         *
507 2064 jaume
         * Establece el adaptador.
508 2094 jaume
         *
509 2064 jaume
         * @deprecated
510
         * @param wcs
511
         */
512 2644 jaume
        public void setWCSAdaptor(FMapWCSAdapter wcs){
513 2048 jaume
                this.wcs = wcs;
514
        }
515
516 2064 jaume
        /**
517 2094 jaume
         * Returns the bounding box that is being used.
518
         *
519 2064 jaume
         * Obtiene la Bounding Box sobre la que se est? operando
520
         * @return Rectangle2D
521
         */
522
        private Rectangle2D getBbox() {
523 2012 jaume
                return wcs.getBbox();
524
        }
525
526
        /**
527 2094 jaume
         * Returns the current resolution for the coverage at the view.
528
         *
529
         * Obtiene la resoluci?n actual para la cobertura de la vista.
530 2012 jaume
         * @return
531
         */
532 2330 jaume
        private Point2D getRes() {
533 2012 jaume
                return wcs.getRes();
534
        }
535
536
        /**
537 2097 jaume
         * Sets the current resolution for the coverage at the view.
538
         * This value is automatically calculated by gvSIG. Thus, this method should
539
         * be used only to reload this value from a previously saved project.
540 2094 jaume
         *
541 2064 jaume
         * Establece la resoluci?n actual para la cobertura de la vista.
542
         * Este valor es calculado autom?ticamente por gvSIG. ?ste m?todo deber?a
543
         * ser usado ?nicamente para recuperar este valor de un proyecto
544
         * anteriormente guardado.
545 2012 jaume
         * @param res
546
         */
547 2330 jaume
        //private void setRes(double res) {
548
        private void setRes(Point2D res) {
549 2012 jaume
                wcs.setRes(res);
550
        }
551
552 2064 jaume
        /**
553 2097 jaume
         * Sets the area of the coverage to request.
554
         * This value is automatically calculated by gvSIG. Thus, this method should
555
         * be used only to reload this value from a previuosly saved project.
556
         *
557 2064 jaume
         * Establece el ?rea de la cobertura a pedir.
558
         * Este valor es calculado autom?ticamente por gvSIG. ?ste m?todo deber?a
559
         * ser usado ?nicamente para recuperar el valor de un proyecto anteriormente
560
         * guardado.
561
         *
562
         * @param rect
563
         */
564 2097 jaume
        private void setBBox(Rectangle2D rect) {
565 2012 jaume
                wcs.setBBox(rect);
566
        }
567 2094 jaume
568 2064 jaume
        /**
569 2097 jaume
         * Builds a coverage starting from a full GetCoverage URL.
570
         * (Using this is not a regular function)
571
         *
572 2067 jaume
         * Inicializa una cobertura a partir de una URL GetCoverage completa.
573 2097 jaume
         * (To use this method supposes to skip all the regular operation)
574 2067 jaume
         *
575 2064 jaume
         */
576
        public void initFromQueryString(String queryString){
577 2420 jaume
                System.out.println("Query = "+queryString);
578 2071 luisw
                TreeMap map = new TreeMap();
579 2091 luisw
                String[] params = queryString.split("&");
580 2064 jaume
                for (int i = 0; i < params.length; i++) {
581 2071 luisw
                        String[] nameValue = params[i].split("=");
582
                        map.put(nameValue[0].toUpperCase(), nameValue[1]);
583 2064 jaume
                }
584 2071 luisw
                try {
585
                        String coverageName = (String) map.get((String) "COVERAGE");
586
                        String crs = (String) map.get((String) "CRS");
587
                        String format = (String) map.get((String) "FORMAT");
588
                        String time = (String) map.get((String) "TIME");
589
                        String bands = (String) map.get((String) "BANDS");
590
591
                        setSRS(crs);
592
                        setCoverageName(coverageName);
593
                        if (time != null)
594
                                setTime("TIME="+time);
595
                        OGCWCSService service = (OGCWCSService) wcs.getDriver();
596
                        service.connect();
597
598
                        setLabel( service.getLabel(coverageName) );
599
                        setName( getLabel() );
600
                        setFullExtent ( service.getFullExtent(coverageName, crs) );
601
                        setFormat( format );
602
                        setParameter( "BANDS="+bands );
603
                        setMaxResolution ( service.getMaxResolution(coverageName) );
604
605
                } catch (IOException e) {
606
                        e.printStackTrace();
607
                } catch (DriverException e) {
608
                        e.printStackTrace();
609
                }
610 2012 jaume
        }
611 2094 jaume
612
        /**
613 2623 nacho
         * Asignar el estado del raster
614
         * @param status
615
         */
616
        public void setStatus(StatusRasterInterface status){
617
                this.status = status;
618
        }
619
620
        /**
621
         * Obtiene el estado del raster
622
         * @return
623
         */
624
        public StatusRasterInterface getStatus(){
625
                return this.status;
626
        }
627
628
        /**
629 2097 jaume
         * Builds a coverage starting from a full GetCoverage URL.
630
         * (Using this is not a regular function)
631
         *
632
          * Inicializa una cobertura a partir de una URL GetCoverage completa.
633 2094 jaume
         * (Usar este m?todo supone saltarse todo el funcionamiento normal)
634
         *
635
         * TODO Por completar y probar
636
         * @param queryString
637
         */
638
        public void initFromQueryString2(String queryString){
639
640
                String host = queryString.substring(0, queryString.indexOf('?'));
641
                String[] params = queryString.substring(queryString.indexOf('?')+1, queryString.length()).split("=");
642
                setHost(host);
643
                for (int i = 0; i < params.length; i++) {
644
                        String[] par_nombreValor = params[i].split("=");
645
                        String nombre = par_nombreValor[0].toUpperCase();
646
                        String valor = par_nombreValor[1];
647
                        if (nombre.equals("COVERAGE"))                        setCoverageName(valor);
648
                        else if (nombre.equals("TIME"))                        setTime(valor);
649
                        else if (nombre.equals("FORMAT"))                setFormat(valor);
650
                        else if (nombre.equals("CRS"))                        setSRS(valor);
651
                        else if (nombre.equals("EXCEPTIONS"))        continue;
652
                        else if (nombre.equals("RESX"))                        continue;
653
                        else if (nombre.equals("RESY"))                        continue;
654
                        else if (nombre.equals("RESZ"))                        continue;
655
                        else if (nombre.equals("WIDTH"))                continue;
656
                        else if (nombre.equals("HEIGHT"))                continue;
657
                        else if (nombre.equals("DEPTH"))                continue;
658
                        else if (nombre.equals("BBOX"))                        continue;
659
                        else if (nombre.equals("RESPONSE_CRS"))        continue;
660
                        else                                                                        setParameter(nombre+"="+valor);
661 2420 jaume
                }
662 2644 jaume
                OGCWCSService service = (OGCWCSService) wcs.getDriver();
663
                try {
664
                        service.connect();
665
                        String coverageName = getCoverageName();
666
                        setLabel( service.getLabel(coverageName) );
667
                        setName( getLabel() );
668
                        setFullExtent ( service.getFullExtent(coverageName, getSRS()) );
669
                        setMaxResolution ( service.getMaxResolution(coverageName) );
670
                } catch (IOException e) {
671
                        e.printStackTrace();
672
                } catch (DriverException e) {
673
                        e.printStackTrace();
674
                }
675
676 2094 jaume
        }
677 2623 nacho
678
        /**
679
         * Devuelve la pila de filtros aplicada sobre  la capa raster.
680
         *
681
         * @return RasterFilterStack.
682
         */
683
        public RasterFilterStack getFilterStack() {
684
                return wcs.getFilterStack();
685
        }
686
687
        /**
688
         * Asigna la pila de filtros aplicada al raster
689
         * @return
690
         */
691
        public void setFilterStack(RasterFilterStack stack){
692
                wcs.setFilterStack(stack);
693
        }
694
695
        /* (non-Javadoc)
696
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setTransparency(int)
697
         */
698
        public void setTransparency(int trans) {
699
                wcs.setTransparency(trans);
700
        }
701
702
        /* (non-Javadoc)
703
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
704
         */
705
        public void setBand(int flag, int nBand) {
706
                switch(flag){
707
                case GeoRasterFile.RED_BAND:wcs.setBandR(nBand);break;
708
                case GeoRasterFile.GREEN_BAND:wcs.setBandG(nBand);break;
709
                case GeoRasterFile.BLUE_BAND:wcs.setBandB(nBand);break;
710
                }
711
        }
712
713
        /* (non-Javadoc)
714
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
715
         */
716
        public ArrayList getAttributes() {
717 2651 nacho
                return wcs.getAttributes();
718 2623 nacho
        }
719
        /* (non-Javadoc)
720
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
721
         */
722
        public double getHeight() {
723 2651 nacho
                if(wcs.getGeoRasterFile() != null)
724
                        return wcs.getGeoRasterFile().getHeight();
725
                else
726
                        return 0;
727 2623 nacho
        }
728
        /* (non-Javadoc)
729
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
730
         */
731
        public double getMaxX() {
732 2651 nacho
                if(wcs.getPxRaster() != null)
733
                        return wcs.getPxRaster().getExtent().getMax().getX();
734
                else
735
                        return 0;
736 2623 nacho
        }
737
        /* (non-Javadoc)
738
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
739
         */
740
        public double getMaxY() {
741 2651 nacho
                if(wcs.getPxRaster() != null)
742
                        return wcs.getPxRaster().getExtent().getMax().getY();
743
                else
744
                        return 0;
745 2623 nacho
        }
746
        /* (non-Javadoc)
747
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
748
         */
749
        public double getMinX() {
750 2651 nacho
                if(wcs.getPxRaster() != null)
751
                        return wcs.getPxRaster().getExtent().getMin().getX();
752
                else
753
                        return 0;
754 2623 nacho
        }
755
        /* (non-Javadoc)
756
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
757
         */
758
        public double getMinY() {
759 2651 nacho
                if(wcs.getPxRaster() != null)
760
                        return wcs.getPxRaster().getExtent().getMin().getY();
761
                else
762
                        return 0;
763 2623 nacho
        }
764
        /* (non-Javadoc)
765
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
766
         */
767
        public int[] getPixel(double wcx, double wcy) {
768 2651 nacho
                if(wcs.getPxRaster() != null)
769
                        return wcs.getPxRaster().getPixel(wcx, wcy);
770
                else
771
                        return null;
772 2623 nacho
        }
773
        /* (non-Javadoc)
774
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
775
         */
776
        public RasterAdapter getSource() {
777
                // TODO Auto-generated method stub
778
                return null;
779
        }
780
        /* (non-Javadoc)
781
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
782
         */
783
        public double getWidth() {
784 2651 nacho
                if(wcs.getGeoRasterFile() != null)
785
                        return wcs.getGeoRasterFile().getWidth();
786
                else
787
                        return 0;
788 2623 nacho
        }
789
        /* (non-Javadoc)
790
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
791
         */
792
        public void setPos(int x, int y) {
793 2651 nacho
                this.posX = x;
794
                this.posY = y;
795 2623 nacho
        }
796
        /* (non-Javadoc)
797
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
798
         */
799
        public void setPosWC(double x, double y) {
800 2651 nacho
                this.posXWC = x;
801
                this.posYWC = y;
802 2623 nacho
        }
803
        /* (non-Javadoc)
804
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
805
         */
806
        public void setRGB(int r, int g, int b) {
807 2651 nacho
                this.r = r;
808
                this.g = g;
809
                this.b = b;
810 2623 nacho
        }
811
        /* (non-Javadoc)
812
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
813
         */
814
        public void setSource(RasterAdapter ra) {
815
                // TODO Auto-generated method stub
816
817
        }
818
        /* (non-Javadoc)
819
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
820
         */
821
        public String queryByPoint(Point p) throws DriverException {
822 2764 nacho
                String data = "<file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n";
823 2651 nacho
                ArrayList attr = this.getAttributes();
824
                data += "  <raster\n";
825
                data += "    File=\""+getName()+"\"\n";
826
                for (int i=0; i<attr.size(); i++) {
827
                        Object [] a = (Object []) attr.get(i);
828
829
                        data += "    "+a[0].toString()+"=";
830
                        if (a[1].toString() instanceof String)
831
                                data += "\""+a[1].toString()+"\"\n";
832
                        else
833
                                data += a[1].toString()+"\n";
834
                }
835
                data += "    Point=\""+posX+" , "+posY+"\"\n";
836
                data += "    Point_WC=\""+posXWC+" , "+posYWC+"\"\n";
837
                data += "    RGB=\""+r+", "+g+", "+b+"\"\n";
838
                data += "  />\n";
839
840 2764 nacho
                data += "</file:"+getName().replaceAll("[^a-zA-Z0-9]","")+">\n";
841 2651 nacho
                System.out.println(data);
842
                return data;
843 2623 nacho
        }
844 2869 nacho
845
846
        /* (non-Javadoc)
847
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setTempExtent(com.iver.cit.gvsig.fmap.ViewPort)
848
         */
849
        public void setTempExtent(ViewPort vp){
850
851
        }
852 1979 jaume
}