Statistics
| Revision:

root / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrRaster.java @ 7866

History | View | Annotate | Download (21.5 KB)

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

    
43
import java.awt.Dimension;
44
import java.awt.Graphics2D;
45
import java.awt.Point;
46
import java.awt.Rectangle;
47
import java.awt.geom.AffineTransform;
48
import java.awt.geom.NoninvertibleTransformException;
49
import java.awt.geom.Point2D;
50
import java.awt.geom.Rectangle2D;
51
import java.awt.image.BufferedImage;
52
import java.io.File;
53
import java.lang.reflect.Constructor;
54
import java.lang.reflect.InvocationTargetException;
55
import java.util.ArrayList;
56

    
57
import javax.swing.ImageIcon;
58

    
59
import org.cresques.cts.IProjection;
60
import org.cresques.filter.RasterFilterStack;
61
import org.cresques.filter.RasterStats;
62
import org.cresques.px.Extent;
63

    
64
import com.hardcode.driverManager.Driver;
65
import com.hardcode.driverManager.DriverLoadException;
66
import com.iver.cit.gvsig.fmap.DriverException;
67
import com.iver.cit.gvsig.fmap.MapControl;
68
import com.iver.cit.gvsig.fmap.ViewPort;
69
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
70
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver;
71
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem;
72
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem;
73
import com.iver.utiles.XMLEntity;
74
import com.iver.utiles.swing.threads.Cancellable;
75

    
76

    
77
/**
78
 * Clase b?sica de capa raster.
79
 *
80
 * @author Vicente Caballero Navarro
81
 */
