Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / fmap / raster / layers / FLyrRasterSE.java @ 13601

History | View | Annotate | Download (39.5 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
package org.gvsig.fmap.raster.layers;
20

    
21
import java.awt.Dimension;
22
import java.awt.Graphics2D;
23
import java.awt.Point;
24
import java.awt.Rectangle;
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.NoninvertibleTransformException;
27
import java.awt.geom.Point2D;
28
import java.awt.geom.Rectangle2D;
29
import java.awt.image.BufferedImage;
30
import java.io.File;
31
import java.io.IOException;
32
import java.lang.reflect.Constructor;
33
import java.lang.reflect.InvocationTargetException;
34
import java.util.ArrayList;
35

    
36
import javax.print.attribute.PrintRequestAttributeSet;
37
import javax.swing.ImageIcon;
38

    
39
import org.cresques.cts.IProjection;
40
import org.gvsig.fmap.raster.legend.ColorTableLegend;
41
import org.gvsig.raster.RasterLibrary;
42
import org.gvsig.raster.buffer.BufferFactory;
43
import org.gvsig.raster.dataset.CompositeDataset;
44
import org.gvsig.raster.dataset.FileNotOpenException;
45
import org.gvsig.raster.dataset.IBuffer;
46
import org.gvsig.raster.dataset.IRasterDataSource;
47
import org.gvsig.raster.dataset.InvalidSetViewException;
48
import org.gvsig.raster.dataset.MosaicNotValidException;
49
import org.gvsig.raster.dataset.MultiRasterDataset;
50
import org.gvsig.raster.dataset.NotSupportedExtensionException;
51
import org.gvsig.raster.dataset.RasterDataset;
52
import org.gvsig.raster.dataset.RasterDriverException;
53
import org.gvsig.raster.dataset.properties.DatasetMetadata;
54
import org.gvsig.raster.datastruct.ColorTable;
55
import org.gvsig.raster.datastruct.Extent;
56
import org.gvsig.raster.datastruct.ViewPortData;
57
import org.gvsig.raster.grid.Grid;
58
import org.gvsig.raster.grid.GridPalette;
59
import org.gvsig.raster.grid.GridTransparency;
60
import org.gvsig.raster.grid.filter.RasterFilterList;
61
import org.gvsig.raster.grid.filter.RasterFilterListManager;
62
import org.gvsig.raster.grid.filter.bands.ColorTableFilter;
63
import org.gvsig.raster.grid.filter.bands.ColorTableListManager;
64
import org.gvsig.raster.grid.filter.enhancement.EnhancementListManager;
65
import org.gvsig.raster.grid.render.Rendering;
66
import org.gvsig.raster.hierarchy.IRasterDataset;
67
import org.gvsig.raster.hierarchy.IRasterOperations;
68
import org.gvsig.raster.hierarchy.IRasterProperties;
69
import org.gvsig.raster.hierarchy.IStatistics;
70
import org.gvsig.raster.util.Historical;
71
import org.gvsig.raster.util.MathUtils;
72

    
73
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
74
import com.iver.andami.PluginServices;
75
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
76
import com.iver.cit.gvsig.fmap.MapControl;
77
import com.iver.cit.gvsig.fmap.ViewPort;
78
import com.iver.cit.gvsig.fmap.core.FShape;
79
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
80
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
81
import com.iver.cit.gvsig.fmap.layers.LayerChangeSupport;
82
import com.iver.cit.gvsig.fmap.layers.LayerListener;
83
import com.iver.cit.gvsig.fmap.layers.LegendListener;
84
import com.iver.cit.gvsig.fmap.layers.Tiling;
85
import com.iver.cit.gvsig.fmap.layers.XMLException;
86
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
87
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint;
88
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem;
89
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem;
90
import com.iver.cit.gvsig.fmap.rendering.ILegend;
91
import com.iver.cit.gvsig.project.documents.view.gui.IView;
92
import com.iver.cit.gvsig.project.documents.view.gui.View;
93
import com.iver.utiles.NotExistInXMLEntity;
94
import com.iver.utiles.XMLEntity;
95
import com.iver.utiles.swing.threads.Cancellable;
96
/**
97
 * Capa raster
98
 * @author Nacho Brodin (nachobrodin@gmail.com)
99
 */
100
public class FLyrRasterSE extends FLyrDefault
101
        implements IRasterProperties, IRasterDataset, InfoByPoint, Classifiable, IRasterOperations, IRasterLayerActions {
102
        public static double          noDataDefault      = -99999;
103
        boolean                       isPrinting         = false;
104
        boolean                       mustTileDraw       = false;
105
        boolean                       mustTilePrint      = true;
106
        private int                   maxTileDrawWidth   = 200;
107
        private int                   maxTileDrawHeight  = 200;
108
        int                           maxTilePrintWidth  = 1500;
109
        int                           maxTilePrintHeight = 1500;
110
        private StatusRasterInterface status             = null;
111
        private boolean               firstLoad          = false;
112
        private boolean               removeRasterFlag   = true;
113
        private Object                params             = null;
114
        protected IRasterDataSource   dataset            = null;
115
        protected Rendering           render             = null;
116
        protected BufferFactory       bufferFactory      = null;
117
        private int                   posX               = 0;
118
        private int                   posY               = 0;
119
        private double                posXWC             = 0;
120
        private int                   posYWC             = 0;
121
        private int                   r                  = 0;
122
        private int                   g                  = 0;
123
        private int                   b                  = 0;
124
        private LayerChangeSupport    layerChangeSupport = new LayerChangeSupport();
125
        public double                 noDataValue        = -99999;
126
        
127
        /**
128
         * Lista de transformaciones afines que son aplicadas. Esta lista es simplemente un
129
         * historico que no se utiliza. Es posible utilizarlo para recuperar transformaciones
130
         * anteriores.
131
         */
132
        private Historical            affineTransformList = new Historical();
133
        
134
        static {
135
                 RasterLibrary.wakeUp();
136
        }
137

    
138
        /**
139
         * Crea una capa Raster a partir del nombre driver, fichero y proyecci?n.
140
         * @param layerName Nombre de la capa.
141
         * @param d RasterDriver.
142
         * @param f Fichero.
143
         * @param proj Proyecci?n.
144
         * @return Nueva capa de tipo raster.
145
         * @throws DriverIOException
146
         */
147
        public static FLyrRasterSE createLayer(String layerName, Object params,
148
                        IProjection proj) throws LoadLayerException {
149
                FLyrRasterSE capa = new FLyrRasterSE();
150
                capa.setLoadParams(params);
151
                capa.setName(layerName);
152
                capa.setProjection(proj);
153
                capa.load();
154
                return capa;
155
        }
156

    
157
        /**
158
         * Asigna los par?metros para la carga de la capa
159
         * @param param Par?metros.
160
         */
161
        public void setLoadParams(Object param){
162
                this.params = param;
163
        }
164

    
165
        /**
166
         * Obtiene los par?metros para la carga de la capa
167
         * @return param Par?metros.
168
         */
169
        public Object getLoadParams() {
170
                return params;
171
        }
172

    
173
        /**
174
         * Redefine wakeUp de FLyrDefault
175
         */
176
        public void wakeUp(){
177
        }
178

    
179
        /**
180
         * Asignar el estado del raster
181
         * @param status
182
         */
183
        public void setStatus(StatusRasterInterface status){
184
                this.status = status;
185
        }
186

    
187
        /**
188
         * Obtiene el estado del raster
189
         * @return
190
         */
191
        public StatusRasterInterface getStatus(){
192
                return this.status;
193
        }
194

    
195
        /*
196
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
197
         */
198
        public void load() throws LoadLayerException{
199
                if (getProjection() != null) {
200
                        String fName = null;
201
                        int test = -1;
202
                        if (params != null && params instanceof File) {
203
                                fName = ((File) params).getAbsolutePath();
204
                                test = fName.indexOf("ecwp:");
205
                        }
206

    
207
                        if (test != -1) {
208
                                String urlECW = fName.substring(test + 6);
209
                                fName = "ecwp://" + urlECW;
210
                                System.err.println(test + " " + fName);
211
                        }
212

    
213
                        try {
214
                                if(params instanceof String[][]) {
215
                                        String[][] files = (String[][])params;
216
                                        MultiRasterDataset[][] dt = new MultiRasterDataset[files.length][files[0].length];
217
                                        for (int i = 0; i < files.length; i++) 
218
                                                for (int j = 0; j < files[i].length; j++) 
219
                                                        dt[i][j] = MultiRasterDataset.open(getProjection(), files[i][j]);
220
                                        dataset = new CompositeDataset(dt);
221
                                } else if (params == null || params instanceof File) {
222
                                        if(fName != null)
223
                                                dataset = MultiRasterDataset.open(getProjection(), fName);
224
                                } else
225
                                        dataset = MultiRasterDataset.open(getProjection(), params);
226
                        } catch (NotSupportedExtensionException e) {
227
                                throw new LoadLayerException("Formato no valido", e);
228
                        } catch (RasterDriverException e) {
229
                                throw new LoadLayerException("Formato no valido", e);
230
                        } catch (MosaicNotValidException e) {
231
                                throw new LoadLayerException("Error en el mosaico", e);
232
                        }
233
                        if(dataset != null)
234
                                this.init();
235
                } else
236
                        throw new LoadLayerException("Proyecci?n no asignada", new IOException());
237
        }
238

    
239
        /**
240
         * Acciones de inicializaci?n despu?s de que la fuente de datos
241
         * de la capa est? asignada. El tipo de fuente de datos es variable
242
         * puede ser MultiRasterDataset, CompositeDataset u otras que existan e
243
         * implementen IRasterDatasource.
244
         */
245
        public void init() throws LoadLayerException {
246
                if (dataset == null)
247
                        throw new LoadLayerException("Formato no valido", new IOException());
248
                bufferFactory = new BufferFactory(dataset);
249
                render = new Rendering(bufferFactory);
250
                initFilters();
251
                
252
                //Inicializaci?n del historico de transformaciones
253
                affineTransformList.clear();
254
                affineTransformList.add(this.getAffineTransform());
255
        }
256
        
257
        /**
258
         * Crea el objeto renderizador de raster
259
         * @return Rendering
260
         */
261
        public Rendering getRender() {
262
                if (render == null)
263
                        render = new Rendering(bufferFactory);
264
                return render;
265
        }
266

    
267
        /**
268
         * Filtros a?adidos por defecto en la pila para visualizaci?n.
269
         */
270
        private void initFilters() {
271
                RasterFilterList filterList = new RasterFilterList();
272
                filterList.addParam("IStatistics", getDataSource().getStatistics());
273
                filterList.addParam("MultiRasterDataset", getDataSource());
274
                GridTransparency gridTransparency = new GridTransparency(getDataSource().getTransparencyFilesStatus());
275
                // Inicializo la transparencia tanto para el filtro como para el render
276
                filterList.addParam("Transparency", gridTransparency);
277
                getRender().setLastTransparency(gridTransparency);
278

    
279
                filterList.setInitDataType(getDataType()[0]);
280
                RasterFilterListManager filterManager = new RasterFilterListManager(filterList);
281

    
282
                if (this.getDataSource().getColorTables()[0] != null) {
283
                        GridPalette p = new GridPalette(getDataSource().getColorTables()[0]);
284
                        ColorTableListManager ctm = new ColorTableListManager(filterManager);
285
                        ctm.addColorTableFilter(p);
286
                } else {
287
                        if (getDataType()[0] != IBuffer.TYPE_BYTE) {
288
                                IStatistics stats = getDataSource().getStatistics();
289
                                EnhancementListManager elm = new EnhancementListManager(filterManager);
290
                                elm.addEnhancedFilter(false, stats, 0.0, getRender().getRenderBands());
291
                        }
292
                }
293

    
294
                getRender().setFilterList(filterList);
295
        }
296

    
297
        /**
298
         * @throws ReadDriverException 
299
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
300
         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
301
         *                 com.iver.utiles.swing.threads.Cancellable)
302
         */
303
        public void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel, double scale) throws ReadDriverException {
304
                if (isWithinScale(scale)) {
305

    
306
                        if (status != null && firstLoad) {
307
                                if (mustTileDraw) {
308
                                        Point2D p = vp.getOffset();
309
                                        Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight());
310
                                        Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
311
                                        tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
312
                                        for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) {
313
                                                // drawing part
314
                                                try {
315
                                                        ViewPort vport = tiles.getTileViewPort(vp, tileNr);
316
                                                        // g.setClip(tiles.getClip(tileNr).x, tiles.getClip(tileNr).y, tiles.getClip(tileNr).width - 5, tiles.getClip(tileNr).height);
317
                                                        try {
318
                                                                draw(image, g, vport, cancel);
319
                                                        } catch (ArrayIndexOutOfBoundsException e) {
320
                                                                throw new ReadDriverException("", e);
321
                                                        } catch (InvalidSetViewException e) {
322
                                                                throw new ReadDriverException("Error al asignar la vista en el draw.", e);
323
                                                        } catch (InterruptedException e) {
324
                                                                throw new ReadDriverException("Dibujado interrumpido.", e);
325
                                                        }
326
                                                } catch (NoninvertibleTransformException e) {
327
                                                        throw new ReadDriverException("Error en la transformaci?n", e);
328
                                                }
329
                                        }
330
                                } else
331
                                        try {
332
                                                draw(image, g, vp, cancel);
333
                                        } catch (ArrayIndexOutOfBoundsException e) {
334
                                                throw new ReadDriverException("", e);
335
                                        } catch (InvalidSetViewException e) {
336
                                                throw new ReadDriverException("Error al asignar la vista en el draw.", e);
337
                                        } catch (InterruptedException e) {
338
                                                throw new ReadDriverException("Dibujado interrumpido.", e);
339
                                        }
340
                                status.applyStatus(this);
341
                                firstLoad = false;
342
                        }
343

    
344
                        if (mustTileDraw) {
345
                                Point2D p = vp.getOffset();
346
                                Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight());
347
                                Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
348
                                tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
349
                                for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) {
350
                                        // drawing part
351
                                        try {
352
                                                ViewPort vport = tiles.getTileViewPort(vp, tileNr);
353
                                                try {
354
                                                        draw(image, g, vport, cancel);
355
                                                } catch (ArrayIndexOutOfBoundsException e) {
356
                                                        throw new ReadDriverException("", e);
357
                                                } catch (InvalidSetViewException e) {
358
                                                        throw new ReadDriverException("Error al asignar la vista en el draw.", e);
359
                                                } catch (InterruptedException e) {
360
                                                        throw new ReadDriverException("Dibujado interrumpido.", e);
361
                                                }
362
                                        } catch (NoninvertibleTransformException e) {
363
                                                throw new ReadDriverException("Error en la transformaci?n", e);
364
                                        }
365
                                }
