Statistics
| Revision:

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

History | View | Annotate | Download (37.9 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.FileNotOpenException;
44
import org.gvsig.raster.dataset.IBuffer;
45
import org.gvsig.raster.dataset.IRasterDataSource;
46
import org.gvsig.raster.dataset.InvalidSetViewException;
47
import org.gvsig.raster.dataset.MultiRasterDataset;
48
import org.gvsig.raster.dataset.NotSupportedExtensionException;
49
import org.gvsig.raster.dataset.RasterDataset;
50
import org.gvsig.raster.dataset.RasterDriverException;
51
import org.gvsig.raster.dataset.properties.DatasetMetadata;
52
import org.gvsig.raster.datastruct.ColorTable;
53
import org.gvsig.raster.datastruct.Extent;
54
import org.gvsig.raster.datastruct.ViewPortData;
55
import org.gvsig.raster.grid.Grid;
56
import org.gvsig.raster.grid.GridPalette;
57
import org.gvsig.raster.grid.GridTransparency;
58
import org.gvsig.raster.grid.filter.RasterFilterList;
59
import org.gvsig.raster.grid.filter.RasterFilterListManager;
60
import org.gvsig.raster.grid.filter.bands.ColorTableFilter;
61
import org.gvsig.raster.grid.filter.bands.ColorTableListManager;
62
import org.gvsig.raster.grid.filter.enhancement.EnhancementListManager;
63
import org.gvsig.raster.grid.render.Rendering;
64
import org.gvsig.raster.hierarchy.IRasterDataset;
65
import org.gvsig.raster.hierarchy.IRasterOperations;
66
import org.gvsig.raster.hierarchy.IRasterProperties;
67
import org.gvsig.raster.hierarchy.IStatistics;
68
import org.gvsig.raster.util.Historical;
69
import org.gvsig.raster.util.MathUtils;
70

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

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

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

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

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

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

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

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

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

    
211
                        try {
212
                                if (params == null || params instanceof File)
213
                                        dataset = MultiRasterDataset.open(getProjection(), fName);
214
                                else
215
                                        dataset = MultiRasterDataset.open(getProjection(), params);
216
                        } catch (NotSupportedExtensionException e) {
217
                                throw new LoadLayerException("Formato no valido", e);
218
                        } catch (RasterDriverException e) {
219
                                throw new LoadLayerException("Formato no valido", e);
220
                        }
221
                        this.init();
222
                } else
223
                        throw new LoadLayerException("Proyecci?n no asignada", new IOException());
224
        }
225

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

    
254
        /**
255
         * Filtros a?adidos por defecto en la pila para visualizaci?n.
256
         */
257
        private void initFilters() {
258
                RasterFilterList filterList = new RasterFilterList();
259
                filterList.addParam("IStatistics", getDataSource().getStatistics());
260
                filterList.addParam("MultiRasterDataset", getDataSource());
261
                GridTransparency gridTransparency = new GridTransparency(getDataSource().getTransparencyFilesStatus());
262
                // Inicializo la transparencia tanto para el filtro como para el render
263
                filterList.addParam("Transparency", gridTransparency);
264
                getRender().setLastTransparency(gridTransparency);
265

    
266
                filterList.setInitDataType(getDataType()[0]);
267
                RasterFilterListManager filterManager = new RasterFilterListManager(filterList);
268

    
269
                if (this.getDataSource().getColorTables()[0] != null) {
270
                        GridPalette p = new GridPalette(getDataSource().getColorTables()[0]);
271
                        ColorTableListManager ctm = new ColorTableListManager(filterManager);
272
                        ctm.addColorTableFilter(p);
273
                } else {
274
                        if (getDataType()[0] != IBuffer.TYPE_BYTE) {
275
                                IStatistics stats = getDataSource().getStatistics();
276
                                EnhancementListManager elm = new EnhancementListManager(filterManager);
277
                                elm.addEnhancedFilter(false, stats, 0.0, getRender().getRenderBands());
278
                        }
279
                }
280
                System.out.println("initFilters.....");
281
                getRender().setFilterList(filterList);
282
        }
