Statistics
| Revision:

root / branches / gvSIG_WMSv2 / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / FLyrWMS.java @ 3741

History | View | Annotate | Download (25.3 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.layers;
42

    
43
import java.awt.Component;
44
import java.awt.Graphics2D;
45
import java.awt.Point;
46
import java.awt.geom.AffineTransform;
47
import java.awt.geom.NoninvertibleTransformException;
48
import java.awt.geom.Point2D;
49
import java.awt.geom.Rectangle2D;
50
import java.awt.image.BufferedImage;
51
import java.awt.image.DataBuffer;
52
import java.io.BufferedOutputStream;
53
import java.io.ByteArrayInputStream;
54
import java.io.DataOutputStream;
55
import java.io.File;
56
import java.io.FileOutputStream;
57
import java.io.IOException;
58
import java.lang.reflect.Constructor;
59
import java.lang.reflect.InvocationTargetException;
60
import java.net.MalformedURLException;
61
import java.net.URL;
62
import java.util.ArrayList;
63
import java.util.HashMap;
64
import java.util.Hashtable;
65
import java.util.Vector;
66

    
67
import javax.swing.JOptionPane;
68

    
69
import org.cresques.geo.ViewPortData;
70
import org.cresques.io.GdalFile;
71
import org.cresques.io.GeoRasterFile;
72
import org.cresques.io.raster.RasterFilterStack;
73
import org.cresques.io.raster.RasterFilterStackManager;
74
import org.cresques.px.Extent;
75
import org.cresques.px.PxRaster;
76
import org.exolab.castor.xml.ValidationException;
77
import org.gvsig.remoteClient.utils.Utilities;
78
import org.gvsig.remoteClient.wms.WMSStatus;
79

    
80
import com.devx.io.TempFileManager;
81
import com.iver.andami.PluginServices;
82
import com.iver.cit.gvsig.fmap.DriverException;
83
import com.iver.cit.gvsig.fmap.ViewPort;
84
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
85
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
86
import com.iver.cit.gvsig.fmap.drivers.WMSException;
87
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver;
88
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint;
89
import com.iver.cit.gvsig.fmap.operations.Cancellable;
90
import com.iver.utiles.StringUtilities;
91
import com.iver.utiles.XMLEntity;
92

    
93

    
94
/**
95
* Capa WMS.
96
*
97
* @author Fernando Gonz?lez Cort?s
98
*/
99
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations {
100

    
101
        boolean isPrinting = false;
102
        boolean mustTileDraw = false;
103
        boolean mustTilePrint = true;
104
        int maxTileDrawWidth = -1;
105
        int maxTileDrawHeight = -1;
106
        int maxTilePrintWidth = 1500;
107
        int maxTilePrintHeight = 1500;
108
    
109
    public URL host;
110
    public String m_Format;
111
    
112
        private String m_SRS;
113
        private String layerQuery;
114
        private String infoLayerQuery;
115
        private FMapWMSDriver wms;
116
        private WMSStatus wmsStatus;
117
    private WMSStatus wmsPreviousStatus= null;
118
        private Rectangle2D fullExtent;
119
        private boolean wmsTransparency;
120
    private Vector styles;
121
    private Vector dimensions;
122
        private StatusRasterInterface                status = null;
123
        private int                                                 posX = 0, posY = 0;
124
        private double                                                 posXWC = 0, posYWC = 0;
125
        private int                                                 r = 0, g = 0, b = 0;
126
        private GeoRasterFile                                 rasterFile = null;
127
        private PxRaster                                         raster = null;
128
        private RasterFilterStack                         filterStack = null;
129
        public         boolean                                                firstLoad = false;
130
        private int                                                 transparency = -1;
131
        private int                                                 rband = 0, gband = 1, bband = 2;
132
        private RasterFilterStackManager        stackManager = null;
133

    
134

    
135
        /**
136
         * Devuelve el XMLEntity con la informaci?n necesaria para reproducir la
137
         * capa.
138
         *
139
         * @return XMLEntity.
140
         * @throws XMLException
141
         */
142
        public XMLEntity getXMLEntity() throws XMLException {
143
                XMLEntity xml = super.getXMLEntity();
144

    
145
                xml.putProperty("fullExtent", StringUtilities.rect2String(fullExtent));
146
                xml.putProperty("host", host.toExternalForm());
147
                xml.putProperty("infoLayerQuery", infoLayerQuery);
148
                xml.putProperty("layerQuery", layerQuery);
149
                xml.putProperty("format", m_Format);
150
                xml.putProperty("srs", m_SRS);
151
                if (status!=null)
152
                        status.getXMLEntity(xml, true, this);
153
                else{
154
                        status = new StatusLayerRaster();
155
                        status.getXMLEntity(xml, true, this);
156
                }
157
        
158
        xml.putProperty("wms_transparency", wmsTransparency);
159
        
160
        if (styles!=null){
161
            String stylePr = "";
162
            for (int i = 0; i < styles.size(); i++) {
163
                stylePr += (String) styles.get(i);
164
                if (i<styles.size()-1)
165
                    stylePr += ",";
166
            }
167
            xml.putProperty("styles", stylePr);
168
        }
169
        if (dimensions!=null){
170
            String dim = "";
171
            for (int i = 0; i < dimensions.size(); i++) {
172
                dim += (String) dimensions.get(i);
173
                if (i<dimensions.size()-1)
174
                    dim += ",";
175
            }
176
            xml.putProperty("dimensions", dim);
177
        }
178
        return xml;
179
        }
180

    
181
        /**
182
         * A partir del XMLEntity reproduce la capa.
183
         *
184
         * @param xml XMLEntity
185
         *
186
         * @throws XMLException
187
         * @throws DriverException
188
         * @throws DriverIOException
189
         */
190
        public void setXMLEntity03(XMLEntity xml)
191
                throws XMLException {
192
                super.setXMLEntity(xml);
193
                fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
194
                                        "fullExtent"));
195

    
196
                try {
197
                        host = new URL(xml.getStringProperty("host"));
198
                } catch (MalformedURLException e) {
199
                        throw new XMLException(e);
200
                }
201

    
202
                infoLayerQuery = xml.getStringProperty("infoLayerQuery");
203
                layerQuery = xml.getStringProperty("layerQuery");
204
                m_Format = xml.getStringProperty("format");
205
                m_SRS = xml.getStringProperty("srs");
206
        }