366
                        } else {
367
                                try {
368
                                        draw(image, g, vp, cancel);
369
                                } catch (ArrayIndexOutOfBoundsException e) {
370
                                        throw new ReadDriverException("", e);
371
                                } catch (InvalidSetViewException e) {
372
                                        throw new ReadDriverException("Error al asignar la vista en el draw.", e);
373
                                } catch (InterruptedException e) {
374
                                        throw new ReadDriverException("Dibujado interrumpido.", e);
375
                                }
376
                        }
377

    
378
                        if (getVirtualLayers() != null) {
379
                                getVirtualLayers().draw(image, g, vp, cancel, scale);
380
                        }
381
                }
382
        }
383

    
384
        private void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel) throws ArrayIndexOutOfBoundsException, InvalidSetViewException, InterruptedException {
385
                Extent e = new Extent(vp.getAdjustedExtent());
386
                Dimension imgSz = vp.getImageSize();
387
                ViewPortData vp2 = new ViewPortData(vp.getProjection(), e, imgSz );
388
                vp2.setMat(vp.getAffineTransform());
389
                getRender().draw(g, vp2);
390
        }
391

    
392
        /**
393
         * Inserta la proyecci?n.
394
         *
395
         * @param proj Proyecci?n.
396
         */
397
        public void setProjection(IProjection proj) {
398
                super.setProjection(proj);
399
        }