283

    
284
        /**
285
         * @throws ReadDriverException 
286
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
287
         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
288
         *                 com.iver.utiles.swing.threads.Cancellable)
289
         */
290
        public void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel, double scale) throws ReadDriverException {
291
                if (isWithinScale(scale)) {
292

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

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

    
365
                        if (getVirtualLayers() != null) {
366
                                getVirtualLayers().draw(image, g, vp, cancel, scale);
367
                        }
368
                }
369
        }
370

    
371
        private void draw(BufferedImage image, Graphics2D g, ViewPort vp, Cancellable cancel) throws ArrayIndexOutOfBoundsException, InvalidSetViewException, InterruptedException {
372
                Extent e = new Extent(vp.getAdjustedExtent());
373
                Dimension imgSz = vp.getImageSize();
374
                ViewPortData vp2 = new ViewPortData(vp.getProjection(), e, imgSz );
375
                vp2.setMat(vp.getAffineTransform());
376
                getRender().draw(g, vp2);
377
        }
378

    
379
        /**
380
         * Inserta la proyecci?n.
381
         *
382
         * @param proj Proyecci?n.
383
         */
384
        public void setProjection(IProjection proj) {
385
                super.setProjection(proj);
386
        }
387

    
388
        /*
389
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
390
         */
391
        public Rectangle2D getFullExtent(){
392
                return dataset.getExtent().toRectangle2D();
393

    
394
        }
395

    
396
        /**
397
         * Obtiene el valor del pixel del Image en la posici?n real x,y
398
         * @param x Posici?n x
399
         * @param y Posici?n y
400
         * @return valor de pixel
401
         */
402
        public int[] getPixel(double wcx, double wcy) {
403
                int[] argb = { -1, -1, -1, -1 };
404
                if (wcx <= getMaxX() && wcx >= getMinX() && wcy <= getMaxY() && wcy >= getMinY()) {
405
                        View theView = (View) PluginServices.getMDIManager().getActiveWindow();
406
                        if (theView instanceof IView) {
407
                                // BufferedImage buf = ((IView) theView).getMapControl().getImage();
408
                                Point2D p = ((IView) theView).getMapControl().getViewPort().fromMapPoint(wcx, wcy);
409
                                return getPixel((int) p.getX(), (int) p.getY());
410
                        }
411
                }
412
                return argb;
413
        }
414

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

    
439
        /*
440
         * (non-Javadoc)
441
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getMaxX()
442
         */
443
        public double getMaxX(){
444
                return this.getFullExtent().getMaxX();
445
        }
446

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

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

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

    
471
        /* (non-Javadoc)
472
         * @deprecated. See String getInfo(Point p) throws DriverException
473
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
474
         */
475
        public String queryByPoint(Point p) {
476
                String data = "<file:" + normalizeAsXMLTag(getName()) + ">\n";
477

    
478
                ArrayList attr = getAttributes();
479
                data += "  <raster\n";
480
                data += "    File=\"" + getFile() + "\"\n";
481
                for (int i = 0; i < attr.size(); i++) {
482
                        Object[] a = (Object[]) attr.get(i);
483

    
484
                        data += "    " + a[0].toString() + "=";
485
                        if (a[1].toString() instanceof String)
486
                                data += "\"" + a[1].toString() + "\"\n";
487
                        else
488
                                data += a[1].toString() + "\n";
489
                }
490
                data += "    Point=\"" + posX + " , " + posY + "\"\n";
491
                data += "    Point_WC=\"" + MathUtils.format(posXWC, 3) + " , " + MathUtils.format(posYWC, 3) + "\"\n";
492
                data += "    RGB=\"" + r + ", " + g + ", " + b + "\"\n";
493
                data += "  />\n";
494

    
495
                data += "</file:" + normalizeAsXMLTag(getName()) + ">\n";
496
                return data;
497
        }
498

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

    
501
                Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
502
                Point2D px = null;
