Statistics
| Revision:

root / trunk / extensions / extWCS / src / com / iver / cit / gvsig / fmap / layers / FMapWCSAdapter.java @ 3053

History | View | Annotate | Download (23 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.layers;
42

    
43
import java.awt.Dimension;
44
import java.awt.Graphics2D;
45
import java.awt.Image;
46
import java.awt.geom.Point2D;
47
import java.awt.geom.Rectangle2D;
48
import java.awt.image.BufferedImage;
49
import java.awt.image.DataBuffer;
50
import java.io.File;
51
import java.io.IOException;
52
import java.util.ArrayList;
53

    
54
import org.cresques.geo.ViewPortData;
55
import org.cresques.io.GdalFile;
56
import org.cresques.io.GeoRasterFile;
57
import org.cresques.io.raster.RasterFilterStack;
58
import org.cresques.io.raster.RasterFilterStackManager;
59
import org.cresques.io.rasterOld.ComputeMinMaxFilter;
60
import org.cresques.io.rasterOld.GreyscaleRasterToImageFilter;
61
import org.cresques.io.rasterOld.LinearEnhancementFilter;
62
import org.cresques.io.rasterOld.RasterBuf;
63
import org.cresques.io.rasterOld.RasterStats;
64
import org.cresques.io.rasterOld.RasterToImageFilter;
65
import org.cresques.px.Extent;
66
import org.cresques.px.PxRaster;
67

    
68
import com.iver.cit.gvsig.fmap.DriverException;
69
import com.iver.cit.gvsig.fmap.ViewPort;
70
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
71
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver;
72
import com.iver.cit.gvsig.fmap.operations.Cancellable;
73

    
74
import es.gva.cit.jgdal.Gdal;
75
import es.gva.cit.jgdal.GdalBuffer;
76
import es.gva.cit.jgdal.GdalException;
77
import es.gva.cit.jgdal.GdalRasterBand;
78
import es.gva.cit.jgdal.GeoTransform;
79
import es.uji.lsi.wcs.client.ServerErrorResponseException;
80

    
81
/**
82
 * Class to interact FMapWCSDriver
83
 * 
84
 * La clase FMapWCSAdaptor recubre la interacci?n con el FMapWCSDriver 
85
 * @author jaume - jaume.dominguez@iver.es
86
 *
87
 */
88
public class FMapWCSAdapter {
89
        private boolean                                         driverInitialized = false;
90
        private FMapWCSDriver                                driver;
91
        private Rectangle2D                                 fullExtent, bbox;
92
        
93
        private static final double                 METROSXGRADO = 111120D;
94
        private String                                                 coverageName;
95
        private String                                                 SRS;
96
        private String                                                 format;
97
        private String                                                 time;
98
        private String                                                 parameter;
99
        //private double                                                 maxRes;
100
        private Point2D                                                maxRes;
101
        private String                                                 coverageQuery;
102
        private String                                                 lastCoverageQuery = "";
103
        private File                                                 fCoverage = null;
104
        private PxRaster                                         raster = null;
105
        private RasterFilterStack                         filterStack = null;
106
        private GeoRasterFile                                 rasterFile = null;
107
        //private double                                                 res;
108
        private Point2D                                                res;
109
        private boolean                                         zoomingToPixel;
110
        
111
        private int                                                 transparency = -1;
112
        private int                                                 rband = 0, gband = 1, bband = 2;
113
        private RasterFilterStackManager        stackManager = null;
114
        public         boolean                                                firstLoad = false;
115
        
116
        /**
117
         * Returns the coverage resolution
118
         * 
119
         * obtiene la resoluci?n de la cobertura (de la capa FlyrWCS)
120
         * @return
121
         */
122
        //public double getRes() {
123
        public Point2D getRes() {
124
                return res;
125
        }
126
        
127
        /**
128
         * Sets the coverage resolution (the layer's resolution)
129
         * 
130
         * Establece la resoluci?n de la cobertura (de la capa FlyrWCS)
131
         * @param res
132
         */
133
        //public void setRes(double res) {
134
        public void setRes(Point2D res) {
135
                this.res = res;
136
        }
137
        
138
        /**
139
         * Sets the driver that works with the adaptor.
140
         * 
141
         * Establece el driver sobre el que act?a el adaptador 
142
         */
143
        public void setDriver(FMapWCSDriver d) {
144
                driver = d;
145
        }
146
        
147
        /**
148
         * Gets a ref to the object that implements the vectorial interface in order
149
         * of the Strategy can optimize the driver's function.
150
         * 
151
         * Obtiene una referencia al objeto que implementa la interfaz vectorial con
152
         *  el fin de que las Strategy puedan optimizar en funci?n del driver.
153
         */
154
        public FMapWCSDriver getDriver(){
155
                return driver;
156
        }
157
        
158
        /**
159
         * Automatically called by gvSIG
160
         * 
161
         * Llamado autom?ticamente por gvSIG. 
162
         * Pinta la cobertura (r?ster) en el ViewPort.
163
         * 
164
         * @param image, g, viewPort, cancel
165
         * @throws ServerErrorResponseException 
166
         * @throws ServerErrorResponseException 
167
         */
168
        public void draw(BufferedImage image, Graphics2D g,
169
                        ViewPort viewPort, Cancellable cancel) throws DriverException, ServerErrorResponseException {
170
                if (viewPort.getExtent().getMinX() > fullExtent.getMaxX())
171
                        return;
172
                if (viewPort.getExtent().getMinY() > fullExtent.getMaxY())
173
                        return;
174
                if (viewPort.getExtent().getMaxX() < fullExtent.getMinX())
175
                        return;
176
                if (viewPort.getExtent().getMaxY() < fullExtent.getMinY())
177
                        return;
178
                setBBox(viewPort.getAdjustedExtent());
179
                
180
                double x = bbox.getMinX();
181
                double y = bbox.getMinY();
182
                double w = bbox.getWidth();
183
                double h = bbox.getHeight();
184
                
185
                double scalex = viewPort.getAffineTransform().getScaleX()        /* g.getTransform().getScaleX()*/ ,
186
                scaley = viewPort.getAffineTransform().getScaleY()                /* g.getTransform().getScaleY() */;
187
                int wImg = (int) Math.abs(w*scalex)+1, hImg = (int) Math.abs(h*scaley)+1;
188
                if (wImg <= 0 || hImg <= 0) return;
189
                
190
                setCoverageQuery(bbox, new Dimension(wImg, hImg));
191
                
192
                //try {
193
                        if (lastCoverageQuery.compareTo(coverageQuery) != 0) {
194
                                setWCSClientCoverageQuery(coverageQuery);
195
                                fCoverage = driver.getCoverage();
196
                        }
197
                        
198
                        if (fCoverage != null) {
199
                                //drawJaume(g, viewPort, fCoverage);
200
                                drawLWS(g, viewPort, fCoverage);
201
                        }
202
//                } catch (ServerErrorResponseException e) {
203
//                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage(), "Error",
204
//                                        JOptionPane.ERROR_MESSAGE);
205
//                        View view=(View)PluginServices.getMDIManager().getActiveView();
206
//                        view.getTOC().layerRemoved(LayerCollectionEvent.createLayerRemovedEvent(this));
207
//                }
208
        }
209
                
210
        /**
211
         * Draws using PxRaster
212
         * 
213
         * Pinta usando PxRaster
214
         */        
215
        private void drawLWS(Graphics2D g, ViewPort viewPort, File fCoverage) {
216
                
217
                //Creamos el PxRaster
218
                
219
                rasterFile = new GdalFile(viewPort.getProjection(), fCoverage.getAbsolutePath());
220
                Extent e = new Extent(bbox);
221
                raster = new PxRaster(rasterFile, null, rasterFile.getExtent());
222
                
223
                //Recuperamos la pila de filtros si ya hubiese sido cargado antes
224
                
225
                if(this.filterStack!=null)
226
                        raster.filterStack = this.filterStack;
227
                
228
                raster.setTransparency(false);
229
                
230
                //Creamos el viewportdata
231
                
232
                ViewPortData vpData = new ViewPortData(viewPort.getProjection(), e, viewPort.getImageSize() );
233
                vpData.setMat(viewPort.getAffineTransform());
234
                                
235
                //Asignamos transparencia y orden de bandas
236
                if(this.transparency==-1 && !this.firstLoad);
237
                else
238
                        raster.setTransparency(this.transparency);
239
                
240
                raster.setBand(GeoRasterFile.RED_BAND,rband);
241
                raster.setBand(GeoRasterFile.GREEN_BAND, gband);
242
                raster.setBand(GeoRasterFile.BLUE_BAND, bband);
243
        
244
                //Despues del primer pxRaster asignamos el stackManager guardado para los siguientes.
245
                //Con esto conseguimos asignar los cambios que se hayan producido desde el cuadro de 
246
                //propiedades cuando creamos un nuevo pxRaster
247
                
248
                if(this.stackManager != null)
249
                        raster.setStackManager(this.stackManager); 
250
                                                
251
                raster.draw(g, vpData);
252
                
253
                //En el primer pxRaster de una imagen obtenemos el Stack Manager para poder modificarlo
254
                //si queremos desde las propiedades
255
                
256
                if(this.stackManager == null)
257
                        this.stackManager = raster.getStackManager(); 
258
                
259

    
260
                if(this.filterStack == null)
261
                        this.filterStack = raster.filterStack;
262
                
263
                
264
        }
265
        
266
        /**
267
         * Gets the filter stack
268
         * 
269
         * Obtiene la pila de filtros
270
         * @return 
271
         */
272
        public RasterFilterStack getFilterStack(){
273
                if(raster!=null)
274
                        return raster.filterStack;
275
                return null;
276
        }
277
        
278
        /**
279
         * Obtiene la lista de atributos de raster
280
         * @return        lista de atributos. Cada elmento de la lista es un array Object
281
         * con dos elementos. El primero el nombre del atributo y el segundo el valor
282
         * del mismo.
283
         */
284
        public ArrayList getAttributes() {
285
                if(rasterFile != null){
286
                        ArrayList attr = new ArrayList();
287
                        String dataType = "Byte";
288
                        if (rasterFile.getDataType() == DataBuffer.TYPE_BYTE) dataType = "Byte";
289
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_SHORT)
290
                                dataType = "Short";
291
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_USHORT)
292
                                dataType = "Unsigned Short";
293
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_INT)
294
                                dataType = "Integer";
295
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_FLOAT)
296
                                dataType = "Float";