400

    
401
        /*
402
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
403
         */
404
        public Rectangle2D getFullExtent(){
405
                return dataset.getExtent().toRectangle2D();
406

    
407
        }
408

    
409
        /**
410
         * Obtiene el valor del pixel del Image en la posici?n real x,y
411
         * @param x Posici?n x
412
         * @param y Posici?n y
413
         * @return valor de pixel
414
         */
415
        public int[] getPixel(double wcx, double wcy) {
416
                int[] argb = { -1, -1, -1, -1 };
417
                if (wcx <= getMaxX() && wcx >= getMinX() && wcy <= getMaxY() && wcy >= getMinY()) {
418
                        View theView = (View) PluginServices.getMDIManager().getActiveWindow();
419
                        if (theView instanceof IView) {
420
                                // BufferedImage buf = ((IView) theView).getMapControl().getImage();
421
                                Point2D p = ((IView) theView).getMapControl().getViewPort().fromMapPoint(wcx, wcy);
422
                                return getPixel((int) p.getX(), (int) p.getY());
423
                        }
424
                }
425
                return argb;
426
        }
427

    
428
        /**
429
         * Obtiene el valor del pixel del Image en la posici?n x,y
430
         * @param x Posici?n x
431
         * @param y Posici?n y
432
         * @return valor de pixel
433
         */
434
        public int[] getPixel(int pxx, int pxy) {
435
                int[] argb = { -1, -1, -1, -1 };
436
                View theView = (View) PluginServices.getMDIManager().getActiveWindow();
437
                BufferedImage buf = null;
438
                if (theView instanceof IView)
439
                        buf = ((IView) theView).getMapControl().getImage();
440
                if (pxx >= 0 && pxx < buf.getWidth() && pxy >= 0 && pxy < buf.getHeight()) {
441
                        if (theView instanceof IView) {
442
                                int value = buf.getRGB(pxx, pxy);
443
                                argb[0] = ((value & 0xff000000) >> 24);
444
                                argb[1] = ((value & 0x00ff0000) >> 16);
445
                                argb[2] = ((value & 0x0000ff00) >> 8);
446
                                argb[3] = (value & 0x000000ff);
447
                        }
448
                }
449
                return argb;
450
        }