503
                if(        pReal.getX() > this.getMinX() &&
504
                        pReal.getX() < this.getMaxX() &&
505
                        pReal.getY() > this.getMinY() &&
506
                        pReal.getY() < this.getMaxY()) {
507
                        ArrayList attr = getAttributes();
508
                        int w = 0, h = 0;
509
                        for (int i = 0; i < attr.size(); i++) {
510
                                Object[] a = (Object[]) attr.get(i);
511
                                if (a[0].toString().equals("Width"))
512
                                        w = ((Integer) a[1]).intValue();
513
                                if (a[0].toString().equals("Height"))
514
                                        h = ((Integer) a[1]).intValue();
515
                        }
516
                        px = new Point2D.Double();
517
                        px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWCWidth(),
518
                                                        ((this.getMaxY() - pReal.getY()) * h) / getWCHeight());
519
                }
520
                int[] rgb = getPixel((int) p.getX(), (int) p.getY());
521

    
522
                StringXMLItem[] item = new StringXMLItem[1];
523
                String data = "<file:" + normalizeAsXMLTag(getName()) + ">\n";
524

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

    
560
                item[0] = new StringXMLItem(data, this);
561
                return item;
562
        }
563

    
564
        /**
565
         * Filters a string for being suitable as XML Tag, erasing
566
         * all not alphabetic or numeric characters.
567
         * @param s
568
         * @return string normalized
569
         */
570
        public String normalizeAsXMLTag(String s) {
571
                return s.replaceAll("[^a-zA-Z0-9]", "");
572
        }
573

    
574
        /**
575
         * Obtiene atributos a partir de un georasterfile
576
         * @return
577
         */
578
        public ArrayList getAttributes() {
579
                ArrayList attr = new ArrayList();
580
                Object [][] a = {
581
                        {"Filename", dataset.getDataset(0)[0].getFName()},
582
                        {"Filesize", new Long(dataset.getFileSize())},
583
                        {"Width", new Integer((int)dataset.getWidth())},
584
                        {"Height", new Integer((int)dataset.getHeight())},
585
                        {"Bands", new Integer(dataset.getBandCount())}
586
                };
587
                for (int i = 0; i < a.length; i++)
588
                        attr.add(a[i]);
589
                return attr;
590
        }
591

    
592
        /**
593
         * Escribe en el proyecto la capa actual
594
         * @throws XMLException
595
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
596
         */
597
        public XMLEntity getXMLEntity() throws XMLException {
598
                XMLEntity xml = super.getXMLEntity();
599
                xml.putProperty("file", getFile());
600
                xml.putProperty("driverName", "gvSIG Raster Driver");
601

    
602
                // Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
603
                if (status == null)
604
                        status = new StatusLayerRaster();
605
                status.getXMLEntity(xml, true, this);
606

    
607
                return xml;
608
        }
609

    
610
        public void setXMLEntity03(XMLEntity xml) throws XMLException {
611
        }
612

    
613
        /**
614
         * Recupera de disco los datos de la capa.
615
         */
616
        public void setXMLEntity(XMLEntity xml)throws XMLException {
617
                super.setXMLEntity(xml);
618

    
619
                params = new File(xml.getStringProperty("file"));
620

    
621
                // Para notificar al adapter-driver cual es la proyecci?n.
622
                setProjection(super.getProjection());
623

    
624
                //Inicializamos la clase a la que se usa por defecto para
625
                //compatibilidad con proyectos antiguos
626
                String claseStr = StatusLayerRaster.defaultClass;
627
                if (xml.contains("raster.class"))
628
                        claseStr = xml.getStringProperty("raster.class");
629

    
630
                if (status != null)
631
                        status.setXMLEntity(xml, this);
632
                else {
633
                        // Cuando cargamos un proyecto
634

    
635
                        if (claseStr != null && !claseStr.equals("")) {
636
                                try {
637
                                        Class clase = Class.forName(claseStr);
638
                                        Constructor constr = clase.getConstructor(null);
639
                                        status = (StatusRasterInterface) constr.newInstance(null);
640
                                        if (status != null)
641
                                                status.setXMLEntity(xml, this);
642
                                } catch (ClassNotFoundException exc) {
643
                                        throw new XMLException("Error localizando la clase a instanciar. " + claseStr, exc);
644
                                } catch (InstantiationException exc) {
645
                                        throw new XMLException("Error instanciando " + claseStr, exc);
646
                                } catch (IllegalAccessException exc) {
647
                                        throw new XMLException("Error instanciando " + claseStr, exc);
648
                                } catch (NoSuchMethodException exc) {
649
                                        throw new XMLException("Error instanciando " + claseStr, exc);
650
                                } catch (InvocationTargetException exc) {
651
                                        throw new XMLException("Error obteniendo el constructor para la clase " + claseStr, exc);
652
                                }
653
                        }
654
                }
655
                firstLoad = true;
656

    
657
        }
