Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrRaster.java @ 10977

History | View | Annotate | Download (22 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.print.attribute.PrintRequestAttributeSet;
58
import javax.swing.ImageIcon;
59

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

    
65
import com.hardcode.driverManager.Driver;
66
import com.hardcode.driverManager.DriverLoadException;
67
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
68
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
69
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
70
import com.iver.cit.gvsig.fmap.MapControl;
71
import com.iver.cit.gvsig.fmap.ViewPort;
72
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
73
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver;
74
import com.iver.cit.gvsig.fmap.drivers.RasterDriver;
75
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem;
76
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem;
77
import com.iver.utiles.XMLEntity;
78
import com.iver.utiles.swing.threads.Cancellable;
79

    
80

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

    
102
        /**
103
         * Devuelve el RasterAdapter de la capa.
104
         *
105
         * @return RasterAdapter.
106
         */
107
        public RasterAdapter getSource() {
108
                return source;
109
        }
110

    
111
        /**
112
         *Redefine wakeUp de FLyrDefault
113
         */
114
        public void wakeUp(){
115
                /*setName(getName());
116
                setProjection(getProjection());
117
                try {
118
                        load();
119
                } catch (DriverIOException e) {
120
                        e.printStackTrace();
121
                }*/
122
        }
123

    
124
        /**
125
         * Inserta el RasterAdapter.
126
         *
127
         * @param ra RasterAdapter.
128
         */
129
        public void setSource(RasterAdapter ra) {
130
                source = ra;
131
        }
132

    
133
        /**
134
         * Devuelve la pila de filtros aplicada sobre  la capa raster.
135
         *
136
         * @return RasterFilterStack.
137
         */
138
        public RasterFilterStack getFilterStack(){
139
                return source.getFilterStack();
140
        }
141

    
142
        /**
143
         * Asignar el estado del raster
144
         * @param status
145
         */
146
        public void setStatus(StatusRasterInterface status){
147
                this.status = status;
148
        }
149

    
150
        /**
151
         * Asigna la pila de filtros aplicada al raster
152
         * @return
153
         */
154
        public void setFilterStack(RasterFilterStack stack){
155
                source.setFilterStack(stack);
156
        }
157

    
158
        /**
159
         * Obtiene el estado del raster
160
         * @return
161
         */
162
        public StatusRasterInterface getStatus(){
163
                return this.status;
164
        }
165

    
166
        /**
167
         * Asigna la posici?n en la que se ha hecho click al mostrar
168
         * informaci?n del raster.
169
         * @param x        Posici?n en X
170
         * @param y        Posici?n en Y
171
         */
172
        public void setPos(int x, int y){
173
                this.posX = x;
174
                this.posY = y;
175
        }
176

    
177
        /**
178
         * Asigna la posici?n en coordenadas del mundo real en la que se ha
179
         * hecho click al mostrar informaci?n del raster.
180
         * @param x        Posici?n en X
181
         * @param y        Posici?n en Y
182
         */
183
        public void setPosWC(double x, double y){
184
                this.posXWC = x;
185
                this.posYWC = y;
186
        }
187

    
188
        /**
189
         * Asigna RGB en la posici?n en la que se ha
190
         * hecho click al mostrar informaci?n del raster.
191
         * @param r        valor de rojo
192
         * @param g        valor de verde
193
         * @param b        valor de azul
194
         */
195
        public void setRGB(int r, int g, int b){
196
                this.r = r;
197
                this.g = g;
198
                this.b = b;
199
        }
200

    
201
        /*
202
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
203
         */
204
        public void load() throws LoadLayerException {
205
                ((RasterFileAdapter) source).start();
206
                ((RasterFileAdapter) source).setTransparency(getTransparency());
207
        }
208

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

    
240
                        if(mustTileDraw){
241
                                Point2D p = vp.getOffset();
242
                                Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), vp.getImageWidth(), vp.getImageHeight());