451

    
452
        /*
453
         * (non-Javadoc)
454
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getMaxX()
455
         */
456
        public double getMaxX(){
457
                return this.getFullExtent().getMaxX();
458
        }
459

    
460
        /*
461
         * (non-Javadoc)
462
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getMaxY()
463
         */
464
        public double getMaxY(){
465
                return this.getFullExtent().getMaxY();
466
        }
467

    
468
        /*
469
         * (non-Javadoc)
470
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getMinX()
471
         */
472
        public double getMinX(){
473
                return this.getFullExtent().getMinX();
474
        }
475

    
476
        /*
477
         * (non-Javadoc)
478
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getMinY()
479
         */
480
        public double getMinY(){
481
                return this.getFullExtent().getMinY();
482
        }
483

    
484
        /* (non-Javadoc)
485
         * @deprecated. See String getInfo(Point p) throws DriverException
486
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
487
         */
488
        public String queryByPoint(Point p) {
489
                String data = "<file:" + normalizeAsXMLTag(getName()) + ">\n";
490

    
491
                ArrayList attr = getAttributes();
492
                data += "  <raster\n";
493
                data += "    File=\"" + getFile() + "\"\n";
494
                for (int i = 0; i < attr.size(); i++) {
495
                        Object[] a = (Object[]) attr.get(i);
496

    
497
                        data += "    " + a[0].toString() + "=";
498
                        if (a[1].toString() instanceof String)
499
                                data += "\"" + a[1].toString() + "\"\n";
500
                        else
501
                                data += a[1].toString() + "\n";
502
                }
503
                data += "    Point=\"" + posX + " , " + posY + "\"\n";
504
                data += "    Point_WC=\"" + MathUtils.format(posXWC, 3) + " , " + MathUtils.format(posYWC, 3) + "\"\n";
505
                data += "    RGB=\"" + r + ", " + g + ", " + b + "\"\n";
506
                data += "  />\n";
507

    
508
                data += "</file:" + normalizeAsXMLTag(getName()) + ">\n";
509
                return data;
510
        }
511

    
512
        public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException {
513

    
514
                Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
515
                Point2D px = null;
516
                if(        pReal.getX() > this.getMinX() &&
517
                        pReal.getX() < this.getMaxX() &&
518
                        pReal.getY() > this.getMinY() &&
519
                        pReal.getY() < this.getMaxY()) {
520
                        ArrayList attr = getAttributes();
521
                        int w = 0, h = 0;
522
                        for (int i = 0; i < attr.size(); i++) {
523
                                Object[] a = (Object[]) attr.get(i);
524
                                if (a[0].toString().equals("Width"))
525
                                        w = ((Integer) a[1]).intValue();
526
                                if (a[0].toString().equals("Height"))
527
                                        h = ((Integer) a[1]).intValue();
528
                        }
529
                        px = new Point2D.Double();
530
                        px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWCWidth(),
531
                                                        ((this.getMaxY() - pReal.getY()) * h) / getWCHeight());
532
                }
533
                int[] rgb = getPixel((int) p.getX(), (int) p.getY());
534

    
535
                StringXMLItem[] item = new StringXMLItem[1];
536
                String data = "<file:" + normalizeAsXMLTag(getName()) + ">\n";
537

    
538
                data += "  <raster\n";
539
                data += "    View_Point=\"" + p.getX() + " , " + p.getY() + "\"\n";
540
                data += "    World_Point=\"" + MathUtils.format(pReal.getX(), 3) + " , " + MathUtils.format(pReal.getY(), 3) + "\"\n";
541
                if (px == null)
542
                        data += "    Pixel_Point=\"Out\"\n";
543
                else
544
                        data += "    Pixel_Point=\"" + (int) px.getX() + " , " + (int) px.getY() + "\"\n";
545
                data += "    RGB=\"" + rgb[1] + "  " + rgb[2] + "  " + rgb[3] + "\"\n";
546
                data += "    Band_Value=\"";
547
                try {
548
                        if (px != null) {
549
                                if(getDataType()[0] >= 0 && getDataType()[0] <= 3){
550
                                        for(int i = 0; i < getBandCount(); i++)
551
                                                data += ((Integer)getDataSource().getData((int)px.getX(), (int)px.getY(), i)).intValue() + "  ";
552
                                }
553
                                if(getDataType()[0] == 4){
554
                                        for(int i = 0; i < getBandCount(); i++)
555
                                                data += ((Float)getDataSource().getData((int)px.getX(), (int)px.getY(), i)).floatValue() + "  ";
556
                                }
557
                                if(getDataType()[0] == 5){
558
                                        for(int i = 0; i < getBandCount(); i++)
559
                                                data += ((Double)getDataSource().getData((int)px.getX(), (int)px.getY(), i)).doubleValue() + "  ";
560
                                }
561
                        }
562
                } catch (RasterDriverException ex) {
563
                        throw new ReadDriverException("Error en el acceso al dataset", ex);
564
                } catch (InvalidSetViewException ex) {
565
                        throw new ReadDriverException("Error en la asignaci?n de la vista en getData", ex);
566
                } catch (FileNotOpenException ex) {
567
                        throw new ReadDriverException("Fichero no abierto en el dataset", ex);
568
                }
569
                data += "\"\n";
570
                data += "  />\n";
571
                data += "</file:" + normalizeAsXMLTag(getName()) + ">\n";
572

    
573
                item[0] = new StringXMLItem(data, this);
574
                return item;
575
        }
576

    
577
        /**
578
         * Filters a string for being suitable as XML Tag, erasing
579
         * all not alphabetic or numeric characters.
580
         * @param s
581
         * @return string normalized
582
         */
583
        public String normalizeAsXMLTag(String s) {
584
                return s.replaceAll("[^a-zA-Z0-9]", "");
585
        }
586

    
587
        /**
588
         * Obtiene atributos a partir de un georasterfile
589
         * @return
590
         */
591
        public ArrayList getAttributes() {
592
                ArrayList attr = new ArrayList();
593
                Object [][] a = {
594
                        {"Filename", dataset.getDataset(0)[0].getFName()},
595
                        {"Filesize", new Long(dataset.getFileSize())},
596
                        {"Width", new Integer((int)dataset.getWidth())},
597
                        {"Height", new Integer((int)dataset.getHeight())},
598
                        {"Bands", new Integer(dataset.getBandCount())}
599
                };
600
                for (int i = 0; i < a.length; i++)
601
                        attr.add(a[i]);
602
                return attr;
603
        }