658

    
659
        /* (non-Javadoc)
660
         * @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)
661
         */
662
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet propeties) throws ReadDriverException {
663

    
664
                if (!isVisible() || !isWithinScale(scale))
665
                        return;
666

    
667
                isPrinting = true;
668
                if (!mustTilePrint) {
669
                        draw(null, g, viewPort, cancel,scale);
670
                } else {
671
                        // Para no pedir imagenes demasiado grandes, vamos
672
                        // a hacer lo mismo que hace EcwFile: chunkear.
673
                        // Llamamos a drawView con cuadraditos m?s peque?os
674
                        // del BufferedImage ni caso, cuando se imprime viene con null
675
                        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds());
676
                        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
677

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

    
681
                        //RasterStats stats = getSource().getFilterStack().getStats();
682
                        //if(stats != null)
683
                        //stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue));
684

    
685

    
686
                        for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) {
687
                                // Parte que dibuja
688
                                try {
689
                                        ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
690
                                        draw(null, g, vp, cancel, scale);
691
                                } catch (NoninvertibleTransformException e) {
692
                                        throw new ReadDriverException("Error en la transformaci?n.", e);
693
                                }
694
                        }
695
                        /*if(stats != null){
696
                                getSource().getFilterStack().getStats().history.clear();
697
                                stats = getSource().getFilterStack().getStats();
698
                        }*/
699
                }
700
                isPrinting = false;
701
        }
702

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

    
709
                int numW, numH;
710
                int stepX, stepY;
711
                int xProv, yProv;
712
                int A = 1500;
713
                int H = 1500;
714
                int altoAux, anchoAux;
715

    
716
                AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone();
717

    
718
                // Vamos a hacerlo en trozos de AxH
719
                Rectangle r = g.getClipBounds();
720
                numW = (int) (r.width) / A;
721
                numH = (int) (r.height) / H;
722

    
723
                double[] srcPts = new double[8];
724
                double[] dstPts = new double[8];
725

    
726
                yProv = (int) r.y;
727
                for (stepY = 0; stepY < numH + 1; stepY++) {
728
                        if ((yProv + H) > r.getMaxY())
729
                                altoAux = (int) r.getMaxY() - yProv;
730
                        else
731
                                altoAux = H;
732

    
733
                        xProv = (int) r.x;
734
                        for (stepX = 0; stepX < numW + 1; stepX++) {
735
                                if ((xProv + A) > r.getMaxX())
736
                                        anchoAux = (int) r.getMaxX() - xProv;
737
                                else
738
                                        anchoAux = A;
739

    
740
                                //Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux);
741

    
742
                                // Parte que dibuja
743
                                srcPts[0] = xProv;
744
                                srcPts[1] = yProv;
745
                                srcPts[2] = xProv + anchoAux + 1;
746
                                srcPts[3] = yProv;
747
                                srcPts[4] = xProv + anchoAux + 1;
748
                                srcPts[5] = yProv + altoAux + 1;
749
                                srcPts[6] = xProv;
750
                                srcPts[7] = yProv + altoAux + 1;
751

    
752
                                try {
753
                                        mat.inverseTransform(srcPts, 0, dstPts, 0, 4);
754
                                        Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(dstPts[0], dstPts[1], dstPts[2] - dstPts[0], dstPts[5] - dstPts[3]);
755
                                        // Extent extent = new Extent(rectCuadricula);
756

    
757
                                        Dimension tam = new Dimension(anchoAux + 1, altoAux + 1);
758
                                        ViewPort vp = viewPort.cloneViewPort();
759
                                        vp.setImageSize(tam);
760
                                        vp.setExtent(rectCuadricula);
761
                                        vp.setAffineTransform(mat);
762
                                        draw(null, g, vp, cancel, scale);
763

    
764
                                } catch (NoninvertibleTransformException e) {
765
                                        throw new ReadDriverException("Error en la transformaci?n.", e);
766
                                }
767
                                // Fin parte que dibuja
768
                                xProv = xProv + A;
769
                        }
770
                        yProv = yProv + H;
771
                }
