Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / fmap / raster / layers / FLyrRasterSE.java @ 13594

History | View | Annotate | Download (38.8 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.XMLEntity;
94
import com.iver.utiles.swing.threads.Cancellable;
95
/**
96
 * Capa raster
97
 * @author Nacho Brodin (nachobrodin@gmail.com)
98
 */
99
public class FLyrRasterSE extends FLyrDefault
100
        implements IRasterProperties, IRasterDataset, InfoByPoint, Classifiable, IRasterOperations, IRasterLayerActions {
101
        public static double          noDataDefault      = -99999;
102
        boolean                       isPrinting         = false;
103
        boolean                       mustTileDraw       = false;
104
        boolean                       mustTilePrint      = true;
105
        private int                   maxTileDrawWidth   = 200;
106
        private int                   maxTileDrawHeight  = 200;
107
        int                           maxTilePrintWidth  = 1500;
108
        int                           maxTilePrintHeight = 1500;
109
        private StatusRasterInterface status             = null;
110
        private boolean               firstLoad          = false;
111
        private boolean               removeRasterFlag   = true;
112
        private Object                params             = null;
113
        protected IRasterDataSource   dataset            = null;
114
        protected Rendering           render             = null;
115
        protected BufferFactory       bufferFactory      = null;
116
        private int                   posX               = 0;
117
        private int                   posY               = 0;
118
        private double                posXWC             = 0;
119
        private int                   posYWC             = 0;
120
        private int                   r                  = 0;
121
        private int                   g                  = 0;
122
        private int                   b                  = 0;
123
        private LayerChangeSupport    layerChangeSupport = new LayerChangeSupport();
124
        public double                 noDataValue        = -99999;
125
        
126
        /**
127
         * Lista de transformaciones afines que son aplicadas. Esta lista es simplemente un
128
         * historico que no se utiliza. Es posible utilizarlo para recuperar transformaciones
129
         * anteriores.
130
         */
131
        private Historical            affineTransformList = new Historical();
132
        
133
        static {
134
                 RasterLibrary.wakeUp();
135
        }
136

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

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

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

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

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

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

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

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

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

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

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

    
276
                filterList.setInitDataType(getDataType()[0]);
277
                RasterFilterListManager filterManager = new RasterFilterListManager(filterList);
278

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

    
291
                getRender().setFilterList(filterList);
292
        }
293

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

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

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

    
375
                        if (getVirtualLayers() != null) {
376
                                getVirtualLayers().draw(image, g, vp, cancel, scale);
377
                        }
378
                }
379
        }
380

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

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

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

    
404
        }
405

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

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

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

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

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

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

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

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

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

    
505
                data += "</file:" + normalizeAsXMLTag(getName()) + ">\n";
506
                return data;
507
        }
508

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

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

    
532
                StringXMLItem[] item = new StringXMLItem[1];
533
                String data = "<file:" + normalizeAsXMLTag(getName()) + ">\n";
534

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

    
570
                item[0] = new StringXMLItem(data, this);
571
                return item;
572
        }
573

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

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

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

    
612
                // Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
613
                if (status == null)
614
                        status = new StatusLayerRaster();
615
                status.getXMLEntity(xml, true, this);
616

    
617
                return xml;
618
        }
619

    
620
        public void setXMLEntity03(XMLEntity xml) throws XMLException {
621
        }
622

    
623
        /**
624
         * Recupera de disco los datos de la capa.
625
         */
626
        public void setXMLEntity(XMLEntity xml)throws XMLException {
627
                super.setXMLEntity(xml);
628

    
629
                params = new File(xml.getStringProperty("file"));
630

    
631
                // Para notificar al adapter-driver cual es la proyecci?n.
632
                setProjection(super.getProjection());
633

    
634
                //Inicializamos la clase a la que se usa por defecto para
635
                //compatibilidad con proyectos antiguos
636
                String claseStr = StatusLayerRaster.defaultClass;
637
                if (xml.contains("raster.class"))
638
                        claseStr = xml.getStringProperty("raster.class");
639

    
640
                if (status != null)
641
                        status.setXMLEntity(xml, this);
642
                else {
643
                        // Cuando cargamos un proyecto
644

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

    
667
        }
668

    
669
        /* (non-Javadoc)
670
         * @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)
671
         */
672
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet propeties) throws ReadDriverException {
673

    
674
                if (!isVisible() || !isWithinScale(scale))
675
                        return;
676

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

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

    
691
                        //RasterStats stats = getSource().getFilterStack().getStats();
692
                        //if(stats != null)
693
                        //stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue));
694

    
695

    
696
                        for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) {
697
                                // Parte que dibuja
698
                                try {
699
                                        ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
700
                                        draw(null, g, vp, cancel, scale);
701
                                } catch (NoninvertibleTransformException e) {
702
                                        throw new ReadDriverException("Error en la transformaci?n.", e);
703
                                }
704
                        }