243
                                Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
244
                                tiles.setAffineTransform((AffineTransform) vp.getAffineTransform().clone());
245
                                for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
246
                                        // drawing part
247
                                        try {
248
                                                ViewPort vport = tiles.getTileViewPort(vp, tileNr);
249
                                                ((RasterFileAdapter) source).draw(image, g, vport, cancel);
250
                                        } catch (NoninvertibleTransformException e) {
251
                                                e.printStackTrace();
252
                                        }
253
                                }
254
                        }else
255
                                ((RasterFileAdapter) source).draw(image, g, vp, cancel);
256

    
257
                } catch (DriverIOException e) {
258
                        throw new ReadDriverException(getName(),e);
259
                }
260

    
261
                if (getVirtualLayers() != null) {
262
                        getVirtualLayers().draw(image, g, vp, cancel,scale);
263
                }
264
                }
265
        }
266

    
267
        /**
268
         * Inserta la proyecci?n.
269
         *
270
         * @param proj Proyecci?n.
271
         */
272
        public void setProjection(IProjection proj) {
273
                super.setProjection(proj);
274

    
275
                if (source != null && source.getDriver() != null && source.getDriver() instanceof GeorreferencedRasterDriver) {
276
                        GeorreferencedRasterDriver geoDrv = (GeorreferencedRasterDriver) source.getDriver();
277

    
278
                        if (geoDrv.getProjection() == null) {
279
                                geoDrv.setProjection(proj);
280
                        }
281
                }
282
        }
283

    
284
        public void setTransparency(int trans) {
285
                super.setTransparency(trans);
286
                ((RasterFileAdapter) source).setTransparency(trans);
287
                if (getMapContext() != null){
288
                        getMapContext().invalidate();
289
                }
290
        }
291

    
292
        public int getTransparency() {
293
                return ((RasterFileAdapter) source).getTransparency();
294
        }
295

    
296
        /*
297
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
298
         */
299
        public Rectangle2D getFullExtent() {
300
                return ((RasterFileAdapter) source).getFullExtent();
301
        }
302

    
303
        /**
304
         * Obtiene el valor del pixel del Image en la posici?n x,y
305
         * @param x Posici?n x
306
         * @param y Posici?n y
307
         * @return valor de pixel
308
         */
309
        public int[] getPixel(double wcx, double wcy){
310
                return ((RasterFileAdapter) source).getPixel(wcx, wcy);
311
        }
312

    
313
        public double getMaxX(){
314
                return this.getFullExtent().getMaxX();
315
        }
316

    
317
        public double getMaxY(){
318
                return this.getFullExtent().getMaxY();
319
        }
320

    
321
        public double getMinX(){
322
                return this.getFullExtent().getMinX();
323
        }
324

    
325
        public double getMinY(){
326
                return this.getFullExtent().getMinY();
327
        }
328

    
329
        public double getHeight(){
330
                return this.getFullExtent().getHeight();
331
        }
332

    
333
        public double getWidth(){
334
                return this.getFullExtent().getWidth();
335
        }
336

    
337

    
338
        /* (non-Javadoc)
339
         * @deprecated. See String getInfo(Point p) throws DriverException
340
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint#queryByPoint(java.awt.Point)
341
         */
342
        public String queryByPoint(Point p) throws ReadDriverException {
343
                String data = "<file:"+normalizeAsXMLTag(getName())+">\n";
344

    
345
                ArrayList attr = source.getAttributes();
346
                data += "  <raster\n";
347
                data += "    File=\""+((RasterFileAdapter) source).getFile()+"\"\n";
348
                for (int i=0; i<attr.size(); i++) {
349
                        Object [] a = (Object []) attr.get(i);
350

    
351
                        data += "    "+a[0].toString()+"=";
352
                        if (a[1].toString() instanceof String)
353
                                data += "\""+a[1].toString()+"\"\n";
354
                        else
355
                                data += a[1].toString()+"\n";
356
                }
357
                data += "    Point=\""+posX+" , "+posY+"\"\n";
358
                data += "    Point_WC=\""+posXWC+" , "+posYWC+"\"\n";
359
                data += "    RGB=\""+r+", "+g+", "+b+"\"\n";
360
                data += "  />\n";
361

    
362
                data += "</file:"+normalizeAsXMLTag(getName())+">\n";
363
                //System.out.println(data);
364
                return data;
365
        }