207

    
208
        /**
209
         * A partir del XMLEntity reproduce la capa.
210
         *
211
         * @param xml XMLEntity
212
         *
213
         * @throws XMLException
214
         * @throws DriverException
215
         * @throws DriverIOException
216
         */
217
        public void setXMLEntity(XMLEntity xml)
218
                throws XMLException {
219
                super.setXMLEntity(xml);
220
                fullExtent = StringUtilities.string2Rect(xml.getStringProperty(
221
                                        "fullExtent"));
222

    
223
                try {
224
                        host = new URL(xml.getStringProperty("host"));
225
                } catch (MalformedURLException e) {
226
                        throw new XMLException(e);
227
                }
228

    
229
                infoLayerQuery = xml.getStringProperty("infoLayerQuery");
230
                layerQuery = xml.getStringProperty("layerQuery");
231
                m_Format = xml.getStringProperty("format");
232
                m_SRS = xml.getStringProperty("srs");
233
                
234
                String claseStr = null;
235
                if (xml.contains("raster.class")) {
236
                        claseStr = xml.getStringProperty("raster.class");
237
                }
238
        if (xml.contains("wms_transparency"))
239
            wmsTransparency = xml.getBooleanProperty("wms_transparency");
240
        if (xml.contains("styles")){
241
            styles = new Vector();
242
            String[] stl = xml.getStringProperty("styles").split(",");
243
            for (int i = 0; i < stl.length; i++) {
244
                styles.add(stl[i]);
245
            }
246
        }
247
        if (xml.contains("dimensions")){
248
            dimensions = new Vector();
249
            String[] dims = xml.getStringProperty("dimensions").split(",");
250
            for (int i = 0; i < dims.length; i++){
251
                dimensions.add(dims[i]);
252
            }
253
                
254
        }
255
                if(status!=null)
256
                        status.setXMLEntity(xml, this);
257
                else{
258
                        
259
                        //Cuando cargamos un proyecto 
260
                        
261
                        if(claseStr!=null && !claseStr.equals("")){
262
                                try{
263
                                        Class clase = Class.forName(claseStr);
264
                                        Constructor constr = clase.getConstructor(null);
265
                                        status = (StatusRasterInterface)constr.newInstance(null);
266
                                        if(status!=null)
267
                                                status.setXMLEntity(xml, this);
268
                                }catch(ClassNotFoundException exc){
269
                                        exc.printStackTrace();
270
                                }catch(InstantiationException exc){
271
                                        exc.printStackTrace();
272
                                }catch(IllegalAccessException exc){
273
                                        exc.printStackTrace();
274
                                }catch(NoSuchMethodException exc){
275
                                        exc.printStackTrace();
276
                                }catch(InvocationTargetException exc){
277
                                        exc.printStackTrace();
278
                                }                                        
279
                        }
280
                }
281
                firstLoad = true;
282
        }