297
                        else if (rasterFile.getDataType() == DataBuffer.TYPE_DOUBLE)
298
                                dataType = "Double";
299
                        else
300
                                dataType = "Unknown";
301
                        Object [][] a = {
302
                                {"Filename",rasterFile.getName().substring(rasterFile.getName().lastIndexOf("/")+1, rasterFile.getName().length())},
303
                                {"Filesize",new Long(rasterFile.getFileSize())},
304
                                {"Width",new Integer(rasterFile.getWidth())},
305
                                {"Height", new Integer(rasterFile.getHeight())},
306
                                {"Bands", new Integer(rasterFile.getBandCount())}
307
                                //{"BandDataType", dataType}
308
                        };
309
                        for (int i=0; i<a.length; i++){
310
                                System.out.println("===> "+a[i][0]+" "+a[i][1]);
311
                                attr.add(a[i]);
312
                        }
313
                        return attr;
314
                }
315
                return  null;
316
        }
317
        
318
        /**
319
         * Sets the filter stack
320
         * 
321
         * Establece la pila de filtros
322
         * 
323
         * @param filterStack pila
324
         */
325
        public void setFilterStack(RasterFilterStack filterStack){
326
                this.filterStack = filterStack;                 
327
        }
328
        
329
        /**
330
         * Gets the last created PxRaster
331
         * 
332
         * Obtiene el ?ltimo PxRaster creado
333
         * 
334
         * @return
335
         */