82
public class FLyrRaster extends FLyrDefault implements RasterOperations {
83
        private RasterAdapter                                 source;
84
        boolean                                                         isPrinting = false;
85
        boolean                                                         mustTileDraw = false;
86
        boolean                                                         mustTilePrint = true;
87
        private int                                                        maxTileDrawWidth = 200;
88
        private int                                                 maxTileDrawHeight = 200;
89
        int                                                                 maxTilePrintWidth = 1500;
90
        int                                                                 maxTilePrintHeight = 1500;
91
        private StatusRasterInterface                status = null;
92
        private boolean                                                firstLoad = false;
93
        private int                                                 posX = 0, posY = 0;
94
        private double                                                 posXWC = 0, posYWC = 0;
95
        private int                                                 r = 0, g = 0, b = 0;
96
        private boolean                                                removeRasterFlag = true;
97
                        
98
        /**
99
         * Devuelve el RasterAdapter de la capa.
100
         *
101
         * @return RasterAdapter.
102
         */
103
        public RasterAdapter getSource() {
104
                return source;
105
        }
106

    
107
        /**
108
         *Redefine wakeUp de FLyrDefault
109
         */
110
        public void wakeUp(){
111
                /*setName(getName());
112
                setProjection(getProjection());
113
                try {
114
                        load();
115
                } catch (DriverIOException e) {
116
                        e.printStackTrace();
117
                }*/                        
118
        }
119
        
120
        /**
121
         * Inserta el RasterAdapter.
122
         *
123
         * @param ra RasterAdapter.
124
         */
125
        public void setSource(RasterAdapter ra) {
126
                source = ra;
127
        }
128

    
129
        /**
130
         * Devuelve la pila de filtros aplicada sobre  la capa raster.
131
         *
132
         * @return RasterFilterStack.
133
         */
134
        public RasterFilterStack getFilterStack(){
135
                return source.getFilterStack();
136
        }
137
        
138
        /**
139
         * Asignar el estado del raster
140
         * @param status
141
         */
142
        public void setStatus(StatusRasterInterface status){
143
                this.status = status;
144
        }
145
        
146
        /**
147
         * Asigna la pila de filtros aplicada al raster
148
         * @return
149
         */
150
        public void setFilterStack(RasterFilterStack stack){
151
                source.setFilterStack(stack);                
152
        }
153
        
154
        /**
155
         * Obtiene el estado del raster
156
         * @return
157
         */
158
        public StatusRasterInterface getStatus(){
159
                return this.status;
160
        }
161
        
162
        /**
163
         * Asigna la posici?n en la que se ha hecho click al mostrar
164
         * informaci?n del raster.
165
         * @param x        Posici?n en X
166
         * @param y        Posici?n en Y
167
         */
168
        public void setPos(int x, int y){
169
                this.posX = x;
170
                this.posY = y;
171
        }
172
        
173
        /**
174
         * Asigna la posici?n en coordenadas del mundo real en la que se ha 
175
         * hecho click al mostrar informaci?n del raster.
176
         * @param x        Posici?n en X
177
         * @param y        Posici?n en Y
178
         */
179
        public void setPosWC(double x, double y){
180
                this.posXWC = x;
181
                this.posYWC = y;
182
        }
183
        
184
        /**
185
         * Asigna RGB en la posici?n en la que se ha 
186
         * hecho click al mostrar informaci?n del raster.
187
         * @param r        valor de rojo
188
         * @param g        valor de verde
189
         * @param b        valor de azul
190
         */
191
        public void setRGB(int r, int g, int b){
192
                this.r = r;
193
                this.g = g;
194
                this.b = b;
195
        }
196
        
197
        /*
198
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
199
         */
200
        public void load() throws DriverIOException {
201
                ((RasterFileAdapter) source).start();
202
                ((RasterFileAdapter) source).setTransparency(getTransparency());
203
        }
204

    
205
        /**
206
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
207
         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
208
         *                 com.iver.utiles.swing.threads.Cancellable)
209
         */
210
        public void draw(BufferedImage image, Graphics2D g, ViewPort vp,
211
                Cancellable cancel,double scale) throws DriverException {
212
                if (isWithinScale(scale)){        
213
                try {
214
                        if(status!=null && firstLoad){
215
                                if(mustTileDraw){
216
                                        Point2D p = vp.getOffset();
217
                                        Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight());
218
                                        Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
219
                                        tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
220
                                        for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
221
                                                // drawing part
222
                                                try {
223
                                                        ViewPort vport = tiles.getTileViewPort(vp, tileNr);
224
                                                        //g.setClip(tiles.getClip(tileNr).x, tiles.getClip(tileNr).y, tiles.getClip(tileNr).width - 5, tiles.getClip(tileNr).height);
225
                                                        ((RasterFileAdapter) source).draw(image, g, vport, cancel);
226
                                                } catch (NoninvertibleTransformException e) {
227
                                                        e.printStackTrace();
228
                                                }
229
                                        }
230
                                }else
231
                                        ((RasterFileAdapter) source).draw(image, g, vp, cancel);        
232
                                status.applyStatus(this);
233
                                firstLoad = false;
234
                        }
235
                
236
                        if(mustTileDraw){
237
                                Point2D p = vp.getOffset();
238
                                Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight());
239
                                Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
240
                                tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
241
                                for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
242
                                        // drawing part
243
                                        try {
244
                                                ViewPort vport = tiles.getTileViewPort(vp, tileNr);
245
                                                ((RasterFileAdapter) source).draw(image, g, vport, cancel);
246
                                        } catch (NoninvertibleTransformException e) {
247
                                                e.printStackTrace();
248
                                        }
249
                                }
250
                        }else
251
                                ((RasterFileAdapter) source).draw(image, g, vp, cancel);
252
                                                                        
253
                } catch (DriverIOException e) {
254
                        throw new DriverException(e);
255
                }
256

    
257
                if (getVirtualLayers() != null) {
258
                        getVirtualLayers().draw(image, g, vp, cancel,scale);
259
                }
260
                }
261
        }
262

    
263
        /**
264
         * Inserta la proyecci?n.
265
         *
266
         * @param proj Proyecci?n.
267
         */
268
        public void setProjection(IProjection proj) {
269
                super.setProjection(proj);
270

    
271
                if (source != null && source.getDriver() != null && source.getDriver() instanceof GeorreferencedRasterDriver) {
272
                        GeorreferencedRasterDriver geoDrv = (GeorreferencedRasterDriver) source.getDriver();
273

    
274
                        if (geoDrv.getProjection() == null) {
275
                                geoDrv.setProjection(proj);
276
                        }
277
                }
278
        }
279
        
280
        public void setTransparency(int trans) {
281
                super.setTransparency(trans);
282
                ((RasterFileAdapter) source).setTransparency(trans);
283
                if (getMapContext() != null){
284
                        getMapContext().invalidate();
285
                }
286
        }