283

    
284
        /**
285
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
286
         */
287
        public String queryByPoint(Point p) throws DriverException {
288
                try {
289
                        return new String(getDriver()
290
                                        .getFeatureInfo(wmsStatus,(int)p.getX(),(int)p.getY(),Integer.MAX_VALUE));
291
                } catch (WMSException  e) {
292
                        return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" +
293
                        e.getMessage() + "</exception>";
294
                } catch (ValidationException e) {
295
                        /*
296
                         * TODO Las traducciones en este m?todo han de ser
297
                         * las mismas que en el m?todo de dibujado
298
                         */
299
                        throw new DriverException("No se reconoce el formato de la respuesta",
300
                                e);
301
                } catch (UnsupportedVersionException e) {
302
                        throw new DriverException("Conflicto de versiones", e);
303
                } catch (IOException e) {
304
                        throw new DriverException("Error en la conexi?n", e);
305
                }
306
        }
307

    
308
        /**
309
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
310
         */
311
        public Rectangle2D getFullExtent() {
312
                return fullExtent;
313
        }
314

    
315
        /**
316
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
317
         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
318
         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
319
         */
320
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
321
                        Cancellable cancel,double scale) throws DriverException {
322
                if (isWithinScale(scale)){        
323
                        try {
324
                                                        
325
                                if (wmsStatus == null)
326
                                {
327
                                        wmsStatus = new WMSStatus();
328
                                }
329
                                wmsStatus.setExtent(viewPort.getAdjustedExtent());
330
                                wmsStatus.setFormat(m_Format);
331
                                wmsStatus.setHeight( viewPort.getImageHeight());
332
                wmsStatus.setWidth( viewPort.getImageWidth());
333
                                wmsStatus.setLayerNames(Utilities.createVector(layerQuery,","));
334
                                wmsStatus.setSrs(m_SRS);
335
                                wmsStatus.setStyles(styles);
336
                wmsStatus.setDimensions(dimensions);
337
                wmsStatus.setTransparency(wmsTransparency);
338
                                if (wmsPreviousStatus == null || !wmsPreviousStatus.equals(wmsStatus)){
339
                    wmsPreviousStatus = wmsStatus;
340
                                    byte[] bytes;
341
                                    bytes = getDriver().getMap(wmsStatus);
342
                                    
343
                                    ByteArrayInputStream inbytes = new ByteArrayInputStream(bytes);
344
                                    //BufferedImage tempImg = ImageIO.read(inbytes);
345
                                    // LWS Cambio de estrategia en el posicionado para la impresi?n.
346
                                    Point2D p2=new Point2D.Double(viewPort.getAdjustedExtent().getX(), viewPort.getAdjustedExtent().getMaxY()); //viewPort.getOffset();
347
                                    viewPort.getAffineTransform().transform(p2, p2);
348
                                    
349
                                    rasterProcess(g, viewPort, createTemp(inbytes, "wms_Query", viewPort));
350
                                    if(status!=null && firstLoad){
351
                                        status.applyStatus(this);
352
                                        firstLoad = false;
353
                                    }
354
                    
355
                                }
356
                                //g.drawImage(tempImg,(int)p2.getX(),(int)p2.getY(), null);
357
                        } catch (ValidationException e) {
358
                                throw new DriverException("No se reconoce el formato de la respuesta",
359
                                                e);
360
                        } catch (UnsupportedVersionException e) {
361
                                throw new DriverException("Conflicto de versiones", e);
362
                        } catch (IOException e) {
363
                                throw new DriverException("Error en la conexi?n", e);
364
                        } catch (WMSException e) {
365
                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
366
                                this.setVisible(false);
367
                wmsPreviousStatus = null;
368
                        }
369
                }
370
        }