336
        public PxRaster getPxRaster(){
337
                return raster;
338
        }
339
        
340
        /**
341
         * Gets the last open GeoRasterFile against the temp file received
342
         * 
343
         * Obtiene el ?ltimo GeoRasterFile abierto sobre el temporal recibido
344
         * @return
345
         */
346
        public GeoRasterFile getGeoRasterFile(){
347
                return rasterFile;
348
        }
349
        
350
        /**
351
         * Sets the Bouning Box of the query according to the zoom. If the zoom's extension
352
         * is greather than the coverage's full extent or the view only covers a part of
353
         * the coverage's area, it cuts the required edges to those given by the coverage's
354
         * full extent.
355
         * 
356
         * Establece la Bounding Box de la consulta seg?n el zoom. En caso de que 
357
         * el zoom abarque m?s de la estensi?n m?xima (fullExtent) o la vista cubra
358
         * solo una parte de la cobertura, acota los l?mites necesarios a aquellos
359
         * marcados por la extensi?n m?xima.
360
         * 
361
         * @param rect
362
         */
363
        public void setBBox(Rectangle2D rect) {
364
                double x1 = rect.getMinX();
365
                double y1 = rect.getMinY();
366
                double x2 = rect.getMaxX();
367
                double y2 = rect.getMaxY();
368
                if (x1 < fullExtent.getMinX())
369
                        x1 = fullExtent.getMinX();
370
                if (y1 < fullExtent.getMinY())
371
                        y1 = fullExtent.getMinY();
372
                if (x2 > fullExtent.getMaxX())
373
                        x2 = fullExtent.getMaxX();
374
                if (y2 > fullExtent.getMaxY())
375
                        y2 = fullExtent.getMaxY();
376
                
377
                if (bbox == null)
378
                        bbox = new Rectangle2D.Double();
379
                
380
                bbox.setRect(x1, y1, x2 - x1, y2 - y1);
381
        }