705
                        /*if(stats != null){
706
                                getSource().getFilterStack().getStats().history.clear();
707
                                stats = getSource().getFilterStack().getStats();
708
                        }*/
709
                }
710
                isPrinting = false;
711
        }
712

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

    
719
                int numW, numH;
720
                int stepX, stepY;
721
                int xProv, yProv;
722
                int A = 1500;
723
                int H = 1500;
724
                int altoAux, anchoAux;
725

    
726
                AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone();
727

    
728
                // Vamos a hacerlo en trozos de AxH
729
                Rectangle r = g.getClipBounds();
730
                numW = (int) (r.width) / A;
731
                numH = (int) (r.height) / H;
732

    
733
                double[] srcPts = new double[8];
734
                double[] dstPts = new double[8];
735

    
736
                yProv = (int) r.y;
737
                for (stepY = 0; stepY < numH + 1; stepY++) {
738
                        if ((yProv + H) > r.getMaxY())
739
                                altoAux = (int) r.getMaxY() - yProv;
740
                        else
741
                                altoAux = H;
742

    
743
                        xProv = (int) r.x;
744
                        for (stepX = 0; stepX < numW + 1; stepX++) {
745
                                if ((xProv + A) > r.getMaxX())
746
                                        anchoAux = (int) r.getMaxX() - xProv;
747
                                else
748
                                        anchoAux = A;
749

    
750
                                //Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux);
751

    
752
                                // Parte que dibuja
753
                                srcPts[0] = xProv;
754
                                srcPts[1] = yProv;
755
                                srcPts[2] = xProv + anchoAux + 1;
756
                                srcPts[3] = yProv;
757
                                srcPts[4] = xProv + anchoAux + 1;
758
                                srcPts[5] = yProv + altoAux + 1;
759
                                srcPts[6] = xProv;
760
                                srcPts[7] = yProv + altoAux + 1;
761

    
762
                                try {
763
                                        mat.inverseTransform(srcPts, 0, dstPts, 0, 4);
764
                                        Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(dstPts[0], dstPts[1], dstPts[2] - dstPts[0], dstPts[5] - dstPts[3]);
765
                                        // Extent extent = new Extent(rectCuadricula);
766

    
767
                                        Dimension tam = new Dimension(anchoAux + 1, altoAux + 1);
768
                                        ViewPort vp = viewPort.cloneViewPort();
769
                                        vp.setImageSize(tam);
770
                                        vp.setExtent(rectCuadricula);
771
                                        vp.setAffineTransform(mat);
772
                                        draw(null, g, vp, cancel, scale);
773

    
774
                                } catch (NoninvertibleTransformException e) {
775
                                        throw new ReadDriverException("Error en la transformaci?n.", e);
776
                                }
777
                                // Fin parte que dibuja
778
                                xProv = xProv + A;
779
                        }
780
                        yProv = yProv + H;
781
                }
782
        }
783

    
784
        /**
785
         * Borra de la lista de listeners el que se pasa como par?metro.
786
         *
787
         * @param o LayerListener a borrar.
788
         *
789
         * @return True si ha sido correcto el borrado del Listener.
790
         */
791
        public boolean removeLayerListener(LayerListener o) {
792
                //Salva a RMF
793
                try {
794
                        if(this.getDataSource() != null)
795
                                this.getDataSource().saveRmfModification();
796
                } catch (IOException e) {
797
                        //No se ha salvado nada
798
                }
799

    
800
                if (this.isRemoveRasterFlag()) {
801
                        dataset.close();
802
                        this.setRemoveRasterFlag(true);
803
                }
804
                return super.layerListeners.remove(o);
805
        }
806

    
807
        /**
808
         * @return Returns the removeRasterFlag.
809
         */
810
        public boolean isRemoveRasterFlag() {
811
                return removeRasterFlag;
812
        }
813

    
814
        /**
815
         * Asigna el valor del flag que dice si destruimos la memoria del raster
816
         * al eliminarlo del TOC o  no.
817
         * @param removeRasterFlag The removeRasterFlag to set.
818
         */
819
        public void setRemoveRasterFlag(boolean removeRasterFlag) {
820
                this.removeRasterFlag = removeRasterFlag;
821
        }
822

    
823
        public ImageIcon getTocImageIcon() {
824
                return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG"));
825
        }