371
        
372
        /**
373
         * Crea un fichero temporal con los datos obtenidos
374
         * @param img
375
         * @param name
376
         * @return
377
         * @throws IOException
378
         */
379
        public File createTemp(ByteArrayInputStream is, String name, ViewPort vp) throws IOException{
380
            File f = null;
381
            File tfw = null;
382
            try{
383
                    f = TempFileManager.createTempFile(name, "tmp");
384
                    
385
                    String extWorldFile = ".wld";
386
                    if(m_Format.equals("image/tif") || m_Format.equals("image/tiff"))
387
                            extWorldFile = ".tfw";
388
                    if(m_Format.equals("image/jpeg"))
389
                            extWorldFile = ".jpgw";
390
                                        
391
                    tfw = new File(f.getAbsolutePath().substring(0, f.getAbsolutePath().lastIndexOf(File.separator))+File.separator+f.getName()+ extWorldFile);
392
                    f.deleteOnExit();
393
                    tfw.deleteOnExit();
394
            } catch (IOException io) {
395
                    io.printStackTrace();
396
            }
397
         
398
            //Generamos un world file para gdal
399
            DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(tfw)) );
400
            dos.writeBytes((vp.getAdjustedExtent().getMaxX() - vp.getAdjustedExtent().getMinX())/vp.getImageWidth()+"\n");
401
            dos.writeBytes("0.0\n");
402
            dos.writeBytes("0.0\n");
403
            dos.writeBytes((vp.getAdjustedExtent().getMaxY() - vp.getAdjustedExtent().getMinY())/vp.getImageHeight()+"\n");
404
            dos.writeBytes(""+vp.getAdjustedExtent().getMinX()+"\n");
405
            dos.writeBytes(""+vp.getAdjustedExtent().getMinY()+"\n");
406
            dos.close();
407
            
408
            //Salvamos la imagen a disco
409
        System.out.println("Stored at '"+f.getAbsolutePath()+"'");
410
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
411
            int data = is.read();
412
            while(data != -1){
413
                    bos.write(data);
414
                    data = is.read();
415
            }
416
            bos.close();
417
            return f;
418
        }
419
         
420
        /**
421
         * Draws using PxRaster
422
         * 
423
         * Pinta usando PxRaster
424
         */        
425
        private void rasterProcess(Graphics2D g, ViewPort viewPort, File file) {
426
                
427
                //Creamos el PxRaster        
428
                rasterFile = new GdalFile(viewPort.getProjection(), file.getAbsolutePath());
429
                Extent e = new Extent(viewPort.getAdjustedExtent());
430
                raster = new PxRaster(rasterFile, null, rasterFile.getExtent());
431
                
432
                //Recuperamos la pila de filtros si ya hubiese sido cargado antes
433
                
434
                if(this.filterStack!=null)
435
                        raster.filterStack = this.filterStack;
436
                
437
                raster.setTransparency(false);
438
                
439
                //Creamos el viewportdata
440
                
441
                ViewPortData vpData = new ViewPortData(viewPort.getProjection(), e, viewPort.getImageSize() );
442
                vpData.setMat(viewPort.getAffineTransform());
443
                                
444
                //Asignamos transparencia y orden de bandas
445
                if(this.transparency==-1 && !firstLoad);
446
                else
447
                        raster.setTransparency(this.transparency);
448
                
449
                raster.setBand(GeoRasterFile.RED_BAND,rband);
450
                raster.setBand(GeoRasterFile.GREEN_BAND, gband);
451
                raster.setBand(GeoRasterFile.BLUE_BAND, bband);
452
        
453
                //Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
454
                //Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de 
455
                //propiedades cuando creamos un nuevo pxRaster
456
                
457
                if(this.stackManager != null)
458
                        raster.setStackManager(this.stackManager); 
459
                                                
460
                raster.draw(g, vpData);
461
                
462
                //En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
463
                //si queremos desde las propiedades
464
                
465
                if(this.stackManager == null)
466
                        this.stackManager = raster.getStackManager(); 
467
                
468
                if(this.filterStack == null)
469
                        this.filterStack = raster.filterStack;
470
        }