366

    
367
        public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException {
368

    
369
                Point2D pReal = getMapContext().getViewPort().toMapPoint(p);
370
                Point2D px = null;
371
                if(        pReal.getX() > this.getMinX() &&
372
                        pReal.getX() < this.getMaxX() &&
373
                        pReal.getY() > this.getMinY() &&
374
                        pReal.getY() < this.getMaxY()){
375
                        ArrayList attr = source.getAttributes();
376
                        int w = 0, h = 0;
377
                        for (int i=0; i<attr.size(); i++) {
378
                                Object [] a = (Object []) attr.get(i);
379
                                if(a[0].toString().equals("Width"))
380
                                        w = ((Integer)a[1]).intValue();
381
                                if(a[0].toString().equals("Height"))
382
                                        h = ((Integer)a[1]).intValue();
383
                        }
384
                        px = new Point2D.Double();
385
                        px.setLocation( ((pReal.getX() - this.getMinX()) * w) / getWidth(),
386
                                                        ((this.getMaxY() - pReal.getY()) * h) / getHeight());
387
                }
388

    
389
                int[] rgb = this.getPixel(pReal.getX(), pReal.getY());
390

    
391
                StringXMLItem[] item = new StringXMLItem[1];
392
                String data = "<file:"+normalizeAsXMLTag(getName())+">\n";
393

    
394
                data += "  <raster\n";
395
                data += "    View_Point=\""+p.getX()+" , "+p.getY()+"\"\n";
396
                data += "    World_Point=\""+pReal.getX()+" , "+pReal.getY()+"\"\n";
397
                if(px == null)
398
                        data += "    Pixel_Point=\"Out\"\n";
399
                else
400
                        data += "    Pixel_Point=\""+(int)px.getX()+" , "+(int)px.getY()+"\"\n";
401
                data += "    RGB=\""+rgb[1]+"  "+rgb[2]+"  "+rgb[3]+"\"\n";
402
                data += "    Band_Value=\"";
403
                if(this.getSource().getDataType() >= 0 && this.getSource().getDataType() <= 3){
404
                        for(int i = 0; i < this.getSource().getNumBands(); i++)
405
                                data += ((Integer)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).intValue()+"  ";
406
                }
407
                if(this.getSource().getDataType() >= 4){
408
                        for(int i = 0; i < this.getSource().getNumBands(); i++)
409
                                data += ((Float)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).floatValue()+"  ";
410
                }
411
                if(this.getSource().getDataType() >= 5){
412
                        for(int i = 0; i < this.getSource().getNumBands(); i++)
413
                                data += ((Double)((RasterDriver)this.getSource().getDriver()).getData((int)px.getX(), (int)px.getY(), i)).doubleValue()+"  ";
414
                }
415
                data += "\"\n";
416
                data += "  />\n";
417
                data += "</file:"+normalizeAsXMLTag(getName())+">\n";
418

    
419
                item[0] = new StringXMLItem(data, this);
420
                return item;
421

    
422
        }
423

    
424
        /**
425
         * Filters a string for being suitable as XML Tag, erasing
426
         * all not alphabetic or numeric characters.
427
         * @param s
428
         * @return string normalized
429
         */
430
        public String normalizeAsXMLTag(String s) {
431
                return s.replaceAll("[^a-zA-Z0-9]","");
432
        }