287

    
288
        public int getTransparency() {
289
                return ((RasterFileAdapter) source).getTransparency();
290
        }
291
        
292
        /*
293
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
294
         */
295
        public Rectangle2D getFullExtent() throws DriverException {
296
                return ((RasterFileAdapter) source).getFullExtent();
297
        }
298

    
299
        /**
300
         * Obtiene el valor del pixel del Image en la posici?n x,y
301
         * @param x Posici?n x
302
         * @param y Posici?n y
303
         * @return valor de pixel
304
         */
305
        public int[] getPixel(double wcx, double wcy){
306
                return ((RasterFileAdapter) source).getPixel(wcx, wcy);
307
        }
308
        
309
        public double getMaxX(){
310
                try {
311
                        return this.getFullExtent().getMaxX();
312
                }catch(DriverException e){
313
                        return 0D;
314
                }
315
        }
316
        
317
        public double getMaxY(){
318
                try {
319
                        return this.getFullExtent().getMaxY();
320
                }catch(DriverException e){
321
                        return 0D;
322
                }
323
        }
324
        
325
        public double getMinX(){
326
                try {
327
                        return this.getFullExtent().getMinX();
328
                }catch(DriverException e){
329
                        return 0D;
330
                }
331
        }
332
        
333
        public double getMinY(){
334
                try {
335
                        return this.getFullExtent().getMinY();
336
                }catch(DriverException e){
337
                        return 0D;
338
                }
339
        }
340
        
341
        public double getHeight(){
342
                try {
343
                        return this.getFullExtent().getHeight();
344
                }catch(DriverException e){
345
                        return 0D;
346
                }
347
        }
348
        
349
        public double getWidth(){
350
                try {
351
                        return this.getFullExtent().getWidth();
352
                }catch(DriverException e){
353
                        return 0D;
354
                }
355
        }
356

    
357
        
358
        /* (non-Javadoc)
359
         * @deprecated. See String getInfo(Point p) throws DriverException
360
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
361
         */
362
        public String queryByPoint(Point p) throws DriverException {
363
                String data = "<file:"+normalizeAsXMLTag(getName())+">\n";
364

    
365
                ArrayList attr = source.getAttributes();
366
                data += "  <raster\n";
367
                data += "    File=\""+((RasterFileAdapter) source).getFile()+"\"\n";
368
                for (int i=0; i<attr.size(); i++) {
369
                        Object [] a = (Object []) attr.get(i);
370

    
371
                        data += "    "+a[0].toString()+"=";
372
                        if (a[1].toString() instanceof String)
373
                                data += "\""+a[1].toString()+"\"\n";
374
                        else
375
                                data += a[1].toString()+"\n";
376
                }
377
                data += "    Point=\""+posX+" , "+posY+"\"\n";
378
                data += "    Point_WC=\""+posXWC+" , "+posYWC+"\"\n";
379
                data += "    RGB=\""+r+", "+g+", "+b+"\"\n";
380
                data += "  />\n";
381

    
382
                data += "</file:"+normalizeAsXMLTag(getName())+">\n";
383
                //System.out.println(data);
384
                return data;
385
        }
386
        
387
        public XMLItem[] getInfo(Point p, double tolerance) throws DriverException {
388
                
389
                Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
390
                Point2D px = null;
391
                if(        pReal.getX() > this.getMinX() && 
392
                        pReal.getX() < this.getMaxX() && 
393
                        pReal.getY() > this.getMinY() && 
394
                        pReal.getY() < this.getMaxY()){
395
                        ArrayList attr = source.getAttributes();
396
                        int w = 0, h = 0;
397
                        for (int i=0; i<attr.size(); i++) {
398
                                Object [] a = (Object []) attr.get(i);
399
                                if(a[0].toString().equals("Width"))
400
                                        w = ((Integer)a[1]).intValue();
401
                                if(a[0].toString().equals("Height"))
402
                                        h = ((Integer)a[1]).intValue();
403
                        }        
404
                        px = new Point();
405
                        px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWidth(),
406
                                                        ((this.getMaxY() - pReal.getY()) * h) / getHeight());
407
                }
408
                        
409
                int[] rgb = this.getPixel(pReal.getX(), pReal.getY());
410
                
411
                StringXMLItem[] item = new StringXMLItem[1]; 