382
        
383
        /**
384
         * Establishes the initial values that will be included in the query.
385
         * 
386
         * Para establecer los valores iniciales que se incluiran en la consulta.
387
         * 
388
         * @param layersRectangle
389
         * @param srs
390
         * @param format
391
         * @param parametro
392
         * @param times
393
         */
394
        public void setCoverageQuery(Rectangle2D bBox, Dimension sz) {
395
                String coverage    = "COVERAGE=" + coverageName;
396
                String crs                    = "&CRS=" + SRS;
397
                String boundingBox = "&BBOX=" + bBox.getMinX() 
398
                                                   + "," + bBox.getMinY()
399
                                                   + "," + bBox.getMaxX()
400
                                                   + "," + bBox.getMaxY();
401
                String time            = this.time != null ? "&" + this.time : "";
402
                String param            = parameter != null ? "&" + parameter : "";
403
                res                                   = new Point2D.Double(bBox.getWidth() / sz.getWidth(), bBox.getHeight() / sz.getHeight());
404
                
405
                // TODO LWS 01 oct 05 esto no funciona. Hay que hacer un c?lculo correcto
406
                // y reevaluar porqu? hizo falta.
407
                // mientras tanto RESX y RESY ya no se usan
408
                // Calculo cutre para ver si son grados (o metros). Si da menos de 180
409
                // es que son grados y lo paso a metros. (LWS)
410
                if (bBox.getMaxY() < 181D)
411
                        res.setLocation(res.getX()*METROSXGRADO, res.getY()*METROSXGRADO);
412
                
413
                String resX            = "&RESX=" + res.getX();
414
                String resY            = "&RESY=" + res.getY();
415
                String format            = "&FORMAT=" + this.format;
416

    
417
                coverageQuery = coverage + crs + boundingBox + time + param + format;
418
                coverageQuery += "&WIDTH="+sz.width+"&HEIGHT="+sz.height;
419
                System.out.println("coverageQuery="+coverageQuery);
420
                // coverageQuery += resX + resY;
421
        }
422
        
423
        /**
424
         * Takes the coverage parameters and give them to the WCS client. After this,
425
         * it is possible to launch a GetCoverage operation.
426
         * 
427
         * Recoge los par?metros de la capa y los pasa al cliente WCS. Despu?s de
428
         * esto, ya se puede lanzar una GetCoverage
429
         *  
430
         */
431
        private void setWCSClientCoverageQuery(String query) {
432
                lastCoverageQuery = query;
433
                ((FMapWCSDriver) driver).setGetCoverageParams(query);
434
        }
435

    
436
        /**
437
         * Returns the coverage name.
438
         * 
439
         * Devuelve el nombre de la cobertura
440
         * @return
441
         */
442
        public String getCoverageName() {
443
                return coverageName;
444
        }
445
        
446
        /**
447
         * Sets the coverage name.
448
         * 
449
         * Establece el nombre de la cobertura
450
         * @param coverageName
451
         */
452
        public void setCoverageName(String coverageName) {
453
                this.coverageName = coverageName;
454
        }
455
        
456
        /**
457
         * Returns an string containing the query that originated the coverage.
458
         * 
459
         * Obtiene una cadena que contiene la consulta que origin? la cobertura.
460
         * @return String
461
         */