433

    
434
        /**
435
         * Obtiene atributos a partir de un georasterfile
436
         * @return
437
         */
438
        public ArrayList getAttributes() {
439
                return source.getAttributes();
440
        }
441

    
442
        /**
443
         * @throws XMLException
444
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
445
         */
446
        public XMLEntity getXMLEntity() throws XMLException {
447
                XMLEntity xml = super.getXMLEntity();
448

    
449
                if (source instanceof RasterFileAdapter) {
450
                        xml.putProperty("file", ((RasterFileAdapter) source).getFile());
451
                }
452

    
453
                xml.putProperty("driverName", getSource().getDriver().getName());
454

    
455
                //Si no hay ning?n Status aplicamos el StatusLayerRaster que se usa por defecto
456
                if(status == null)
457
                        status = new StatusLayerRaster();
458

    
459
                status.getXMLEntity(xml, true, this);
460

    
461

    
462
                return xml;
463
        }
464

    
465
        public void setXMLEntity03(XMLEntity xml)
466
        throws XMLException {
467
                super.setXMLEntity(xml);
468
                try {
469
                        Driver d = LayerFactory.getDM().getDriver(
470
                                xml.getStringProperty("driverName"));
471
                        File f = new File(xml.getStringProperty("file"));
472
                        RasterAdapter adapter = new RasterFileAdapter(f);
473
                        adapter.setDriver(d);
474
                        setSource(adapter);
475
                        // Para notificar al adapter-driver cual es la proyecci?n.
476
                        setProjection(super.getProjection());
477
                } catch (DriverLoadException e) {
478
                        throw new XMLException(e);
479
                }
480
        }
481

    
482
        public void setXMLEntity(XMLEntity xml)
483
        throws XMLException {
484
                super.setXMLEntity(xml);
485
                try {
486
                        Driver d = LayerFactory.getDM().getDriver(
487
                                xml.getStringProperty("driverName"));
488
                        File f = new File(xml.getStringProperty("file"));
489
                        RasterAdapter adapter = new RasterFileAdapter(f);
490
                        adapter.setDriver(d);
491
                        setSource(adapter);
492
                        // Para notificar al adapter-driver cual es la proyecci?n.
493
                        setProjection(super.getProjection());
494

    
495
                        //Inicializamos la clase a la que se usa por defecto para
496
                        //compatibilidad con proyectos antiguos
497
                        String claseStr = StatusLayerRaster.defaultClass;
498
                        if (xml.contains("raster.class")) {
499
                                claseStr = xml.getStringProperty("raster.class");
500
                        }
501
                        if(status!=null)
502
                                status.setXMLEntity(xml, this);
503
                        else{
504

    
505
                                //Cuando cargamos un proyecto
506

    
507
                                if(claseStr!=null && !claseStr.equals("")){
508
                                        try{
509
                                                Class clase = Class.forName(claseStr);
510
                                                Constructor constr = clase.getConstructor(null);
511
                                                status = (StatusRasterInterface)constr.newInstance(null);
512
                                                if(status!=null)
513
                                                        status.setXMLEntity(xml, this);
514
                                        }catch(ClassNotFoundException exc){
515
                                                exc.printStackTrace();
516
                                        }catch(InstantiationException exc){
517
                                                exc.printStackTrace();
518
                                        }catch(IllegalAccessException exc){
519
                                                exc.printStackTrace();
520
                                        }catch(NoSuchMethodException exc){
521
                                                exc.printStackTrace();
522
                                        }catch(InvocationTargetException exc){
523
                                                exc.printStackTrace();
524
                                        }
525
                                }
526
                        }
527
                        firstLoad = true;
528

    
529

    
530
                } catch (DriverLoadException e) {
531
                        throw new XMLException(e);
532
                }
533
        }
534

    
535
        /* (non-Javadoc)
536
         * @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)
537
         */