412
                String data = "<file:"+normalizeAsXMLTag(getName())+">\n";
413

    
414
                data += "  <raster\n";
415
                data += "    View_Point=\""+p.getX()+" , "+p.getY()+"\"\n";
416
                data += "    World_Point=\""+pReal.getX()+" , "+pReal.getY()+"\"\n";
417
                if(px == null)
418
                        data += "    Pixel_Point=\"Out\"\n";
419
                else
420
                        data += "    Pixel_Point=\""+px.getX()+" , "+px.getY()+"\"\n";
421
                data += "    RGB=\""+rgb[1]+", "+rgb[2]+", "+rgb[3]+"\"\n";
422
                data += "  />\n";
423

    
424
                data += "</file:"+normalizeAsXMLTag(getName())+">\n";
425
                
426
                item[0] = new StringXMLItem(data, this); 
427
                return item;
428
                
429
        }        
430
        
431
        /**
432
         * Filters a string for being suitable as XML Tag, erasing
433
         * all not alphabetic or numeric characters.
434
         * @param s
435
         * @return string normalized
436
         */
437
        public String normalizeAsXMLTag(String s) {
438
                return s.replaceAll("[^a-zA-Z0-9]","");
439
        }
440

    
441
        /**
442
         * Obtiene atributos a partir de un georasterfile
443
         * @return
444
         */
445
        public ArrayList getAttributes() {
446
                return source.getAttributes();
447
        }
448
        
449
        /**
450
         * @throws XMLException
451
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
452
         */
453
        public XMLEntity getXMLEntity() throws XMLException {
454
                XMLEntity xml = super.getXMLEntity();
455
        
456
                if (source instanceof RasterFileAdapter) {
457
                        xml.putProperty("file", ((RasterFileAdapter) source).getFile());
458
                }
459
        
460
                xml.putProperty("driverName", getSource().getDriver().getName());
461
                
462
                //Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
463
                if(status == null)
464
                        status = new StatusLayerRaster();
465
                
466
                status.getXMLEntity(xml, true, this);
467
                
468
        
469
                return xml;
470
        }
471
        
472
        public void setXMLEntity03(XMLEntity xml)
473
        throws XMLException {
474
                super.setXMLEntity(xml);
475
                try {
476
                        Driver d = LayerFactory.getDM().getDriver(
477
                                xml.getStringProperty("driverName"));
478
                        File f = new File(xml.getStringProperty("file"));
479
                        RasterAdapter adapter = new RasterFileAdapter(f);
480
                        adapter.setDriver(d);
481
                        setSource(adapter);
482
                        // Para notificar al adapter-driver cual es la proyecci?n.
483
                        setProjection(super.getProjection());
484
                } catch (DriverLoadException e) {
485
                        throw new XMLException(e);
486
                }
487
        }
488
        
489
        public void setXMLEntity(XMLEntity xml)
490
        throws XMLException {
491
                super.setXMLEntity(xml);
492
                try {
493
                        Driver d = LayerFactory.getDM().getDriver(
494
                                xml.getStringProperty("driverName"));
495
                        File f = new File(xml.getStringProperty("file"));
496
                        RasterAdapter adapter = new RasterFileAdapter(f);
497
                        adapter.setDriver(d);
498
                        setSource(adapter);
499
                        // Para notificar al adapter-driver cual es la proyecci?n.
500
                        setProjection(super.getProjection());
501
                        
502
                        //Inicializamos la clase a la que se usa por defecto para
503
                        //compatibilidad con proyectos antiguos
504
                        String claseStr = StatusLayerRaster.defaultClass;
505
                        if (xml.contains("raster.class")) {
506
                                claseStr = xml.getStringProperty("raster.class");
507
                        }
508
                        if(status!=null)
509
                                status.setXMLEntity(xml, this);
510
                        else{
511
                                
512
                                //Cuando cargamos un proyecto 
513
                                
514
                                if(claseStr!=null && !claseStr.equals("")){
515
                                        try{
516
                                                Class clase = Class.forName(claseStr);
517
                                                Constructor constr = clase.getConstructor(null);
518
                                                status = (StatusRasterInterface)constr.newInstance(null);
519
                                                if(status!=null)
520
                                                        status.setXMLEntity(xml, this);
521
                                        }catch(ClassNotFoundException exc){
522
                                                exc.printStackTrace();
523
                                        }catch(InstantiationException exc){
524
                                                exc.printStackTrace();
525
                                        }catch(IllegalAccessException exc){
526
                                                exc.printStackTrace();
527
                                        }catch(NoSuchMethodException exc){
528
                                                exc.printStackTrace();
529
                                        }catch(InvocationTargetException exc){
530
                                                exc.printStackTrace();
531
                                        }                                        
532
                                }
533
                        }
534
                        firstLoad = true;
535
                        
536
                        
537
                } catch (DriverLoadException e) {
538
                        throw new XMLException(e);
539
                }
540
        }