462
        public String getCoverageQuery() {
463
                return coverageQuery;
464
        }
465
        
466
        /**
467
         * Sets the query string (an URL) that originates the coverage.
468
         * 
469
         * Establece la cadena que contiene la consulta (URL) que origina la cobertura.
470
         * @param coverageQuery
471
         */
472
        public void setCoverageQuery(String coverageQuery) {
473
                this.coverageQuery = coverageQuery;
474
        }
475
        
476
        /**
477
         * The coverage format.
478
         * 
479
         * El formato de la cobertura.
480
         * @return String
481
         */
482
        public String getFormat() {
483
                return format;
484
        }
485
        
486
        /**
487
         * Sets the coverage format to download.
488
         * 
489
         * Establece el formato de la cobertura a descargar.
490
         * @param format
491
         */
492
        public void setFormat(String format) {
493
                this.format = format;
494
        }
495
        
496
        /**
497
         * Gets the max coverage extension.
498
         * 
499
         * Obtiene la extensi?n m?xima de la cobertura
500
         * @return
501
         * @throws DriverException
502
         * @throws IOException
503
         */
504
        public Rectangle2D getFullExtent() throws IOException, DriverException {
505
            if (fullExtent==null)
506
                fullExtent = driver.getFullExtent(coverageName, SRS);
507
                return fullExtent;
508
        }
509
        
510
        /**
511
         * Sets the max extension for the coverage. This value is specified
512
         * by the server. Thus, this method should be used ONLY to reload
513
         * this value from a saved proyect.
514
         * 
515
         * Establece la extensi?n m?xima de la cobertura. ?ste valor viene
516
         * especificado por el servidor. No deber?a de usarse m?s que para
517
         * recuperar un proyecto guardado o desde el Wizard.
518
         * 
519
         * @param fullExtent
520
         */
521
        public void setFullExtent(Rectangle2D fullExtent) {
522
                this.fullExtent = fullExtent;
523
        }
524
        
525
        /**
526
         * Gets the paramenter in name-value pair-formed string.
527
         * 
528
         * Recupera el valor de par?metro en forma de par nombre-valor: "nombre=valor"
529
         * 
530
         * @return String
531
         */
532
        public String getParameter() {
533
                return parameter;
534
        }
535
        
536
        /**
537
         * Sets the parameter and the parameter value list of the coverage as a name-value
538
         * pair form where, for the moment, value is a comma-separated values list. 
539
         * 
540
         * Establece el par?metro y la lista de valores de la cobertura en forma
541
         * de par nombre-valor donde valor es, por el momento, una lista separada 
542
         * por comas
543
         * @param parameter
544
         */
545
        public void setParameter(String parameter) {
546
                this.parameter = parameter;
547
        }
548
        
549
        /**
550
         * Gets the coverage SRS
551
         * 
552
         * Obtiene el SRS de la cobertura
553
         * @return String
554
         */
555
        public String getSRS() {
556
                return SRS;
557
        }
558
        
559
        /**
560
         * Sets the coverage SRS
561
         * 
562
         * Establece el SRS
563
         * @param srs
564
         */
565
        public void setSRS(String srs) {
566
                SRS = srs;
567
        }
568
        
569
        /**
570
         * Gets the TIME parameter.
571
         * 
572
         * Obtiene el par?metro TIME.
573
         * 
574
         * @return String
575
         */
576
        public String getTime() {
577
                return time;
578
        }
579

    
580
        /**
581
         * Sets the TIME parameter (according with the OGC standard it may
582
         * be a comma-separated value list, but probably the server will not
583
         * support querys with more than one value)
584
         * 
585
         * Establece el par?metro TIME (puede ser seg?n OGC una
586
         * lista de valores separados por comas pero casi seguro que
587
         * el servidor no soportar? m?s de un valor)
588
         * @param time
589
         */
590
        public void setTime(String time) {
591
                this.time = time;
592
        }
593
        
594
        /**
595
         * Gets the WCS server's address.
596
         * 
597
         * Obtiene la direcci?n del servidor WCS
598
         * @return String
599
         */
600
        public String getHost() {
601
                return ((FMapWCSDriver) driver).getHost();
602
        }
603
        
