Statistics
| Revision:

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

History | View | Annotate | Download (25.6 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.Hashtable;
64
import java.util.Vector;
65

    
66
import javax.swing.JOptionPane;
67

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

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

    
92

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

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

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

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

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

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

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

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

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

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

    
283
        /**
284
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(com.iver.cit.gvsig.fmap.operations.QueriedPoint)
285
         */
286
        public String queryByPoint(Point p) throws DriverException {
287
//                FeatureInfoQuery query = new FeatureInfoQuery(lastMapQuery);
288
//                query.setFeatureCount(Integer.MAX_VALUE);
289
//                query.setX((int) p.getX());
290
//                query.setY((int) p.getY());
291
//                query.setInfoQuery(infoLayerQuery);
292
                
293
                try {
294
//                        query.setInfoFormat(selectFormat());
295
//                        return new String(getWmsClient().doFeatureInfo(query));
296
                        return new String(getDriver()
297
                                        .getFeatureInfo(wmsStatus,(int)p.getX(),(int)p.getY(),Integer.MAX_VALUE));
298
                } catch (WMSException  e) {
299
                        return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><exception>" +
300
                        e.getMessage() + "</exception>";
301
                } catch (ValidationException e) {
302
                        /*
303
                         * TODO Las traducciones en este m?todo han de ser
304
                         * las mismas que en el m?todo de dibujado
305
                         */
306
                        throw new DriverException("No se reconoce el formato de la respuesta",
307
                                e);
308
                } catch (UnsupportedVersionException e) {
309
                        throw new DriverException("Conflicto de versiones", e);
310
                } catch (IOException e) {
311
                        throw new DriverException("Error en la conexi?n", e);
312
                }
313
//                } catch (com.iver.wmsclient.WMSException e) {
314
//                        throw new DriverException(e.getMessage(), e);
315
                //}
316
//                catch (NoSuchFieldException e) {
317
//                        throw new RuntimeException(
318
//                                "No se rellenaron todos los campos de la petici?n");
319
//                }
320
        }
321

    
322
        /**
323
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
324
         */
325
        public Rectangle2D getFullExtent() {
326
                return fullExtent;
327
        }
328

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

    
523
        /**
524
         * Devuelve el FMapWMSDriver.
525
         *
526
         * @return FMapWMSDriver
527
         *
528
         * @throws IllegalStateException
529
         * @throws ValidationException
530
         * @throws UnsupportedVersionException
531
         * @throws IOException
532
         */
533
        private FMapWMSDriver getDriver()
534
                throws IllegalStateException, ValidationException, 
535
                        UnsupportedVersionException, IOException {
536
                if (wms == null) {
537
                        //wmsClient = WMSClientFactory.getClient(host);
538
                        wms = new FMapWMSDriver();
539
            wms.createClient(host);
540
            
541
                }
542

    
543
                return wms;
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 Hashtable getProperties() {
646
                Hashtable info = new Hashtable();
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
}