471
        
472
        /**
473
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
474
         *                 com.iver.cit.gvsig.fmap.ViewPort,
475
         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
476
         */
477
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
478
                throws DriverException {
479
                if (isVisible() && isWithinScale(scale)){        
480
                isPrinting = true;
481
                if (!mustTilePrint) {
482
                        draw(null, g, viewPort, cancel,scale);
483
                } else {
484
                // Para no pedir imagenes demasiado grandes, vamos
485
                // a hacer lo mismo que hace EcwFile: chunkear.
486
                // Llamamos a drawView con cuadraditos m?s peque?os
487
                // del BufferedImage ni caso, cuando se imprime viene con null
488
                        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
489
                        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
490
                        for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
491
                            // Parte que dibuja
492
                            try {
493
                                ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
494
                                draw(null, g, vp, cancel,scale);
495
                                } catch (NoninvertibleTransformException e) {
496
                                        e.printStackTrace();
497
                                }
498
                }
499
                }
500
            isPrinting = false;
501
                }
502
        }
503
        
504
        public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
505
                throws DriverException {
506
                draw(null, g, viewPort, cancel,scale);
507
        }
508

    
509
        /**
510
         * Devuelve el FMapWMSDriver.
511
         *
512
         * @return FMapWMSDriver
513
         *
514
         * @throws IllegalStateException
515
         * @throws ValidationException
516
         * @throws UnsupportedVersionException
517
         * @throws IOException
518
         */
519
        private FMapWMSDriver getDriver()
520
                throws IllegalStateException, ValidationException, 
521
                        UnsupportedVersionException, IOException {
522
                if (wms == null) {
523
                        //wmsClient = WMSClientFactory.getClient(host);
524
                        wms = new FMapWMSDriver();
525
            wms.createClient(host);
526
            
527
                }
528

    
529
                return wms;
530
        }
531
        
532
        /**
533
         * Devuelve el FMapWMSDriver.
534
         *
535
         * @return FMapWMSDriver
536
         *
537
         * @throws IllegalStateException
538
         * @throws ValidationException
539
         * @throws UnsupportedVersionException
540
         * @throws IOException
541
         */
542
        public void setDriver(FMapWMSDriver drv) {
543
                wms = drv;
544
        }
545

    
546
        /**
547
         * Devuelve el URL.
548
         *
549
         * @return URL.
550
         */
551
        public URL getHost() {
552
                return host;
553
        }
554

    
555
        /**
556
         * Inserta el URL.
557
         *
558
         * @param host URL.
559
         */
560
        public void setHost(URL host) {
561
                this.host = host;
562
        }
563

    
564
        /**
565
         * Devuelve la informaci?n de la consulta.
566
         *
567
         * @return String.
568
         */
569
        public String getInfoLayerQuery() {
570
                return infoLayerQuery;
571
        }
572

    
573
        /**
574
         * Inserta la informaci?n de la consulta.
575
         *
576
         * @param infoLayerQuery String.
577
         */
578
        public void setInfoLayerQuery(String infoLayerQuery) {
579
                this.infoLayerQuery = infoLayerQuery;
580
        }
581

    
582
        /**
583
         * Devuelve la consulta.
584
         *
585
         * @return String.
586
         */
587
        public String getLayerQuery() {
588
                return layerQuery;
589
        }
590

    
591
        /**
592
         * Inserta la consulta.
593
         *
594
         * @param layerQuery consulta.
595
         */
596
        public void setLayerQuery(String layerQuery) {
597
                this.layerQuery = layerQuery;
598
        }
599

    
600
        /**
601
         * Devuelve el formato.
602
         *
603
         * @return Formato.
604
         */
605
        public String getFormat() {
606
                return m_Format;
607
        }
608

    
609
        /**
610
         * Inserta el formato.
611
         *
612
         * @param format Formato.
613
         */
614
        public void setFormat(String format) {
615
                m_Format = format;
616
        }
617

    
618
        /**
619
         * Devuelve el SRS.
620
         *
621
         * @return SRS.
622
         */