604

    
605
        /**
606
         * Escribe en el proyecto la capa actual
607
         * @throws XMLException
608
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
609
         */
610
        public XMLEntity getXMLEntity() throws XMLException {
611
                XMLEntity xml = super.getXMLEntity();
612
                if(getFile() != null)
613
                        xml.putProperty("file", getFile());
614
                xml.putProperty("driverName", "gvSIG Raster Driver");
615

    
616
                // Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
617
                if (status == null)
618
                        status = new StatusLayerRaster();
619
                status.getXMLEntity(xml, true, this);
620

    
621
                return xml;
622
        }
623

    
624
        public void setXMLEntity03(XMLEntity xml) throws XMLException {
625
        }
626

    
627
        /**
628
         * Recupera de disco los datos de la capa.
629
         */
630
        public void setXMLEntity(XMLEntity xml)throws XMLException {
631
                super.setXMLEntity(xml);
632

    
633
                try {
634
                        params = new File(xml.getStringProperty("file"));
635
                
636
                        // Para notificar al adapter-driver cual es la proyecci?n.
637
                        setProjection(super.getProjection());
638

    
639
                        //Inicializamos la clase a la que se usa por defecto para
640
                        //compatibilidad con proyectos antiguos
641
                        String claseStr = StatusLayerRaster.defaultClass;
642
                        if (xml.contains("raster.class"))
643
                                claseStr = xml.getStringProperty("raster.class");
644

    
645
                        if (status != null)
646
                                status.setXMLEntity(xml, this);
647
                        else {
648
                                // Cuando cargamos un proyecto
649

    
650
                                if (claseStr != null && !claseStr.equals("")) {
651
                                        try {
652
                                                Class clase = Class.forName(claseStr);
653
                                                Constructor constr = clase.getConstructor(null);
654
                                                status = (StatusRasterInterface) constr.newInstance(null);
655
                                                if (status != null)
656
                                                        status.setXMLEntity(xml, this);
657
                                        } catch (ClassNotFoundException exc) {
658
                                                throw new XMLException("Error localizando la clase a instanciar. " + claseStr, exc);
659
                                        } catch (InstantiationException exc) {
660
                                                throw new XMLException("Error instanciando " + claseStr, exc);
661
                                        } catch (IllegalAccessException exc) {
662
                                                throw new XMLException("Error instanciando " + claseStr, exc);
663
                                        } catch (NoSuchMethodException exc) {
664
                                                throw new XMLException("Error instanciando " + claseStr, exc);
665
                                        } catch (InvocationTargetException exc) {
666
                                                throw new XMLException("Error obteniendo el constructor para la clase " + claseStr, exc);
667
                                        }
668
                                }
669
                        }
670
                        firstLoad = true;
671
                } catch (NotExistInXMLEntity e) {
672
                        
673
                }
674

    
675
        }
676

    
677
        /* (non-Javadoc)
678
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
679
         */
680
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet propeties) throws ReadDriverException {
681

    
682
                if (!isVisible() || !isWithinScale(scale))
683
                        return;
684

    
685
                isPrinting = true;
686
                if (!mustTilePrint) {
687
                        draw(null, g, viewPort, cancel,scale);
688
                } else {
689
                        // Para no pedir imagenes demasiado grandes, vamos
690
                        // a hacer lo mismo que hace EcwFile: chunkear.
691
                        // Llamamos a drawView con cuadraditos m?s peque?os
692
                        // del BufferedImage ni caso, cuando se imprime viene con null
693
                        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds());
694
                        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
695

    
696
                        //Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n
697
                        //de realce si la imagen es de 16 bits.
698

    
699
                        //RasterStats stats = getSource().getFilterStack().getStats();
700
                        //if(stats != null)
701
                        //stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue));
702

    
703

    
704
                        for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) {
705
                                // Parte que dibuja
706
                                try {
707
                                        ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
708
                                        draw(null, g, vp, cancel, scale);
709
                                } catch (NoninvertibleTransformException e) {
710
                                        throw new ReadDriverException("Error en la transformaci?n.", e);
711
                                }
712
                        }
713
                        /*if(stats != null){
714
                                getSource().getFilterStack().getStats().history.clear();
715
                                stats = getSource().getFilterStack().getStats();
716
                        }*/
717
                }
718
                isPrinting = false;
719
        }
720

    
721
        public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale) throws ReadDriverException {
722
                // Para no pedir imagenes demasiado grandes, vamos
723
                // a hacer lo mismo que hace EcwFile: chunkear.
724
                // Llamamos a drawView con cuadraditos m?s peque?os
725
                // del BufferedImage ni caso, cuando se imprime viene con null
726

    
727
                int numW, numH;
728
                int stepX, stepY;
729
                int xProv, yProv;
730
                int A = 1500;
731
                int H = 1500;
732
                int altoAux, anchoAux;
733

    
734
                AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone();
735

    
736
                // Vamos a hacerlo en trozos de AxH
737
                Rectangle r = g.getClipBounds();
738
                numW = (int) (r.width) / A;
739
                numH = (int) (r.height) / H;
740

    
741
                double[] srcPts = new double[8];
742
                double[] dstPts = new double[8];
743

    
744
                yProv = (int) r.y;
745
                for (stepY = 0; stepY < numH + 1; stepY++) {
746
                        if ((yProv + H) > r.getMaxY())
747
                                altoAux = (int) r.getMaxY() - yProv;
748
                        else
749
                                altoAux = H;
750

    
751
                        xProv = (int) r.x;
752
                        for (stepX = 0; stepX < numW + 1; stepX++) {
753
                                if ((xProv + A) > r.getMaxX())
754
                                        anchoAux = (int) r.getMaxX() - xProv;
755
                                else
756
                                        anchoAux = A;
757

    
758
                                //Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux);
759

    
760
                                // Parte que dibuja
761
                                srcPts[0] = xProv;
762
                                srcPts[1] = yProv;
763
                                srcPts[2] = xProv + anchoAux + 1;
764
                                srcPts[3] = yProv;
765
                                srcPts[4] = xProv + anchoAux + 1;
766
                                srcPts[5] = yProv + altoAux + 1;
767
                                srcPts[6] = xProv;
768
                                srcPts[7] = yProv + altoAux + 1;
769

    
770
                                try {
771
                                        mat.inverseTransform(srcPts, 0, dstPts, 0, 4);
772
                                        Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(dstPts[0], dstPts[1], dstPts[2] - dstPts[0], dstPts[5] - dstPts[3]);
773
                                        // Extent extent = new Extent(rectCuadricula);
774

    
775
                                        Dimension tam = new Dimension(anchoAux + 1, altoAux + 1);
776
                                        ViewPort vp = viewPort.cloneViewPort();
777
                                        vp.setImageSize(tam);
778
                                        vp.setExtent(rectCuadricula);
779
                                        vp.setAffineTransform(mat);
780
                                        draw(null, g, vp, cancel, scale);
781

    
782
                                } catch (NoninvertibleTransformException e) {
783
                                        throw new ReadDriverException("Error en la transformaci?n.", e);
784
                                }
785
                                // Fin parte que dibuja
786
                                xProv = xProv + A;
787
                        }
788
                        yProv = yProv + H;
789
                }
790
        }