541

    
542
        /* (non-Javadoc)
543
         * @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)
544
         */
545
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
546
                throws DriverException {
547
                
548
                if (isVisible() && isWithinScale(scale)){        
549
                isPrinting = true;
550
                if (!mustTilePrint) {
551
                        draw(null, g, viewPort, cancel,scale);
552
                } else {
553
                // Para no pedir imagenes demasiado grandes, vamos
554
                // a hacer lo mismo que hace EcwFile: chunkear.
555
                // Llamamos a drawView con cuadraditos m?s peque?os
556
                // del BufferedImage ni caso, cuando se imprime viene con null
557
                        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipRect());
558
                        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
559
                        
560
                        //Si es la primera lectura salvamos los valores de m?ximo y m?nimo para la aplicaci?n
561
                        //de realce si la imagen es de 16 bits.
562
                        
563
                        RasterStats stats = getSource().getFilterStack().getStats();
564
                        if(stats != null)
565
                                stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue));        
566
                                        
567
                        
568
                        for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
569
                            // Parte que dibuja
570
                            try {
571
                                ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
572
                                draw(null, g, vp, cancel,scale);
573
                                } catch (NoninvertibleTransformException e) {
574
                                        // TODO Auto-generated catch block
575
                                        e.printStackTrace();
576
                                }
577
                }
578
                        
579
                        if(stats != null){
580
                                getSource().getFilterStack().getStats().history.clear();
581
                                stats = getSource().getFilterStack().getStats();
582
                        }
583
                                                
584
                }
585
            isPrinting = false;
586
                }
587
        }
588

    
589
        public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
590
                throws DriverException {                
591
                // Para no pedir imagenes demasiado grandes, vamos
592
                // a hacer lo mismo que hace EcwFile: chunkear.
593
                // Llamamos a drawView con cuadraditos m?s peque?os
594
                // del BufferedImage ni caso, cuando se imprime viene con null
595
                
596
                int numW, numH;
597
                int stepX, stepY;
598
                int xProv, yProv, wProv, hProv;
599
                double xProvD, yProvD, wProvD, hProvD;
600
                int A = 1500; 
601
                int H = 1500;
602
                int altoAux, anchoAux;
603
                
604
                AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone();
605
                
606
                // Vamos a hacerlo en trozos de AxH
607
                Rectangle r = g.getClipRect();
608
                numW = (int) (r.width) / A;
609
                numH = (int) (r.height) / H;                
610
                
611
                
612
                double[] srcPts = new double[8];
613
                double[] dstPts= new double[8];
614

    
615
                yProv = (int) r.y;
616
                for (stepY=0; stepY < numH+1; stepY++)
617
                {
618
                        if ((yProv + H) > r.getMaxY()) 
619
                                altoAux = (int) r.getMaxY() - yProv;
620
                        else
621
                                altoAux = H;
622
                                                
623
                        xProv = (int) r.x;
624
                        for (stepX=0; stepX < numW+1; stepX++)                                
625
                        {                        
626
                                    if ((xProv + A) > r.getMaxX()) 
627
                                            anchoAux = (int) r.getMaxX() - xProv;
628
                                    else
629
                                            anchoAux = A;
630
                                
631
                                Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux);
632
                                
633
                                // Parte que dibuja
634
                                srcPts[0] = xProv;
635
                                srcPts[1] = yProv;
636
                                srcPts[2] = xProv + anchoAux+1;
637
                                srcPts[3] = yProv;
638
                                srcPts[4] = xProv + anchoAux+1;
639
                                srcPts[5] = yProv + altoAux+1;
640
                                srcPts[6] = xProv;
641
                                srcPts[7] = yProv + altoAux+1;
642
                                
643
                                try {
644
                                                mat.inverseTransform(srcPts, 0, dstPts, 0, 4);
645
                                        Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(
646
                                                        dstPts[0], dstPts[1],
647
                                                                dstPts[2] - dstPts[0], dstPts[5]-dstPts[3]); 
648
                                        Extent extent = new Extent(rectCuadricula);
649
                                        
650
                                        Dimension tam = new Dimension(anchoAux+1, altoAux+1);
651
                                        ViewPort vp = viewPort.cloneViewPort();
652
                                        vp.setImageSize(tam);
653
                                        vp.setExtent(rectCuadricula);
654
                                        vp.setAffineTransform(mat);
655
                                        // ViewPortData vp = new ViewPortData(getProjection(), extent, tam);
656
                                        // vp.setMat(mat);
657
                                        // rasterList.draw(g2, vp);
658
                                                                                
659
                                        /*System.out.println("FLyrRaster.print(): fila "+stepX+" de "
660
                                                + numW + " , col "+stepY+" de " + numH + 
661
                                                "\n, Extent = "+vp.getExtent() + " imageSize: "
662
                                                + tam);*/
663
                                        draw(null, g, vp, cancel,scale);
664
                                                
665
                                        } catch (NoninvertibleTransformException e) {
666
                                                // TODO Auto-generated catch block
667
                                                e.printStackTrace();
668
                                        }
669
                                // Fin parte que dibuja
670
                                        xProv = xProv + A;        
671
                        }                        
672
                        yProv = yProv + H;
673
                }  