623
        public String getSRS() {
624
                return m_SRS;
625
        }
626

    
627
        /**
628
         * Inserta el SRS.
629
         *
630
         * @param m_srs SRS.
631
         */
632
        public void setSRS(String m_srs) {
633
                m_SRS = m_srs;
634
        }
635

    
636
        /**
637
         * Inserta la extensi?n total de la capa.
638
         *
639
         * @param fullExtent Rect?ngulo.
640
         */
641
        public void setFullExtent(Rectangle2D fullExtent) {
642
                this.fullExtent = fullExtent;
643
        }
644
        
645
        public HashMap getProperties() {
646
                HashMap info = new HashMap();
647
        String[] layerNames = getLayerQuery().split(",");
648
        Vector layers = new Vector(layerNames.length);
649
        try {
650
            if(getDriver().connect()){
651
                for (int i = 0; i < layerNames.length; i++) {
652
                    layers.add(i, wms.getLayer(layerNames[i]));
653
                }
654
                
655
                info.put("selectedLayers", layers);
656
                info.put("host", getHost());
657
                info.put("srs", getSRS());
658
                info.put("format", getFormat());
659
                info.put("wmsTransparency", new Boolean(wmsTransparency));
660
                info.put("styles", styles);
661
                info.put("dimensions", dimensions);
662
                return info;
663
            }
664
        } catch (Exception e) {
665
            e.printStackTrace();
666
        }
667
        return null;
668
        }
669
        
670
        /**
671
         * Asignar el estado del raster
672
         * @param status
673
         */
674
        public void setStatus(StatusRasterInterface status){
675
                this.status = status;
676
        }
677
        
678
        /**
679
         * Obtiene el estado del raster
680
         * @return
681
         */
682
        public StatusRasterInterface getStatus(){
683
                return this.status;
684
        }
685
        
686
        /* (non-Javadoc)
687
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getAttributes()
688
         */
689
        public ArrayList getAttributes() {
690
                if(rasterFile != null){
691
                        ArrayList attr = new ArrayList();
692
                        String dataType = "Byte";
693
                        if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte";
694
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_SHORT)
695
                                dataType = "Short";
696
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_USHORT)
697
                                dataType = "Unsigned Short";
698
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_INT)
699
                                dataType = "Integer";
700
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_FLOAT)
701
                                dataType = "Float";
702
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_DOUBLE)
703
                                dataType = "Double";
704
                        else
705
                                dataType = "Unknown";
706
                        Object [][] a = {
707
                                {"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())},
708
                                {"Filesize",new Long(rasterFile.getFileSize())},
709
                                {"Width",new Integer(rasterFile.getWidth())},
710
                                {"Height", new Integer(rasterFile.getHeight())},
711
                                {"Bands", new Integer(rasterFile.getBandCount())}
712
                                //{"BandDataType", dataType}
713
                        };
714
                        for (int i=0; i<a.length; i++){
715
                                System.out.println("===> "+a[i][0]+" "+a[i][1]);
716
                                attr.add(a[i]);
717
                        }
718
                        return attr;
719
                }
720
                return  null;
721
        }
722
        /* (non-Javadoc)
723
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getFilterStack()
724
         */
725
        public RasterFilterStack getFilterStack() {
726
                if(raster!=null)
727
                        return raster.filterStack;
728
                return null;
729
        }
730
        /* (non-Javadoc)
731
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getHeight()
732
         */
733
        public double getHeight() {
734
                if(getGeoRasterFile() != null)
735
                        return getGeoRasterFile().getHeight();
736
        return 0;
737
        }
738
        /* (non-Javadoc)
739
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxX()
740
         */
741
        public double getMaxX() {
742
                if(getPxRaster() != null)
743
                        return getPxRaster().getExtent().getMax().getX();
744
        return 0;
745
        }
746
        /* (non-Javadoc)
747
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMaxY()
748
         */
749
        public double getMaxY() {
750
                if(getPxRaster() != null)
751
                        return getPxRaster().getExtent().getMax().getY();
752
        return 0;
753
        }
754
        /* (non-Javadoc)
755
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinX()
756
         */
757
        public double getMinX() {
758
                if(getPxRaster() != null)
759
                        return getPxRaster().getExtent().getMin().getX();
760
        return 0;
761
        }