772
        }
773

    
774
        /**
775
         * Borra de la lista de listeners el que se pasa como par?metro.
776
         *
777
         * @param o LayerListener a borrar.
778
         *
779
         * @return True si ha sido correcto el borrado del Listener.
780
         */
781
        public boolean removeLayerListener(LayerListener o) {
782
                //Salva a RMF
783
                try {
784
                        if(this.getDataSource() != null)
785
                                this.getDataSource().saveRmfModification();
786
                } catch (IOException e) {
787
                        //No se ha salvado nada
788
                }
789

    
790
                if (this.isRemoveRasterFlag()) {
791
                        dataset.close();
792
                        this.setRemoveRasterFlag(true);
793
                }
794
                return super.layerListeners.remove(o);
795
        }
796

    
797
        /**
798
         * @return Returns the removeRasterFlag.
799
         */
800
        public boolean isRemoveRasterFlag() {
801
                return removeRasterFlag;
802
        }
803

    
804
        /**
805
         * Asigna el valor del flag que dice si destruimos la memoria del raster
806
         * al eliminarlo del TOC o  no.
807
         * @param removeRasterFlag The removeRasterFlag to set.
808
         */
809
        public void setRemoveRasterFlag(boolean removeRasterFlag) {
810
                this.removeRasterFlag = removeRasterFlag;
811
        }
812

    
813
        public ImageIcon getTocImageIcon() {
814
                return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG"));
815
        }
816

    
817
        /*
818
         *  (non-Javadoc)
819
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
820
         */
821
        public int[] getTileSize() {
822
                int[] size = {maxTileDrawWidth, maxTileDrawHeight};
823
                return size;
824
        }
825

    
826
        /*
827
         *  (non-Javadoc)
828
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
829
         */
830
        public boolean isTiled() {
831
                return mustTileDraw;
832
        }
833

    
834
        /**
835
         * Obtiene el flag que dice si la imagen est? o no georreferenciada
836
         * @return true si est? georreferenciada y false si no lo est?.
837
         */
838
        public boolean isGeoreferenced() {
839
                return dataset.isGeoreferenced();
840
        }
841

    
842
        /**
843
         * Get datasource object
844
         * @return
845
         */
846
        public BufferFactory getBufferFactory(){
847
                return bufferFactory;
848
        }
849

    
850
        /**
851
         * Asigna el valor noData asociado a la capa
852
         * @return double que representa el valor noData asociado a la capa
853
         */
854
        public double getNoDataValue() {
855
                return noDataValue;
856
        }
857

    
858
        /**
859
         * Asigna el valor no data asociado a la capa
860
         * @param nd
861
         */
862
        public void setNoDataValue(double nd){
863
                if (bufferFactory != null)
864
                        bufferFactory.setNoDataValue(nd);
865
                noDataValue = nd;
866
        }
867

    
868
        /*
869
         * (non-Javadoc)
870
         * @see org.gvsig.fmap.raster.IRasterOperations#getPXHeight()
871
         */
872
        public double getPxHeight() {
873
                return dataset.getHeight();
874
        }
875

    
876
        /*
877
         * (non-Javadoc)
878
         * @see org.gvsig.fmap.raster.IRasterOperations#getPxWidth()
879
         */
880
        public double getPxWidth() {
881
                return dataset.getWidth();
882
        }
883

    
884
        /*
885
         * (non-Javadoc)
886
         * @see org.gvsig.fmap.raster.IGeoDimension#getWCHeight()
887
         */