826

    
827
        /*
828
         *  (non-Javadoc)
829
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
830
         */
831
        public int[] getTileSize() {
832
                int[] size = {maxTileDrawWidth, maxTileDrawHeight};
833
                return size;
834
        }
835

    
836
        /*
837
         *  (non-Javadoc)
838
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
839
         */
840
        public boolean isTiled() {
841
                return mustTileDraw;
842
        }
843

    
844
        /**
845
         * Obtiene el flag que dice si la imagen est? o no georreferenciada
846
         * @return true si est? georreferenciada y false si no lo est?.
847
         */
848
        public boolean isGeoreferenced() {
849
                return dataset.isGeoreferenced();
850
        }
851

    
852
        /**
853
         * Get datasource object
854
         * @return
855
         */
856
        public BufferFactory getBufferFactory(){
857
                return bufferFactory;
858
        }
859

    
860
        /**
861
         * Asigna el valor noData asociado a la capa
862
         * @return double que representa el valor noData asociado a la capa
863
         */
864
        public double getNoDataValue() {
865
                return noDataValue;
866
        }
867

    
868
        /**
869
         * Asigna el valor no data asociado a la capa
870
         * @param nd
871
         */
872
        public void setNoDataValue(double nd){
873
                if (bufferFactory != null)
874
                        bufferFactory.setNoDataValue(nd);
875
                noDataValue = nd;
876
        }
877

    
878
        /*
879
         * (non-Javadoc)
880
         * @see org.gvsig.fmap.raster.IRasterOperations#getPXHeight()
881
         */
882
        public double getPxHeight() {
883
                return dataset.getHeight();
884
        }
885

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

    
894
        /*
895
         * (non-Javadoc)
896
         * @see org.gvsig.fmap.raster.IGeoDimension#getWCHeight()
897
         */
898
        public double getWCHeight() {
899
                return getFullExtent().getHeight();
900
        }
901

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

    
910
        /*
911
         * (non-Javadoc)
912
         * @see org.gvsig.fmap.raster.IRasterFile#getFileSize()
913
         */
914
        public long[] getFileSize(){
915
                int nFiles = dataset.getDatasetCount();
916
                long[] s = new long[nFiles];
917
                for (int i = 0; i < nFiles; i++)
918
                        s[i] = dataset.getFileSize();
919
                return s;
920
        }
921

    
922
        /*
923
         * (non-Javadoc)
924
         * @see org.gvsig.fmap.raster.IRasterFile#getFileName()
925
         */
926
        public String[] getFileName(){
927
                int nFiles = dataset.getDatasetCount();
928
                String[] s = new String[nFiles];
929
                for (int i = 0; i < nFiles; i++)
930
                        s[i] = dataset.getDataset(i)[0].getFName();
931
                return s;
932
        }
933

    
934
        /*
935
         * (non-Javadoc)
936
         * @see org.gvsig.fmap.raster.IRasterFile#getFileCount()
937
         */
938
        public int getFileCount(){
939
                return dataset.getDatasetCount();
940
        }
941

    
942
        /*
943
         * (non-Javadoc)
944
         * @see org.gvsig.fmap.raster.IRasterFile#getFileFormat()
945
         */
946
        public String getFileFormat(){
947
                String fName = dataset.getDataset(0)[0].getFName();
948
                int index = fName.lastIndexOf(".") + 1;
949
                String ext = null;
950
                if (index > 0)
951
                        ext = fName.substring(fName.lastIndexOf(".") + 1, fName.length());
952
                return ext;
953
        }
954

    
955
        /*
956
         * (non-Javadoc)
957
         * @see org.gvsig.fmap.raster.IRasterOperations#getBandCount()
958
         */
959
        public int getBandCount(){
960
                return dataset.getBandCount();
961
        }
962

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

    
971
        /*
972
         * (non-Javadoc)
973
         * @see org.gvsig.fmap.raster.IRasterRendering#getRenderTransparency()
974
         */
975
        public GridTransparency getRenderTransparency(){
976
                return getRender().getLastTransparency();
977
        }
978

    
979
        /*
980
         * (non-Javadoc)
981
         * @see org.gvsig.raster.hierarchy.IRasterDataset#getDataSource()
982
         */
983
        public IRasterDataSource getDataSource() {
984
                return dataset;
985
        }
986

    
987
        /*
988
         * (non-Javadoc)
989
         * @see org.gvsig.fmap.raster.IRasterDataset#addFile(java.lang.String)
990
         */