762
        /* (non-Javadoc)
763
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getMinY()
764
         */
765
        public double getMinY() {
766
                if(getPxRaster() != null)
767
                        return getPxRaster().getExtent().getMin().getY();
768
        return 0;
769
        }
770
        /* (non-Javadoc)
771
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getPixel(double, double)
772
         */
773
        public int[] getPixel(double wcx, double wcy) {
774
                if(getPxRaster() != null)
775
                        return getPxRaster().getPixel(wcx, wcy);
776
        return null;
777
        }
778
        /* (non-Javadoc)
779
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getSource()
780
         */
781
        public RasterAdapter getSource() {
782
                return null;
783
        }
784
        /* (non-Javadoc)
785
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getWidth()
786
         */
787
        public double getWidth() {
788
                if(getGeoRasterFile() != null)
789
                        return getGeoRasterFile().getWidth();
790
        return 0;
791
        }
792
        /* (non-Javadoc)
793
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
794
         */
795
        public void setBand(int flag, int nBand) {
796
                switch(flag){
797
                case GeoRasterFile.RED_BAND:setBandR(nBand);break;
798
                case GeoRasterFile.GREEN_BAND:setBandG(nBand);break;
799
                case GeoRasterFile.BLUE_BAND:setBandB(nBand);break;
800
                }
801
        }
802
        /* (non-Javadoc)
803
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setFilterStack(org.cresques.io.raster.RasterFilterStack)
804
         */
805
        public void setFilterStack(RasterFilterStack stack) {
806
                this.filterStack = stack;
807
        }
808
        /* (non-Javadoc)
809
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPos(int, int)
810
         */
811
        public void setPos(int x, int y) {
812
                this.posX = x;
813
                this.posY = y;
814
        }
815
        
816
        /* (non-Javadoc)
817
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setPosWC(double, double)
818
         */
819
        public void setPosWC(double x, double y) {
820
                this.posXWC = x;
821
                this.posYWC = y;
822
        }
823
        
824
        /* (non-Javadoc)
825
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setRGB(int, int, int)
826
         */
827
        public void setRGB(int r, int g, int b) {
828
                this.r = r;
829
                this.g = g;
830
                this.b = b;
831
        }
832
        /* (non-Javadoc)
833
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setSource(com.iver.cit.gvsig.fmap.layers.RasterAdapter)
834
         */
835
        public void setSource(RasterAdapter ra) {
836
        }
837
        /**
838
         * @return Returns the raster.
839
         */
840
        public PxRaster getPxRaster() {
841
                return raster;
842
        }
843
        /**
844
         * @return Returns the rasterFile.
845
         */
846
        public GeoRasterFile getGeoRasterFile() {
847
                return rasterFile;
848
        }
849
        
850
        public void setTransparency(int trans) {
851
                this.transparency = trans;
852
        }
853
        
854
        /**
855
         * Sets the R-band.
856
         * 
857
         * Asigna la banda R.
858
         * @param r
859
         */
860
        public void setBandR(int r){
861
                this.rband = r;
862
        }
863
        
864
        /**
865
         * Sets the G-band.
866
         * 
867
         * Asigna la banda G
868
         * @param g
869
         */
870
        public void setBandG(int g){
871
                this.gband = g;
872
        }
873
        
874
        /**
875
         * Sets the B-band.
876
         * 
877
         * Asigna la banda B
878
         * @param b
879
         */
880
        public void setBandB(int b){
881
                this.bband = b;
882
        }
883

    
884
    /**
885
     * @return Returns the wmsTransparency.
886
     */
887
    public boolean isWmsTransparency() {
888
        return wmsTransparency;
889
    }
890

    
891
    /**
892
     * @param wmsTransparency The wmsTransparency to set.
893
     */
894
    public void setWmsTransparency(boolean wmsTransparency) {
895
        this.wmsTransparency = wmsTransparency;
896
    }
897

    
898
    /**
899
     * @param styles
900
     */
901
    public void setStyles(Vector styles) {
902
        this.styles = styles;
903
    }
904
    
905
    /**
906
     * @param dimensions
907
     */
908
    public void setDimensions(Vector dimensions) {
909
        this.dimensions = dimensions;
910
    }
911
        
912
}