791

    
792
        /**
793
         * Borra de la lista de listeners el que se pasa como par?metro.
794
         *
795
         * @param o LayerListener a borrar.
796
         *
797
         * @return True si ha sido correcto el borrado del Listener.
798
         */
799
        public boolean removeLayerListener(LayerListener o) {
800
                //Salva a RMF
801
                try {
802
                        if(this.getDataSource() != null)
803
                                this.getDataSource().saveRmfModification();
804
                } catch (IOException e) {
805
                        //No se ha salvado nada
806
                }
807

    
808
                if (this.isRemoveRasterFlag()) {
809
                        dataset.close();
810
                        this.setRemoveRasterFlag(true);
811
                }
812
                return super.layerListeners.remove(o);
813
        }
814

    
815
        /**
816
         * @return Returns the removeRasterFlag.
817
         */
818
        public boolean isRemoveRasterFlag() {
819
                return removeRasterFlag;
820
        }
821

    
822
        /**
823
         * Asigna el valor del flag que dice si destruimos la memoria del raster
824
         * al eliminarlo del TOC o  no.
825
         * @param removeRasterFlag The removeRasterFlag to set.
826
         */
827
        public void setRemoveRasterFlag(boolean removeRasterFlag) {
828
                this.removeRasterFlag = removeRasterFlag;
829
        }
830

    
831
        public ImageIcon getTocImageIcon() {
832
                return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG"));
833
        }
834

    
835
        /*
836
         *  (non-Javadoc)
837
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
838
         */
839
        public int[] getTileSize() {
840
                int[] size = {maxTileDrawWidth, maxTileDrawHeight};
841
                return size;
842
        }
843

    
844
        /*
845
         *  (non-Javadoc)
846
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
847
         */
848
        public boolean isTiled() {
849
                return mustTileDraw;
850
        }
851

    
852
        /**
853
         * Obtiene el flag que dice si la imagen est? o no georreferenciada
854
         * @return true si est? georreferenciada y false si no lo est?.
855
         */
856
        public boolean isGeoreferenced() {
857
                return dataset.isGeoreferenced();
858
        }
859

    
860
        /**
861
         * Get datasource object
862
         * @return
863
         */
864
        public BufferFactory getBufferFactory(){
865
                return bufferFactory;
866
        }
867

    
868
        /**
869
         * Asigna el valor noData asociado a la capa
870
         * @return double que representa el valor noData asociado a la capa
871
         */
872
        public double getNoDataValue() {
873
                return noDataValue;
874
        }
875

    
876
        /**
877
         * Asigna el valor no data asociado a la capa
878
         * @param nd
879
         */
880
        public void setNoDataValue(double nd){
881
                if (bufferFactory != null)
882
                        bufferFactory.setNoDataValue(nd);
883
                noDataValue = nd;
884
        }
885

    
886
        /*
887
         * (non-Javadoc)
888
         * @see org.gvsig.fmap.raster.IRasterOperations#getPXHeight()
889
         */
890
        public double getPxHeight() {
891
                return dataset.getHeight();
892
        }
893

    
894
        /*
895
         * (non-Javadoc)
896
         * @see org.gvsig.fmap.raster.IRasterOperations#getPxWidth()
897
         */
898
        public double getPxWidth() {
899
                return dataset.getWidth();
900
        }
901

    
902
        /*
903
         * (non-Javadoc)
904
         * @see org.gvsig.fmap.raster.IGeoDimension#getWCHeight()
905
         */
906
        public double getWCHeight() {
907
                return getFullExtent().getHeight();
908
        }
909

    
910
        /*
911
         * (non-Javadoc)
912
         * @see org.gvsig.fmap.raster.IGeoDimension#getWCWidth()
913
         */
914
        public double getWCWidth() {
915
                return getFullExtent().getWidth();
916
        }
917

    
918
        /*
919
         * (non-Javadoc)
920
         * @see org.gvsig.fmap.raster.IRasterFile#getFileSize()
921
         */
922
        public long[] getFileSize(){
923
                int nFiles = dataset.getDatasetCount();
924
                long[] s = new long[nFiles];
925
                for (int i = 0; i < nFiles; i++)
926
                        s[i] = dataset.getFileSize();
927
                return s;
928
        }
929

    
930
        /*
931
         * (non-Javadoc)
932
         * @see org.gvsig.fmap.raster.IRasterFile#getFileName()
933
         */
934
        public String[] getFileName(){
935
                int nFiles = dataset.getDatasetCount();
936
                String[] s = new String[nFiles];
937
                for (int i = 0; i < nFiles; i++)
938
                        s[i] = dataset.getDataset(i)[0].getFName();
939
                return s;
940
        }
941

    
942
        /*
943
         * (non-Javadoc)
944
         * @see org.gvsig.fmap.raster.IRasterFile#getFileCount()
945
         */
946
        public int getFileCount(){
947
                return dataset.getDatasetCount();
948
        }