991
        public void addFile(String fileName) throws NotSupportedExtensionException, RasterDriverException{
992
                if (getRender() != null)
993
                        bufferFactory.addFile(RasterDataset.open(getProjection(), fileName));
994
        }
995

    
996
        /*
997
         * (non-Javadoc)
998
         * @see org.gvsig.fmap.raster.IRasterDataset#delFile(java.lang.String)
999
         */
1000
        public void delFile(String fileName) {
1001
                if (getRender() != null)
1002
                        bufferFactory.removeFile(fileName);
1003
        }
1004

    
1005
        /*
1006
         * (non-Javadoc)
1007
         * @see org.gvsig.fmap.raster.IRasterDataset#getInfo(java.lang.String)
1008
         */
1009
        public Object getInfo(String key) {
1010
                if (key.equals("DriverName"))
1011
                        return "gvSIG Raster Driver";
1012
                return null;
1013
        }
1014

    
1015
        /*
1016
         * (non-Javadoc)
1017
         * @see org.gvsig.fmap.raster.IRasterRendering#getRenderFilterList()
1018
         */
1019
        public RasterFilterList getRenderFilterList(){
1020
                return getRender().getFilterList();
1021
        }
1022

    
1023
        /*
1024
         * (non-Javadoc)
1025
         * @see org.gvsig.raster.shared.IRasterOperations#getMetadata()
1026
         */
1027
        public DatasetMetadata[] getMetadata() {
1028
                int count = dataset.getDatasetCount();
1029
                DatasetMetadata[] metadata = new DatasetMetadata[count];
1030
                for (int i = 0; i < count; i++) {
1031
                        metadata[i] = dataset.getDataset(i)[0].getMetadata();
1032
                }
1033
                return metadata;
1034
        }
1035

    
1036
        /*
1037
         * (non-Javadoc)
1038
         * @see org.gvsig.raster.shared.IRasterOperations#getBandCountFromDataset()
1039
         */
1040
        public int[] getBandCountFromDataset() {
1041
                int count = dataset.getDatasetCount();
1042
                int[] bands = new int[count];
1043
                for (int i = 0; i < count; i++) {
1044
                        bands[i] = dataset.getDataset(i)[0].getBandCount();
1045
                }
1046
                return bands;
1047
        }
1048

    
1049
        /*
1050
         * (non-Javadoc)
1051
         * @see org.gvsig.raster.shared.IRasterOperations#getColourInterpretation(int, int)
1052
         */
1053
        public String getColourInterpretation(int band, int dataset) {
1054
                if (this.dataset.getColorInterpretation(dataset) == null)
1055
                        return "Undefined";
1056
                return this.dataset.getColorInterpretation(dataset).get(band);
1057
        }
1058

    
1059
        /*
1060
         * (non-Javadoc)
1061
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getStringProjection()
1062
         */
1063
        public String getWktProjection() throws RasterDriverException {
1064
                try {
1065
                        return dataset.getWktProjection();
1066
                } catch (RasterDriverException e) {
1067
                        throw new RasterDriverException("No puedo obtener la proyecci?n asociada al dataset.", e);
1068
                }
1069
        }
1070

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

    
1087
        /*
1088
         * (non-Javadoc)
1089
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getFullRasterExtent()
1090
         */
1091
        public Extent getFullRasterExtent() {
1092
                return this.getDataSource().getExtent();
1093
        }
1094

    
1095

    
1096
        /**
1097
         * Devuelve el fichero asociado a la capa o null si no tiene.
1098
         * @return Fichero.
1099
         */
1100
        public File getFile() {
1101
                return (params instanceof File) ? ((File)params) : null;
1102
        }
1103

    
1104
        /**
1105
         * Consulta si un fichero es aceptado o no para este tipo de capa.
1106
         * @param file Fichero a consultar
1107
         * @return true si es aceptado y false si no lo es.
1108
         */
1109
        public static boolean isFileAccepted(File file) {
1110
                return RasterDataset.fileIsSupported(file.getName());
1111
        }
1112

    
1113
        /*
1114
         * (non-Javadoc)
1115
         * @see org.gvsig.raster.shared.IRasterRendering#existColorTable()
1116
         */
1117
        public boolean existColorTable() {
1118
                return getRender().existColorTable();
1119
        }
1120

    
1121
        ILegend lastLegend = null;
1122
        /**
1123
         * Define la ultima leyenda valida de la capa o se pone a null para que la
1124
         * capa busque una leyenda valida.
1125
         * @param ct
1126
         */
1127
        public void setLastLegend(ColorTable ct) {
1128
                lastLegend = ColorTableLegend.createLegend(ct);
1129
        }