888
        public double getWCHeight() {
889
                return getFullExtent().getHeight();
890
        }
891

    
892
        /*
893
         * (non-Javadoc)
894
         * @see org.gvsig.fmap.raster.IGeoDimension#getWCWidth()
895
         */
896
        public double getWCWidth() {
897
                return getFullExtent().getWidth();
898
        }
899

    
900
        /*
901
         * (non-Javadoc)
902
         * @see org.gvsig.fmap.raster.IRasterFile#getFileSize()
903
         */
904
        public long[] getFileSize(){
905
                int nFiles = dataset.getDatasetCount();
906
                long[] s = new long[nFiles];
907
                for (int i = 0; i < nFiles; i++)
908
                        s[i] = dataset.getFileSize();
909
                return s;
910
        }
911

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

    
924
        /*
925
         * (non-Javadoc)
926
         * @see org.gvsig.fmap.raster.IRasterFile#getFileCount()
927
         */
928
        public int getFileCount(){
929
                return dataset.getDatasetCount();
930
        }
931

    
932
        /*
933
         * (non-Javadoc)
934
         * @see org.gvsig.fmap.raster.IRasterFile#getFileFormat()
935
         */
936
        public String getFileFormat(){
937
                String fName = dataset.getDataset(0)[0].getFName();
938
                int index = fName.lastIndexOf(".") + 1;
939
                String ext = null;
940
                if (index > 0)
941
                        ext = fName.substring(fName.lastIndexOf(".") + 1, fName.length());
942
                return ext;
943
        }
944

    
945
        /*
946
         * (non-Javadoc)
947
         * @see org.gvsig.fmap.raster.IRasterOperations#getBandCount()
948
         */
949
        public int getBandCount(){
950
                return dataset.getBandCount();
951
        }
952

    
953
        /*
954
         * (non-Javadoc)
955
         * @see org.gvsig.fmap.raster.IRasterOperations#getDatatype()
956
         */
957
        public int[] getDataType(){
958
                return dataset.getDataType();
959
        }
960

    
961
        /*
962
         * (non-Javadoc)
963
         * @see org.gvsig.fmap.raster.IRasterRendering#getRenderTransparency()
964
         */
965
        public GridTransparency getRenderTransparency(){
966
                return getRender().getLastTransparency();
967
        }
968

    
969
        /*
970
         * (non-Javadoc)
971
         * @see org.gvsig.raster.hierarchy.IRasterDataset#getDataSource()
972
         */
973
        public IRasterDataSource getDataSource() {
974
                return dataset;
975
        }
976

    
977
        /*
978
         * (non-Javadoc)
979
         * @see org.gvsig.fmap.raster.IRasterDataset#addFile(java.lang.String)
980
         */
981
        public void addFile(String fileName) throws NotSupportedExtensionException, RasterDriverException{
982
                if (getRender() != null)
983
                        bufferFactory.addFile(RasterDataset.open(getProjection(), fileName));
984
        }
985

    
986
        /*
987
         * (non-Javadoc)
988
         * @see org.gvsig.fmap.raster.IRasterDataset#delFile(java.lang.String)
989
         */
990
        public void delFile(String fileName) {
991
                if (getRender() != null)
992
                        bufferFactory.removeFile(fileName);
993
        }
994

    
995
        /*
996
         * (non-Javadoc)
997
         * @see org.gvsig.fmap.raster.IRasterDataset#getInfo(java.lang.String)
998
         */
999
        public Object getInfo(String key) {
1000
                if (key.equals("DriverName"))
1001
                        return "gvSIG Raster Driver";
1002
                return null;
1003
        }
1004

    
1005
        /*
1006
         * (non-Javadoc)
1007
         * @see org.gvsig.fmap.raster.IRasterRendering#getRenderFilterList()
1008
         */
1009
        public RasterFilterList getRenderFilterList(){
1010
                return getRender().getFilterList();
1011
        }
1012

    
1013
        /*
1014
         * (non-Javadoc)
1015
         * @see org.gvsig.raster.shared.IRasterOperations#getMetadata()
1016
         */