949

    
950
        /*
951
         * (non-Javadoc)
952
         * @see org.gvsig.fmap.raster.IRasterFile#getFileFormat()
953
         */
954
        public String getFileFormat(){
955
                String fName = dataset.getDataset(0)[0].getFName();
956
                int index = fName.lastIndexOf(".") + 1;
957
                String ext = null;
958
                if (index > 0)
959
                        ext = fName.substring(fName.lastIndexOf(".") + 1, fName.length());
960
                return ext;
961
        }
962

    
963
        /*
964
         * (non-Javadoc)
965
         * @see org.gvsig.fmap.raster.IRasterOperations#getBandCount()
966
         */
967
        public int getBandCount(){
968
                return dataset.getBandCount();
969
        }
970

    
971
        /*
972
         * (non-Javadoc)
973
         * @see org.gvsig.fmap.raster.IRasterOperations#getDatatype()
974
         */
975
        public int[] getDataType(){
976
                return dataset.getDataType();
977
        }
978

    
979
        /*
980
         * (non-Javadoc)
981
         * @see org.gvsig.fmap.raster.IRasterRendering#getRenderTransparency()
982
         */
983
        public GridTransparency getRenderTransparency(){
984
                return getRender().getLastTransparency();
985
        }
986

    
987
        /*
988
         * (non-Javadoc)
989
         * @see org.gvsig.raster.hierarchy.IRasterDataset#getDataSource()
990
         */
991
        public IRasterDataSource getDataSource() {
992
                return dataset;
993
        }
994

    
995
        /*
996
         * (non-Javadoc)
997
         * @see org.gvsig.fmap.raster.IRasterDataset#addFile(java.lang.String)
998
         */
999
        public void addFile(String fileName) throws NotSupportedExtensionException, RasterDriverException{
1000
                if (getRender() != null)
1001
                        bufferFactory.addFile(RasterDataset.open(getProjection(), fileName));
1002
        }
1003

    
1004
        /*
1005
         * (non-Javadoc)
1006
         * @see org.gvsig.fmap.raster.IRasterDataset#delFile(java.lang.String)
1007
         */
1008
        public void delFile(String fileName) {
1009
                if (getRender() != null)
1010
                        bufferFactory.removeFile(fileName);
1011
        }
1012

    
1013
        /*
1014
         * (non-Javadoc)
1015
         * @see org.gvsig.fmap.raster.IRasterDataset#getInfo(java.lang.String)
1016
         */
1017
        public Object getInfo(String key) {
1018
                if (key.equals("DriverName"))
1019
                        return "gvSIG Raster Driver";
1020
                return null;
1021
        }
1022

    
1023
        /*
1024
         * (non-Javadoc)
1025
         * @see org.gvsig.fmap.raster.IRasterRendering#getRenderFilterList()
1026
         */
1027
        public RasterFilterList getRenderFilterList(){
1028
                return getRender().getFilterList();
1029
        }
1030

    
1031
        /*
1032
         * (non-Javadoc)
1033
         * @see org.gvsig.raster.shared.IRasterOperations#getMetadata()
1034
         */
1035
        public DatasetMetadata[] getMetadata() {
1036
                int count = dataset.getDatasetCount();
1037
                DatasetMetadata[] metadata = new DatasetMetadata[count];
1038
                for (int i = 0; i < count; i++) {
1039
                        metadata[i] = dataset.getDataset(i)[0].getMetadata();
1040
                }
1041
                return metadata;
1042
        }
1043

    
1044
        /*
1045
         * (non-Javadoc)
1046
         * @see org.gvsig.raster.shared.IRasterOperations#getBandCountFromDataset()
1047
         */
1048
        public int[] getBandCountFromDataset() {
1049
                int count = dataset.getDatasetCount();
1050
                int[] bands = new int[count];
1051
                for (int i = 0; i < count; i++) {
1052
                        bands[i] = dataset.getDataset(i)[0].getBandCount();
1053
                }
1054
                return bands;
1055
        }
1056

    
1057
        /*
1058
         * (non-Javadoc)
1059
         * @see org.gvsig.raster.shared.IRasterOperations#getColourInterpretation(int, int)
1060
         */
1061
        public String getColourInterpretation(int band, int dataset) {
1062
                if (this.dataset.getColorInterpretation(dataset) == null)
1063
                        return "Undefined";
1064
                return this.dataset.getColorInterpretation(dataset).get(band);
1065
        }
1066

    
1067
        /*
1068
         * (non-Javadoc)
1069
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getStringProjection()
1070
         */
1071
        public String getWktProjection() throws RasterDriverException {
1072
                try {
1073
                        return dataset.getWktProjection();
1074
                } catch (RasterDriverException e) {
1075
                        throw new RasterDriverException("No puedo obtener la proyecci?n asociada al dataset.", e);
1076
                }
1077
        }
1078

    
1079
        /**
1080
         * Obtiene el grid de la capa completa. Hay que tener cuidado porque cuando se hace esta
1081
         * petici?n se carga un buffer con todos los datos de la capa. Este buffer puede ser
1082
         * cacheado o no dependiendo del tama?o de esta.
1083
         * @param interpolated true si se solicita un grid interpolado y false si se solicita sin interpolar.
1084
         * @return Grid.
1085
         * @throws InterruptedException 
1086
         */
1087
        public Grid getFullGrid(boolean interpolated) throws InterruptedException {
1088
                BufferFactory bf = getBufferFactory();
1089
                bf.clearDrawableBand();
1090
                bf.setAllDrawableBands();
1091
                bf.setAreaOfInterest();
1092
                return new Grid(bf, interpolated);
1093
        }
1094

    
1095
        /*
1096
         * (non-Javadoc)
1097
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getFullRasterExtent()
1098
         */
1099
        public Extent getFullRasterExtent() {
1100
                return this.getDataSource().getExtent();
1101
        }
1102

    
1103

    
1104
        /**
1105
         * Devuelve el fichero asociado a la capa o null si no tiene.
1106
         * @return Fichero.
1107
         */