1130

    
1131
        /**
1132
         * Devuelve la Leyenda de la capa.
1133
         * @return Leyenda.
1134
         */
1135
        public ILegend getLegend() {
1136
                if (lastLegend != null)
1137
                        return lastLegend;
1138

    
1139
                ColorTable ct = null;
1140
                if(getRenderFilterList() == null)
1141
                        return null;
1142
                
1143
                ColorTableFilter colorTableFilter = (ColorTableFilter) getRenderFilterList().getByName(ColorTableFilter.names[0]);
1144
                if (colorTableFilter != null) {
1145
                        ColorTable ct2 = new GridPalette((ColorTable) colorTableFilter.getColorTable());
1146
                        if (ct2.getColorItems() != null)
1147
                                ct = ct2;
1148
                }
1149
                if (ct == null)
1150
                        ct = this.getDataSource().getColorTables()[0];
1151

    
1152
                return ColorTableLegend.createLegend(ct);
1153
        }
1154

    
1155
        /*
1156
         * (non-Javadoc)
1157
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#addLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
1158
         */
1159
        public void addLegendListener(LegendListener listener) {
1160
                layerChangeSupport.addLayerListener(listener);
1161
        }
1162

    
1163
        /*
1164
         *  (non-Javadoc)
1165
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
1166
         */
1167
        public int getShapeType() throws ReadDriverException {
1168
                return FShape.POLYGON;
1169
        }
1170

    
1171
        /*
1172
         * (non-Javadoc)
1173
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
1174
         */
1175
        public void removeLegendListener(LegendListener listener) {
1176
                layerChangeSupport.removeLayerListener(listener);
1177
        }
1178

    
1179
        /**
1180
         * Metodo que obtiene si un punto cae dentro de los l?mites de la capa
1181
         * o fuera de ellos.
1182
         * @param p Punto a calcular
1183
         * @return true si est? dentro de los l?mites y false si est? fuera
1184
         */
1185
        public boolean isInside(Point2D p) {
1186
                 return getDataSource().isInside(p);
1187
        }
1188

    
1189
        /**
1190
         * Recupera del raster la matriz de transformaci?n que lo situa en cualquier parte de la vista
1191
         * @return AffineTransform
1192
         */
1193
        public AffineTransform getAffineTransform() {
1194
                return getDataSource().getAffineTransform();
1195
        }
1196

    
1197
        /**
1198
         * Asigna al raster la matriz de transformaci?n para situarlo en cualquier parte de la vista
1199
         * @param transf
1200
         */
1201
        public void setAffineTransform(AffineTransform transf) {
1202
                affineTransformList.add(transf);
1203
                getDataSource().setAffineTransform(transf);
1204
        }
1205
        
1206
        /**
1207
         * Asigna al raster la matriz de transformaci?n para situarlo en cualquier parte de la vista.
1208
         * Esta versi?n no guarda en el historico.
1209
         * @param transf
1210
         */
1211
        public void setAT(AffineTransform transf) {
1212
                getDataSource().setAffineTransform(transf);
1213
        }
1214
        
1215
        /**
1216
         * Obtiene la lista de transformaciones que se han ido aplicando al raster.
1217
         * @return Historical. Lista de AffineTransform
1218
         */
1219
        public Historical getAffineTransformHistorical() {
1220
                return this.affineTransformList;
1221
        }
1222
        
1223
        /**
1224
         * Salva la georreferenciaci?n a fichero rmf.
1225
         * @param fName
1226
         * @throws IOException  
1227
         */
1228
        public void saveGeoToRmf() throws IOException {
1229
                getDataSource().saveGeoToRmf();
1230
                affineTransformList.clear();
1231
                affineTransformList.add(this.getAffineTransform());
1232
        }
1233

    
1234
        /*
1235
         * (non-Javadoc)
1236
         * @see org.gvsig.fmap.raster.layers.IRasterLayerActions#isActionEnabled(int)
1237
         */
1238
        public boolean isActionEnabled(int action) {
1239
                switch (action) {
1240
                        case IRasterLayerActions.PROPERTIES_BANDS_FILE_LIST:
1241
                                if (existColorTable())
1242
                                        return false;
1243
                        case IRasterLayerActions.PROPERTIES_BANDS_RGB:
1244
                                if (existColorTable())
1245
                                        return false;
1246
                        case IRasterLayerActions.PROPERTIES_OPACITY:
1247
                                return false;
1248
                        case IRasterLayerActions.PROPERTIES_TRANSPARENCY:
1249
                                return true;
1250
                }
1251
                return true;
1252
        }
1253
}