604
        /**
605
         * Sets the WCS server address.
606
         * 
607
         * Establece la direcci?n del servidor WCS
608
         * @param host (String)
609
         */
610
        public void setHost(String host) {
611
                ((FMapWCSDriver) driver).setHost(host);
612
        }
613
        
614
        /**
615
         * @deprecated
616
         * @param g
617
         * @param viewPort
618
         * @param fCoverage
619
         */
620
        private void drawJaume(Graphics2D g, ViewPort viewPort, File fCoverage) {
621
                Image coverage = renderizeRaster(getRaster(fCoverage));
622
                Point2D p1 = new Point2D.Double(bbox.getMinX(), bbox.getMaxY());
623
                viewPort.getAffineTransform().transform(p1, p1);
624
                g.drawImage(coverage, (int) p1.getX(), (int) p1.getY(), null);
625
        }
626
        
627
        /**
628
         * Computes the geofile raster.
629
         * 
630
         * Computa el r?ster del fichero geogr?fico.
631
         * 
632
         * @deprecated
633
         * @param coverage
634
         * @return RasterBuf
635
         */
636
        private RasterBuf getRaster(File coverage) {
637
                RasterBuf raster = null;
638
                
639
                Gdal migdal = new Gdal();
640
                GeoTransform gt = null;
641
                int ancho = 0, alto = 0;
642
                GdalRasterBand mirasterband = null;
643
                int rastercount = 0;
644
                
645
                try {
646
                        migdal.open(coverage.getAbsolutePath(), Gdal.GA_ReadOnly);
647
                } catch (Exception ge) {
648
                        ge.printStackTrace();
649
                }
650
                
651
                try {
652
                        gt = migdal.getGeoTransform();
653
                } catch (GdalException e) {
654
                        System.out
655
                        .println("I can't obtain the array geoTransform for this image");
656
                }
657
                
658
                try {
659
                        rastercount = migdal.getRasterCount();
660
                        ancho = migdal.getRasterXSize();
661
                        alto = migdal.getRasterYSize();
662
                        int ngcp = migdal.getGCPCount();
663
                        //System.out.println("NGCP="+ngcp);
664
                } catch (GdalException ge) {
665
                        ge.printStackTrace();
666
                        //...
667
                }
668
                
669
                try {
670
                        int dataType = migdal.getRasterBand(1).getRasterDataType();
671
                        GdalBuffer buf = null;
672
                        
673
                        /*
674
                         * Evita el problema de que haya m?s de 3 bandas en el fichero esto
675
                         * deberia hacerse asignando a las 3 bandas del raster una banda
676
                         * distinta del fichero (no necesariamente 1->0, 2->1 y 3->2
677
                         */
678
                        
679
                        if (rastercount > 3)
680
                                rastercount = 3;
681
                        if (dataType == Gdal.GDT_Byte) {
682
                                raster = new RasterBuf(RasterBuf.TYPE_INT, ancho, alto,
683
                                                rastercount, null);
684
                                for (int iBand = 0; iBand < rastercount; iBand++) {
685
                                        mirasterband = migdal.getRasterBand(iBand + 1);
686
                                        buf = mirasterband.readRaster(0, 0, ancho, alto, ancho,
687
                                                        alto, dataType);
688
                                        for (int y = 0; y < alto; y++)
689
                                                for (int x = 0; x < ancho; x++)
690
                                                        raster.setPixelInt(x, y, iBand, buf.buffByte[y
691
                                                                                                                                                 * ancho + x] & 0xff);
692
                                }
693
                                migdal.close();
694
                        } else if (dataType == Gdal.GDT_CInt16
695
                                        || dataType == Gdal.GDT_UInt16
696
                                        || dataType == Gdal.GDT_Int16) {
697
                                raster = new RasterBuf(RasterBuf.TYPE_INT, ancho, alto,
698
                                                rastercount, null);
699
                                for (int iBand = 0; iBand < rastercount; iBand++) {
700
                                        // System.out.println("Banda:"+iBand);
701
                                        mirasterband = migdal.getRasterBand(iBand + 1);
702
                                        buf = mirasterband.readRaster(0, 0, ancho, alto, ancho,
703
                                                        alto, dataType);
704
                                        for (int y = 0; y < alto; y++)
705
                                                for (int x = 0; x < ancho; x++)
706
                                                        raster.setPixelInt(x, y, iBand, buf.buffShort[y
707
                                                                                                                                                  * ancho + x] & 0xffff);
708
                                }
709
                                migdal.close();
710
                        }
711
                } catch (GdalException e1) {
712
                        e1.printStackTrace();
713
                }
714
                return raster;
715
        }