538
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet propeties)
539
                throws ReadDriverException {
540

    
541
                if (isVisible() && isWithinScale(scale)){
542
                isPrinting = true;
543
                if (!mustTilePrint) {
544
                        draw(null, g, viewPort, cancel,scale);
545
                } else {
546
                // Para no pedir imagenes demasiado grandes, vamos
547
                // a hacer lo mismo que hace EcwFile: chunkear.
548
                // Llamamos a drawView con cuadraditos m?s peque?os
549
                // del BufferedImage ni caso, cuando se imprime viene con null
550
                        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, g.getClipBounds());
551
                        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
552

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

    
556
                        RasterStats stats = getSource().getFilterStack().getStats();
557
                        if(stats != null)
558
                                stats.history.add(stats.new History(getName(), stats.minBandValue, stats.maxBandValue, stats.secondMinBandValue, stats.secondMaxBandValue));
559

    
560

    
561
                        for (int tileNr=0; tileNr < tiles.getNumTiles(); tileNr++) {
562
                            // Parte que dibuja
563
                            try {
564
                                ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
565
                                draw(null, g, vp, cancel,scale);
566
                                } catch (NoninvertibleTransformException e) {
567
                                        // TODO Auto-generated catch block
568
                                        e.printStackTrace();
569
                                }
570
                }
571

    
572
                        if(stats != null){
573
                                getSource().getFilterStack().getStats().history.clear();
574
                                stats = getSource().getFilterStack().getStats();
575
                        }
576

    
577
                }
578
            isPrinting = false;
579
                }
580
        }
581

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

    
589
                int numW, numH;
590
                int stepX, stepY;
591
                int xProv, yProv, wProv, hProv;
592
                double xProvD, yProvD, wProvD, hProvD;
593
                int A = 1500;
594
                int H = 1500;
595
                int altoAux, anchoAux;
596

    
597
                AffineTransform mat = (AffineTransform) viewPort.getAffineTransform().clone();
598

    
599
                // Vamos a hacerlo en trozos de AxH
600
                Rectangle r = g.getClipBounds();
601
                numW = (int) (r.width) / A;
602
                numH = (int) (r.height) / H;
603

    
604

    
605
                double[] srcPts = new double[8];
606
                double[] dstPts= new double[8];
607

    
608
                yProv = (int) r.y;
609
                for (stepY=0; stepY < numH+1; stepY++)
610
                {
611
                        if ((yProv + H) > r.getMaxY())
612
                                altoAux = (int) r.getMaxY() - yProv;
613
                        else
614
                                altoAux = H;
615

    
616
                        xProv = (int) r.x;
617
                        for (stepX=0; stepX < numW+1; stepX++)
618
                        {
619
                                    if ((xProv + A) > r.getMaxX())
620
                                            anchoAux = (int) r.getMaxX() - xProv;
621
                                    else
622
                                            anchoAux = A;
623

    
624
                                Rectangle newRect = new Rectangle(xProv, yProv, anchoAux, altoAux);
625

    
626
                                // Parte que dibuja
627
                                srcPts[0] = xProv;
628
                                srcPts[1] = yProv;
629
                                srcPts[2] = xProv + anchoAux+1;
630
                                srcPts[3] = yProv;
631
                                srcPts[4] = xProv + anchoAux+1;
632
                                srcPts[5] = yProv + altoAux+1;
633
                                srcPts[6] = xProv;
634
                                srcPts[7] = yProv + altoAux+1;
635

    
636
                                try {
637
                                                mat.inverseTransform(srcPts, 0, dstPts, 0, 4);
638
                                        Rectangle2D.Double rectCuadricula = new Rectangle2D.Double(
639
                                                        dstPts[0], dstPts[1],
640
                                                                dstPts[2] - dstPts[0], dstPts[5]-dstPts[3]);
641
                                        Extent extent = new Extent(rectCuadricula);
642

    
643
                                        Dimension tam = new Dimension(anchoAux+1, altoAux+1);
644
                                        ViewPort vp = viewPort.cloneViewPort();
645
                                        vp.setImageSize(tam);
646
                                        vp.setExtent(rectCuadricula);
647
                                        vp.setAffineTransform(mat);
648
                                        // ViewPortData vp = new ViewPortData(getProjection(), extent, tam);
649
                                        // vp.setMat(mat);
650
                                        // rasterList.draw(g2, vp);
651

    
652
                                        /*System.out.println("FLyrRaster.print(): fila "+stepX+" de "
653
                                                + numW + " , col "+stepY+" de " + numH +
654
                                                "\n, Extent = "+vp.getExtent() + " imageSize: "
655
                                                + tam);*/
656
                                        draw(null, g, vp, cancel,scale);
657

    
658
                                        } catch (NoninvertibleTransformException e) {
659
                                                // TODO Auto-generated catch block
660
                                                e.printStackTrace();
661
                                        }
662
                                // Fin parte que dibuja
663
                                        xProv = xProv + A;
664
                        }
665
                        yProv = yProv + H;
666
                }