1017
        public DatasetMetadata[] getMetadata() {
1018
                int count = dataset.getDatasetCount();
1019
                DatasetMetadata[] metadata = new DatasetMetadata[count];
1020
                for (int i = 0; i < count; i++) {
1021
                        metadata[i] = dataset.getDataset(i)[0].getMetadata();
1022
                }
1023
                return metadata;
1024
        }
1025

    
1026
        /*
1027
         * (non-Javadoc)
1028
         * @see org.gvsig.raster.shared.IRasterOperations#getBandCountFromDataset()
1029
         */
1030
        public int[] getBandCountFromDataset() {
1031
                int count = dataset.getDatasetCount();
1032
                int[] bands = new int[count];
1033
                for (int i = 0; i < count; i++) {
1034
                        bands[i] = dataset.getDataset(i)[0].getBandCount();
1035
                }
1036
                return bands;
1037
        }
1038

    
1039
        /*
1040
         * (non-Javadoc)
1041
         * @see org.gvsig.raster.shared.IRasterOperations#getColourInterpretation(int, int)
1042
         */
1043
        public String getColourInterpretation(int band, int dataset) {
1044
                if (this.dataset.getColorInterpretation(dataset) == null)
1045
                        return "Undefined";
1046
                return this.dataset.getColorInterpretation(dataset).get(band);
1047
        }
1048

    
1049
        /*
1050
         * (non-Javadoc)
1051
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getStringProjection()
1052
         */
1053
        public String getWktProjection() throws RasterDriverException {
1054
                try {
1055
                        return dataset.getWktProjection();
1056
                } catch (RasterDriverException e) {
1057
                        throw new RasterDriverException("No puedo obtener la proyecci?n asociada al dataset.", e);
1058
                }
1059
        }
1060

    
1061
        /**
1062
         * Obtiene el grid de la capa completa. Hay que tener cuidado porque cuando se hace esta
1063
         * petici?n se carga un buffer con todos los datos de la capa. Este buffer puede ser
1064
         * cacheado o no dependiendo del tama?o de esta.
1065
         * @param interpolated true si se solicita un grid interpolado y false si se solicita sin interpolar.
1066
         * @return Grid.
1067
         * @throws InterruptedException 
1068
         */
1069
        public Grid getFullGrid(boolean interpolated) throws InterruptedException {
1070
                BufferFactory bf = getBufferFactory();
1071
                bf.clearDrawableBand();
1072
                bf.setAllDrawableBands();
1073
                bf.setAreaOfInterest();
1074
                return new Grid(bf, interpolated);
1075
        }
1076

    
1077
        /*
1078
         * (non-Javadoc)
1079
         * @see org.gvsig.raster.shared.IRasterGeoOperations#getFullRasterExtent()
1080
         */
1081
        public Extent getFullRasterExtent() {
1082
                return this.getDataSource().getExtent();
1083
        }
1084

    
1085

    
1086
        /**
1087
         * Devuelve el fichero asociado a la capa o null si no tiene.
1088
         * @return Fichero.
1089
         */
1090
        public File getFile() {
1091
                return (params instanceof File) ? ((File)params) : null;
1092
        }
1093

    
1094
        /**
1095
         * Consulta si un fichero es aceptado o no para este tipo de capa.
1096
         * @param file Fichero a consultar
1097
         * @return true si es aceptado y false si no lo es.
1098
         */
1099
        public static boolean isFileAccepted(File file) {
1100
                return RasterDataset.fileIsSupported(file.getName());
1101
        }
1102

    
1103
        /*
1104
         * (non-Javadoc)
1105
         * @see org.gvsig.raster.shared.IRasterRendering#existColorTable()
1106
         */
1107
        public boolean existColorTable() {
1108
                return this.getRender().existColorTable();
1109
        }
1110

    
1111
        ILegend lastLegend = null;
1112
        /**
1113
         * Define la ultima leyenda valida de la capa o se pone a null para que la
1114
         * capa busque una leyenda valida.
1115
         * @param ct
1116
         */