1108
        public File getFile() {
1109
                /*if(params instanceof File)
1110
                        return new File[][]{{((File)params)}};
1111
                else if (params instanceof String[][]) {
1112
                        String[][] fileList = (String[][])params;
1113
                        File[][] files = new File[fileList.length][fileList[0].length];
1114
                        for (int i = 0; i < fileList.length; i++) 
1115
                                for (int j = 0; j < fileList[i].length; j++)
1116
                                        files[i][j] = new File(fileList[i][j]);
1117
                        return files;
1118
                }
1119
                return null;*/
1120
                return (params instanceof File) ? ((File)params) : null;
1121
        }
1122

    
1123
        /**
1124
         * Consulta si un fichero es aceptado o no para este tipo de capa.
1125
         * @param file Fichero a consultar
1126
         * @return true si es aceptado y false si no lo es.
1127
         */
1128
        public static boolean isFileAccepted(File file) {
1129
                return RasterDataset.fileIsSupported(file.getName());
1130
        }
1131

    
1132
        /*
1133
         * (non-Javadoc)
1134
         * @see org.gvsig.raster.shared.IRasterRendering#existColorTable()
1135
         */
1136
        public boolean existColorTable() {
1137
                return getRender().existColorTable();
1138
        }
1139

    
1140
        ILegend lastLegend = null;
1141
        /**
1142
         * Define la ultima leyenda valida de la capa o se pone a null para que la
1143
         * capa busque una leyenda valida.
1144
         * @param ct
1145
         */
1146
        public void setLastLegend(ColorTable ct) {
1147
                lastLegend = ColorTableLegend.createLegend(ct);
1148
        }
1149

    
1150
        /**
1151
         * Devuelve la Leyenda de la capa.
1152
         * @return Leyenda.
1153
         */
1154
        public ILegend getLegend() {
1155
                if (lastLegend != null)
1156
                        return lastLegend;
1157

    
1158
                ColorTable ct = null;
1159
                if(getRenderFilterList() == null)
1160
                        return null;
1161
                
1162
                ColorTableFilter colorTableFilter = (ColorTableFilter) getRenderFilterList().getByName(ColorTableFilter.names[0]);
1163
                if (colorTableFilter != null) {
1164
                        ColorTable ct2 = new GridPalette((ColorTable) colorTableFilter.getColorTable());
1165
                        if (ct2.getColorItems() != null)
1166
                                ct = ct2;
1167
                }
1168
                if (ct == null)
1169
                        ct = this.getDataSource().getColorTables()[0];
1170

    
1171
                return ColorTableLegend.createLegend(ct);
1172
        }
1173

    
1174
        /*
1175
         * (non-Javadoc)
1176
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#addLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
1177
         */
1178
        public void addLegendListener(LegendListener listener) {
1179
                layerChangeSupport.addLayerListener(listener);
1180
        }
1181

    
1182
        /*
1183
         *  (non-Javadoc)
1184
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
1185
         */
1186
        public int getShapeType() throws ReadDriverException {
1187
                return FShape.POLYGON;
1188
        }
1189

    
1190
        /*
1191
         * (non-Javadoc)
1192
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
1193
         */
1194
        public void removeLegendListener(LegendListener listener) {
1195
                layerChangeSupport.removeLayerListener(listener);
1196
        }
1197

    
1198
        /**
1199
         * Metodo que obtiene si un punto cae dentro de los l?mites de la capa
1200
         * o fuera de ellos.
1201
         * @param p Punto a calcular
1202
         * @return true si est? dentro de los l?mites y false si est? fuera
1203
         */
1204
        public boolean isInside(Point2D p) {
1205
                 return getDataSource().isInside(p);
1206
        }
1207

    
1208
        /**
1209
         * Recupera del raster la matriz de transformaci?n que lo situa en cualquier parte de la vista
1210
         * @return AffineTransform
1211
         */
1212
        public AffineTransform getAffineTransform() {
1213
                return getDataSource().getAffineTransform();
1214
        }
1215

    
1216
        /**
1217
         * Asigna al raster la matriz de transformaci?n para situarlo en cualquier parte de la vista
1218
         * @param transf
1219
         */
1220
        public void setAffineTransform(AffineTransform transf) {
1221
                affineTransformList.add(transf);
1222
                getDataSource().setAffineTransform(transf);
1223
        }
1224
        
1225
        /**
1226
         * Asigna al raster la matriz de transformaci?n para situarlo en cualquier parte de la vista.
1227
         * Esta versi?n no guarda en el historico.
1228
         * @param transf
1229
         */
1230
        public void setAT(AffineTransform transf) {
1231
                getDataSource().setAffineTransform(transf);
1232
        }
1233
        
1234
        /**
1235
         * Obtiene la lista de transformaciones que se han ido aplicando al raster.
1236
         * @return Historical. Lista de AffineTransform
1237
         */
1238
        public Historical getAffineTransformHistorical() {
1239
                return this.affineTransformList;
1240
        }
1241
        
1242
        /**
1243
         * Salva la georreferenciaci?n a fichero rmf.
1244
         * @param fName
1245
         * @throws IOException  
1246
         */
1247
        public void saveGeoToRmf() throws IOException {
1248
                getDataSource().saveGeoToRmf();
1249
                affineTransformList.clear();
1250
                affineTransformList.add(this.getAffineTransform());
1251
        }
1252

    
1253
        /*
1254
         * (non-Javadoc)
1255
         * @see org.gvsig.fmap.raster.layers.IRasterLayerActions#isActionEnabled(int)
1256
         */
1257
        public boolean isActionEnabled(int action) {
1258
                switch (action) {
1259
                        case IRasterLayerActions.PROPERTIES_BANDS_FILE_LIST:
1260
                                if (existColorTable())
1261
                                        return false;
1262
                        case IRasterLayerActions.PROPERTIES_BANDS_RGB:
1263
                                if (existColorTable())
1264
                                        return false;
1265
                        case IRasterLayerActions.PROPERTIES_OPACITY:
1266
                        case IRasterLayerActions.PROPERTIES_TRANSPARENCY:
1267
                        case IRasterLayerActions.PROPERTIES_BRIGHTNESSCONTRAST:
1268
                        case IRasterLayerActions.PROPERTIES_ENHANCED:
1269
                        case IRasterLayerActions.PROPERTIES_PANSHARPENING:
1270
                                return true;
1271
                }
1272
                return true;
1273
        }
1274
}