667

    
668
        }
669

    
670
        /**
671
         * A?ade un fichero a la capa raster
672
         * @param fileName Nombre del fichero
673
         */
674
        public void addFiles(String fileName){
675
                ((RasterFileAdapter) source).addFile(fileName);
676
        }
677

    
678
        /**
679
         * Elimina un fichero a la capa raster
680
         * @param fileName Nombre del fichero
681
         */
682
        public void delFile(String fileName){
683
                ((RasterFileAdapter) source).delFile(fileName);
684
        }
685

    
686
        /* (non-Javadoc)
687
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#setBand(int, int)
688
         */
689
        public void setBand(int flag, int nBand) {
690
                this.getSource().setBand(flag, nBand);
691
        }
692

    
693
        /**
694
         * Borra de la lista de listeners el que se pasa como par?metro.
695
         *
696
         * @param o LayerListener a borrar.
697
         *
698
         * @return True si ha sido correcto el borrado del Listener.
699
         */
700
        public boolean removeLayerListener(LayerListener o) {
701
                if(this.isRemoveRasterFlag()){
702
                        /*try{
703
                                ((RasterFileAdapter) source).stop();
704
                        }catch(DriverIOException exc){
705

706
                        }*/
707
                        this.setRemoveRasterFlag(true);
708
                }
709
                return super.layerListeners.remove(o);
710
        }
711

    
712
        /**
713
         * @return Returns the removeRasterFlag.
714
         */
715
        public boolean isRemoveRasterFlag() {
716
                return removeRasterFlag;
717
        }
718

    
719
        /**
720
         * Asigna el valor del flag que dice si destruimos la memoria del raster
721
         * al eliminarlo del TOC o  no.
722
         * @param removeRasterFlag The removeRasterFlag to set.
723
         */
724
        public void setRemoveRasterFlag(boolean removeRasterFlag) {
725
                this.removeRasterFlag = removeRasterFlag;
726
        }
727

    
728
        public ImageIcon getTocImageIcon() {
729
                return new ImageIcon(MapControl.class.getResource("images/icolayerRaster.PNG"));
730
        }
731

    
732
        /*
733
         *  (non-Javadoc)
734
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
735
         */
736
        public int[] getTileSize() {
737
                int[] size = {maxTileDrawWidth, maxTileDrawHeight};
738
                return size;
739
        }
740

    
741
        /*
742
         *  (non-Javadoc)
743
         * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
744
         */
745
        public boolean isTiled() {
746
                return mustTileDraw;
747
        }
748

    
749
        /**
750
         * Obtiene el flag que dice si la imagen est? o no georreferenciada
751
         * @return true si est? georreferenciada y false si no lo est?.
752
         */
753
        public boolean isGeoreferenced() {
754
                return getSource().isGeoreferenced();
755
        }
756
}