716
        
717
        /**
718
         * Construye un objeto Image a partir de un RasterBuf
719
         * @deprecated (usado en drawJaume)
720
         * @param raster
721
         * @return Image
722
         */
723
        public Image renderizeRaster(RasterBuf raster) {
724
                RasterStats stats = new RasterStats(raster.getBandNr());
725
                int alpha = 255; // transparencia
726
                boolean debug = false;
727
                ComputeMinMaxFilter filter = new ComputeMinMaxFilter(raster, stats);
728
                
729
                LinearEnhancementFilter lEFilter = new LinearEnhancementFilter(raster,
730
                                stats);
731
                Image image = null;
732
                if (raster.getBandNr() == 1)
733
                        image = new GreyscaleRasterToImageFilter(raster, alpha).getImage();
734
                else
735
                        image = new RasterToImageFilter(raster, alpha).getImage();
736
                
737
                if (debug)
738
                        stats.pinta();
739
                return image;
740
        }
741
        
742
        /**
743
         * Returns the current bounding box.
744
         * 
745
         * Devuelve la boundix box actual.
746
         * 
747
         * @return Rectangle2D
748
         */
749
        public Rectangle2D getBbox() {
750
                return bbox;
751
        }
752
        /**
753
         * Gets the max resolution of the coverage.
754
         * 
755
         * Obtiene la resoluci?n m?xima de la cobertura
756
         * @return maxRes
757
         */
758
        //public double getMaxResolution() {
759
        public Point2D getMaxResolution() {
760
                return maxRes;
761
        }
762

    
763
        /**
764
         * Sets the MAX resolution supported by the coverage.
765
         * 
766
         * The max resolution is given by the server within the DescribeCoverage document
767
         * in the SpationDomain section.
768
         * 
769
         * Use this method only to load this value from there (the DescribeCoverage document)
770
         * of from an already saved project because an incorrect value will bring
771
         * computing errors when doing "zoom to raster resolution".
772
         * 
773
         * 
774
         * 
775
         * Establece la resoluci?n M?XIMA que soporta la cobertura.
776
         * 
777
         * La resoluci?n m?xima viene fijada por el servidor dentro documento
778
         * DescribeCoverage en la secci?n SpatialDomain.
779
         * 
780
         * Use este m?todo ?nicamente para cargar el valor para la resoluci?n m?xima
781
         * desde all? o desde un proyecto guardado en anterioridad, puesto que un
782
         * valor incorrecto reportar? (conllevar?) errores de c?lculo cuando se haga
783
         * un "zoom a la resoluci?n del r?ster".
784
         * 
785
         * @param res
786
         */
787
        //public void setMaxResolution(double res) {
788
        public void setMaxResolution(Point2D res) {
789
                maxRes = res;
790
        }
791
        /**
792
         * Sets the transparency for the next PxRaster that is going to be loaded.
793
         * 
794
         * Asigna la transparencia para el siguiente PxRaster que se cargue.
795
         * @param t
796
         */
797
        public void setTransparency(int t){
798
                this.transparency = t;
799
        }
800
        
801
        /**
802
         * Sets the R-band.
803
         * 
804
         * Asigna la banda R.
805
         * @param r
806
         */
807
        public void setBandR(int r){
808
                this.rband = r;
809
        }
810
        
811
        /**
812
         * Sets the G-band.
813
         * 
814
         * Asigna la banda G
815
         * @param g
816
         */
817
        public void setBandG(int g){
818
                this.gband = g;
819
        }
820
        
821
        /**
822
         * Sets the B-band.
823
         * 
824
         * Asigna la banda B
825
         * @param b
826
         */
827
        public void setBandB(int b){
828
                this.bband = b;
829
        }
830

    
831
        /**
832
         * Gets the coverage (not the FLyrWCS) from an URL.
833
         * 
834
         * Obtiene la cobertura (no la FLyrWCS) a partir de una URL.
835
         * @param query
836
         */
837
        public void getCoverageFromQuery(String query) {
838
                driver.setGetCoverageParams(query);
839
        }
840
}