674
                
675
        }
676
        
677
        /**
678
         * A?ade un fichero a la capa raster
679
         * @param fileName Nombre del fichero
680
         */
681
        public void addFiles(String fileName){
682
                ((RasterFileAdapter) source).addFile(fileName);
683
        }
684
        
685
        /**
686
         * Elimina un fichero a la capa raster
687
         * @param fileName Nombre del fichero
688
         */
689
        public void delFile(String fileName){
690
                ((RasterFileAdapter) source).delFile(fileName);
691
        }
692
        
693
        /* (non-Javadoc)
694
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
695
         */
696
        public void setBand(int flag, int nBand) {
697
                this.getSource().setBand(flag, nBand);
698
        }
699
        
700
        /**
701
         * Borra de la lista de listeners el que se pasa como par?metro.
702
         *
703
         * @param o LayerListener a borrar.
704
         *
705
         * @return True si ha sido correcto el borrado del Listener.
706
         */
707
        public boolean removeLayerListener(LayerListener o) {
708
                if(this.isRemoveRasterFlag()){
709
                        /*try{
710
                                ((RasterFileAdapter) source).stop();
711
                        }catch(DriverIOException exc){
712
                                
713
                        }*/
714
                        this.setRemoveRasterFlag(true);
715
                }
716
                return super.layerListeners.remove(o);
717
        }
718
        
719
        /**
720
         * @return Returns the removeRasterFlag.
721
         */
722
        public boolean isRemoveRasterFlag() {
723
                return removeRasterFlag;
724
        }
725
        
726
        /**
727
         * Asigna el valor del flag que dice si destruimos la memoria del raster
728
         * al eliminarlo del TOC o  no.
729
         * @param removeRasterFlag The removeRasterFlag to set.
730
         */
731
        public void setRemoveRasterFlag(boolean removeRasterFlag) {
732
                this.removeRasterFlag = removeRasterFlag;
733
        }
734
        
735
        public ImageIcon getTocImageIcon() {                        
736
                return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG"));
737
        }
738
        
739
        /*
740
         *  (non-Javadoc)
741
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
742
         */
743
        public int[] getTileSize() {
744
                int[] size = {maxTileDrawWidth, maxTileDrawHeight}; 
745
                return size;
746
        }
747

    
748
        /*
749
         *  (non-Javadoc)
750
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
751
         */
752
        public boolean isTiled() {
753
                return mustTileDraw;
754
        }
755
        
756
        /**
757
         * Obtiene el flag que dice si la imagen est? o no georreferenciada
758
         * @return true si est? georreferenciada y false si no lo est?.
759
         */
760
        public boolean isGeoreferenced() {
761
                return getSource().isGeoreferenced();
762
        }
763
}