1117
        public void setLastLegend(ColorTable ct) {
1118
                lastLegend = ColorTableLegend.createLegend(ct);
1119
        }
1120

    
1121
        /**
1122
         * Devuelve la Leyenda de la capa.
1123
         * @return Leyenda.
1124
         */
1125
        public ILegend getLegend() {
1126
                if (lastLegend != null)
1127
                        return lastLegend;
1128

    
1129
                ColorTable ct = null;
1130
                ColorTableFilter colorTableFilter = (ColorTableFilter) getRenderFilterList().getByName(ColorTableFilter.names[0]);
1131
                if (colorTableFilter != null) {
1132
                        ColorTable ct2 = new GridPalette((ColorTable) colorTableFilter.getColorTable());
1133
                        if (ct2.getColorItems() != null)
1134
                                ct = ct2;
1135
                }
1136
                if (ct == null)
1137
                        ct = this.getDataSource().getColorTables()[0];
1138

    
1139
                return ColorTableLegend.createLegend(ct);
1140
        }
1141

    
1142
        /*
1143
         * (non-Javadoc)
1144
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#addLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
1145
         */
1146
        public void addLegendListener(LegendListener listener) {
1147
                layerChangeSupport.addLayerListener(listener);
1148
        }
1149

    
1150
        /*
1151
         *  (non-Javadoc)
1152
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
1153
         */
1154
        public int getShapeType() throws ReadDriverException {
1155
                return FShape.POLYGON;
1156
        }
1157

    
1158
        /*
1159
         * (non-Javadoc)
1160
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
1161
         */
1162
        public void removeLegendListener(LegendListener listener) {
1163
                layerChangeSupport.removeLayerListener(listener);
1164
        }
1165

    
1166
        /**
1167
         * Metodo que obtiene si un punto cae dentro de los l?mites de la capa
1168
         * o fuera de ellos.
1169
         * @param p Punto a calcular
1170
         * @return true si est? dentro de los l?mites y false si est? fuera
1171
         */
1172
        public boolean isInside(Point2D p) {
1173
                 return getDataSource().isInside(p);
1174
        }
1175

    
1176
        /**
1177
         * Recupera del raster la matriz de transformaci?n que lo situa en cualquier parte de la vista
1178
         * @return AffineTransform
1179
         */
1180
        public AffineTransform getAffineTransform() {
1181
                return getDataSource().getAffineTransform();
1182
        }
1183

    
1184
        /**
1185
         * Asigna al raster la matriz de transformaci?n para situarlo en cualquier parte de la vista
1186
         * @param transf
1187
         */
1188
        public void setAffineTransform(AffineTransform transf) {
1189
                affineTransformList.add(transf);
1190
                getDataSource().setAffineTransform(transf);
1191
        }
1192
        
1193
        /**
1194
         * Asigna al raster la matriz de transformaci?n para situarlo en cualquier parte de la vista.
1195
         * Esta versi?n no guarda en el historico.
1196
         * @param transf
1197
         */
1198
        public void setAT(AffineTransform transf) {
1199
                getDataSource().setAffineTransform(transf);
1200
        }
1201
        
1202
        /**
1203
         * Obtiene la lista de transformaciones que se han ido aplicando al raster.
1204
         * @return Historical. Lista de AffineTransform
1205
         */
1206
        public Historical getAffineTransformHistorical() {
1207
                return this.affineTransformList;
1208
        }
1209
        
1210
        /**
1211
         * Salva la georreferenciaci?n a fichero rmf.
1212
         * @param fName
1213
         * @throws IOException  
1214
         */
1215
        public void saveGeoToRmf() throws IOException {
1216
                getDataSource().saveGeoToRmf();
1217
                affineTransformList.clear();
1218
                affineTransformList.add(this.getAffineTransform());
1219
        }
1220

    
1221
        /*
1222
         * (non-Javadoc)
1223
         * @see org.gvsig.fmap.raster.layers.IRasterLayerActions#isActionEnabled(int)
1224
         */
1225
        public boolean isActionEnabled(int action) {
1226
                return true;
1227
        }
1228
}