Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / Grid.java @ 20871

History | View | Annotate | Download (36.6 KB)

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

    
21
import java.io.IOException;
22
import java.util.Arrays;
23

    
24
import org.gvsig.raster.buffer.BufferFactory;
25
import org.gvsig.raster.buffer.RasterBuffer;
26
import org.gvsig.raster.buffer.RasterBufferInvalidAccessException;
27
import org.gvsig.raster.buffer.RasterBufferInvalidException;
28
import org.gvsig.raster.dataset.IBuffer;
29
import org.gvsig.raster.dataset.IRasterDataSource;
30
import org.gvsig.raster.datastruct.Extent;
31
import org.gvsig.raster.datastruct.Transparency;
32
import org.gvsig.raster.grid.filter.RasterFilterList;
33

    
34
/**
35
 * Clase que representa una rejilla de datos raster. Este tipo de grid tiene el interfaz necesario
36
 * de acceso a la informaci?n raster para aplicaciones de analisis raster. Contiene m?todos de acceso al
37
 * dato tanto en lectura como en escritura y encapsula operaciones entre grids. Adem?s contiene
38
 * objetos que contienen las caracter?sticas asociadas a ese grid. Sobre un grid pueden
39
 * aplicarse tambi?n operaciones de filtrado.
40
 *
41
 * Podemos crear un Grid de cinco formas distitas:
42
 * <UL>
43
 * <LI>A partir de una fuente de datos (cargada en el constructor). Se har? una petici?n del extent pasado por par?metro con las bandas seleccionadas por par?metro.</LI>
44
 * <LI>A partir de un extensi?n de capa, una extensi?n de vista, un tipo de dato y un n?mero de datos
45
 * crea un Grid vacio util para escritura.</LI>
46
 * <LI>A partir de una fuente de datos (cargados). Datasource se usa como buffer de datos cargados y se selecciona si queremos el reader interpolado.</LI>
47
 * <LI>A partir de una fuente de datos (cargada en el constructor). Se har? una petici?n del extent completo de la fuente con las bandas seleccionadas por par?metro.</LI>
48
 * <LI>A partir de una fuente de datos (cargada en el constructor). Se har? una petici?n del extent completo de la fuente con todas las bandas disponibles.</LI>
49
 * </UL>
50
 *
51
 * @author Victor Olaya (volaya@ya.com)
52
 * @author Nacho Brodin (nachobrodin@gmail.com)
53
 */
54
public class Grid implements IQueryableGrid, IWritableGrid{
55

    
56
        public final static double                 DEG_45_IN_RAD = Math.PI / 180. * 45.;
57
        public final static double                 DEG_90_IN_RAD = Math.PI / 180. * 90.;
58
        public final static double                 DEG_180_IN_RAD = Math.PI ;
59
        public final static double                 DEG_270_IN_RAD = Math.PI / 180. * 270.;
60
        public final static double                 DEG_360_IN_RAD = Math.PI * 2.;
61

    
62
        /* neighbor's address*/                               /* N  NE   E  SE   S  SW   W  NW */
63
        private final static int                 m_iOffsetX []=        {  0,  1,  1,  1,  0, -1, -1, -1};
64
        private final static int                m_iOffsetY []=        {  1,  1,  0, -1, -1, -1,  0,  1};
65

    
66
        private double                                         m_dDist[];
67
        public double                                         _2DX, _6DX, _DX_2, _4DX_2;
68

    
69
        private int[]                                         bands = null;
70
        private int                                         dataType = IBuffer.TYPE_UNDEFINED;
71

    
72
        private RasterBuffer                        rasterBuf = null;
73
        private GridReader                                 reader = null;
74
        private GridWriter                                 writer = null;
75
        private GridExtent                                 windowExtent = null;
76
        private GridExtent                                 layerExtent = null;
77
        private GridStatistic                        statistic = null;
78
        private GridPalette[]                        palette = null;
79
        private RasterFilterList                filterList = null;
80

    
81

    
82

    
83
        /**
84
         * Crea un grid a partir de un MultiRasterDataset. Usa el extent de la fuente de datos como
85
         * extent completo y el extent pasado como par?metro como extensi?n de ventana.
86
         *
87
         * Cuando se construye el reader se carga el buffer con la extensi?n definida en windowExtent
88
         * y las bandas especificadas en bands.
89
         *
90
         * @param IRasterDataSource datasets que proporcionan los datos
91
         * @param bands n?mero de bandas requeridas
92
         * @param windowExtent Extensi?n de la ventana. Si este par?metro es null se usar? el
93
         * mismo que el de la capa.
94
         */
95
        public Grid(IRasterDataSource datasets, int[] bands, GridExtent windowExtent)
96
                        throws RasterBufferInvalidException{
97
                BufferFactory bufferFactory = new BufferFactory(datasets);
98
                double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(),
99
                                                                                        bufferFactory.getSourceHeight()); 
100
                layerExtent = new GridExtent(        bufferFactory.getDataSource().getExtent(), 
101
                                                                                cellSize[0],
102
                                                                                cellSize[1]);
103
                if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null)
104
                        dataType = bufferFactory.getDataSource().getDataType()[0];
105
                this.bands = bands;
106

    
107
                if(windowExtent == null)
108
                        this.windowExtent = layerExtent;
109
                else
110
                        this.windowExtent = windowExtent;
111

    
112
                rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf();
113

    
114
                if (windowExtent.fitsIn(layerExtent))
115
                        reader = new GridNotInterpolated(bufferFactory, layerExtent, windowExtent, bands);
116
                else
117
                        reader = new GridInterpolated(bufferFactory, layerExtent, windowExtent, bands);
118
                writer = new GridWriter(layerExtent, dataType, rasterBuf);
119

    
120
                init(bufferFactory);
121
        }
122

    
123
        /**
124
         * Crea un grid vacio a partir de un extent y un tipo de datos. Se crea un buffer vacio en el
125
         * que puede escribirse a trav?s del writer. Los datos escritos pueden ser consultados con el
126
         * reader. No tiene una fuente de datos asociada ya que es un grid vacio basicamente para
127
         * escritura.
128
         * @param layerExtent Tama?o completo de la capa
129
         * @param windowExtent Ventana de datos.
130
         * @param dataType Tipo de datos del buffer
131
         * @param bands n?mero de bandas requeridas y orden de dibujado en el buffer
132
         */
133
        public Grid(GridExtent layerExtent,
134
                                GridExtent windowExtent,
135
                                int dataType,
136
                                int[] bands) throws RasterBufferInvalidException{
137
                this.windowExtent = windowExtent;
138
                this.layerExtent = layerExtent;
139
                this.dataType = dataType;
140

    
141
                rasterBuf = RasterBuffer.getBuffer(dataType, layerExtent.getNX(), layerExtent.getNY(), bands.length, true);
142

    
143
                if (windowExtent.fitsIn(layerExtent))
144
                        reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands);
145
                else
146
                        reader = new GridInterpolated(rasterBuf, layerExtent, windowExtent, bands);
147
                writer = new GridWriter(layerExtent, dataType, rasterBuf);
148
                init(null);
149
        }
150

    
151
        /**
152
         * Crea un grid a partir de un BufferFactory. El buffer debe estar cargado de datos y el extent
153
         * de este viene definido en el par?metro windowExtent.
154
         * @param bufferFactory Fuente de datos
155
         * @param windowExtent        Extent de los datos cargados en bufferFactory
156
         * @param notInterp Si es true fuerza a que el reader sea sin interpolaci?n. Si es false decide si
157
         * el reader es interpolado o no a partir de los extents de capa y la ventana seleccionada.
158
         */
159
        public Grid(BufferFactory bufferFactory, boolean notInterp) {
160
                double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(),
161
                                bufferFactory.getSourceHeight()); 
162
                this.layerExtent = new GridExtent(        bufferFactory.getDataSource().getExtent(), 
163
                                                                                        cellSize[0],
164
                                                                                        cellSize[1]);
165
                if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null)
166
                        dataType = bufferFactory.getDataSource().getDataType()[0];
167
                bands = bufferFactory.getDrawableBands();
168

    
169
                this.windowExtent = new GridExtent(        bufferFactory.getDataExtent(), 
170
                                                                                        cellSize[0],
171
                                                                                        cellSize[1]);
172

    
173
                rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf();
174

    
175
                if(notInterp) {
176
                        reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands);
177
                } else {
178
                        if (windowExtent.fitsIn(layerExtent))
179
                                reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands);
180
                        else
181
                                reader = new GridInterpolated(rasterBuf, layerExtent, windowExtent, bands);
182
                }
183
                writer = new GridWriter(layerExtent, dataType, rasterBuf);
184
                init(bufferFactory);
185
        }
186

    
187
        /**
188
         * Crea un grid a partir de un BufferFactory. Se har? una petici?n del extent completo de la fuente.
189
         * bufferFactory tiene asociada una fuente de datos pero se ignorar? si tiene el buffer lleno. La instanciaci?n
190
         * de GridNotInterpolated har? que se haga la petici?n para cargar raster completo.
191
         * @param bufferFactory Fuente de datos
192
         * @param bands n?mero de bandas requeridas y orden de dibujado en el buffer
193
         */
194
        public Grid(BufferFactory bufferFactory, int[] bands)
195
                        throws RasterBufferInvalidException{
196
                //La petici?n es del raster completo
197
                double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(),
198
                                bufferFactory.getSourceHeight()); 
199
                windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(), 
200
                                                                                                        cellSize[0],
201
                                                                                                        cellSize[1]);
202
                if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null)
203
                        dataType = bufferFactory.getDataSource().getDataType()[0];
204
                this.bands = bands;
205

    
206
                reader = new GridNotInterpolated(bufferFactory, layerExtent, windowExtent, bands);
207
                rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf();
208
                writer = new GridWriter(windowExtent, dataType, rasterBuf);
209

    
210
                init(bufferFactory);
211
        }
212

    
213
        /**
214
         * Crea un grid a partir de un BufferFactory. Se har? una petici?n del extent completo de la fuente.
215
         * bufferFactory tiene asociada una fuente de datos pero se ignorar? si tiene el buffer lleno. La instanciaci?n
216
         * de GridNotInterpolated har? que se haga la petici?n para cargar raster completo. El buffer se cargar?
217
         * con todas las bandas disponibles.
218
         * @param bufferFactory Fuente de datos
219
         */
220
        public Grid(BufferFactory bufferFactory) throws RasterBufferInvalidException {
221
                //La petici?n es del raster completo
222
                double cellSize[] = calcCellSize(bufferFactory.getDataSource(), bufferFactory.getSourceWidth(),
223
                                bufferFactory.getSourceHeight()); 
224
                windowExtent = layerExtent = new GridExtent(bufferFactory.getDataSource().getExtent(), 
225
                                                                                                        cellSize[0],
226
                                                                                                        cellSize[1]);
227
                if(bufferFactory.getDataSource() != null && bufferFactory.getDataSource().getDataType() != null)
228
                        dataType = bufferFactory.getDataSource().getDataType()[0];
229

    
230
                bands = new int[bufferFactory.getBandCount()];
231
                for(int i = 0; i < bufferFactory.getBandCount(); i ++)
232
                        bands[i] = i;
233
                reader = new GridNotInterpolated(bufferFactory, layerExtent, windowExtent, bands);
234
                rasterBuf = (RasterBuffer)bufferFactory.getRasterBuf();
235
                writer = new GridWriter(windowExtent, dataType, rasterBuf);
236

    
237
                init(bufferFactory);
238
        }
239
        
240
        /**
241
         * Calcula el tama?o de celda a partir de un dataset, un ancho y un alto en pixeles
242
         * @return
243
         */
244
        private double[] calcCellSize(IRasterDataSource mDataset, double w, double h) {
245
                double dCellsize[] = new double[2];
246
                try {
247
                        Extent e = mDataset.getExtent();
248
                        dCellsize[0] = (e.getMax().getX() - e.getMin().getX() ) / w;
249
                        dCellsize[1] = (e.getMax().getY() - e.getMin().getY() ) / h;
250
                        
251
                        return dCellsize;
252
                } catch (NullPointerException e) {
253
                        dCellsize[0] = 1;
254
                        dCellsize[1] = 1;
255
                        return dCellsize;
256
                }
257
        }
258

    
259
        /**
260
         * Selecciona la forma de obtener datos con o sin interpolaci?n. Si pasamos el par?metro
261
         * false al aplicar un m?todo de consulta de datos este ser? aplicado sin interpolaci?n.
262
         * @param interpolation
263
         */
264
        public void switchToInterpolationMethod(boolean interpolation){
265
                //GridExtent layer = new GridExtent(0, 0, rasterBuf.getWidth(), rasterBuf.getHeight(), 1);
266
                if(interpolation)
267
                        reader = new GridInterpolated(rasterBuf, layerExtent, windowExtent, bands);
268
                else
269
                        reader = new GridNotInterpolated(rasterBuf, layerExtent, windowExtent, bands);
270
                init(null);
271
        }
272

    
273
        /**
274
         * Inicializaci?n de constantes
275
         */
276
        private void init(BufferFactory ds) {
277
                int i;
278
                GridTransparency transparency = null;
279

    
280
                double dCellSize = getCellSize();
281

    
282
                statistic = new GridStatistic(this);
283
                if (ds == null)
284
                        transparency = new GridTransparency();
285
                else {
286
                        Transparency transp = ds.getDataSource().getTransparencyFilesStatus();
287
                        if (transp != null)
288
                                transparency = new GridTransparency(transp);
289
                        this.palette = new GridPalette[ds.getColorTables().length];
290
                        for (int iPal = 0; iPal < ds.getColorTables().length; iPal++) {
291
                                if (ds.getColorTables()[iPal] != null)
292
                                        this.palette[iPal] = new GridPalette(ds.getColorTables()[iPal]);
293
                        }
294
                }
295
                filterList = new RasterFilterList();
296
                if (ds != null) {
297
                        filterList.addEnvParam("IStatistics", ds.getDataSource().getStatistics());
298
                        filterList.addEnvParam("MultiRasterDataset", ds.getDataSource());
299
                }
300
                filterList.addEnvParam("Transparency", transparency);
301
                filterList.setInitRasterBuf(rasterBuf);
302

    
303
                m_dDist = new double[8];
304

    
305
                for (i = 0; i < 8; i++) {
306
                        m_dDist[i] = Math.sqrt ( m_iOffsetX[i] * dCellSize * m_iOffsetX[i] * dCellSize
307
                                                                        + m_iOffsetY[i] * dCellSize * m_iOffsetY[i] * dCellSize );
308
                }
309

    
310
                _2DX = dCellSize * 2.0;
311
                _6DX = dCellSize * 6.0;
312
                _DX_2 = dCellSize * dCellSize;
313
                _4DX_2 = 4.0 * _DX_2;
314
        }
315

    
316
        //************* Write Services *********************
317

    
318
        /*
319
         *  (non-Javadoc)
320
         * @see org.gvsig.fmap.grid.IWritableGrid#assign(byte)
321
         */
322
        public void assign(byte value)throws GridException {
323
                try {
324
                        writer.assign(value);
325
                } catch (RasterBufferInvalidAccessException e) {
326
                        throw new GridException("Error wrinting buffer");
327
                }
328
        }
329

    
330
        /*
331
         *  (non-Javadoc)
332
         * @see org.gvsig.fmap.grid.IWritableGrid#assign(short)
333
         */
334
        public void assign(short value)throws GridException {
335
                try {
336
                        writer.assign(value);
337
                } catch (RasterBufferInvalidAccessException e) {
338
                        throw new GridException("Error wrinting buffer");
339
                }
340
        }
341

    
342
        /*
343
         *  (non-Javadoc)
344
         * @see org.gvsig.fmap.grid.IWritableGrid#assign(int)
345
         */ 
346
        public void assign(int value)throws GridException {
347
                try {
348
                        writer.assign(value);
349
                } catch (RasterBufferInvalidAccessException e) {
350
                        throw new GridException("Error wrinting buffer");
351
                }
352
        }
353

    
354
        /*
355
         *  (non-Javadoc)
356
         * @see org.gvsig.fmap.grid.IWritableGrid#assign(float)
357
         */
358
        public void assign(float value)throws GridException {
359
                try {
360
                        writer.assign(value);
361
                } catch (RasterBufferInvalidAccessException e) {
362
                        throw new GridException("Error wrinting buffer");
363
                }
364
        }
365

    
366
        /*
367
         *  (non-Javadoc)
368
         * @see org.gvsig.fmap.grid.IWritableGrid#assign(double)
369
         */
370
        public void assign(double value)throws GridException {
371
                try {
372
                        writer.assign(value);
373
                } catch (RasterBufferInvalidAccessException e) {
374
                        throw new GridException("Error wrinting buffer");
375
                }
376
        }
377

    
378
        /*
379
         *  (non-Javadoc)
380
         * @see org.gvsig.fmap.grid.IWritableGrid#assign(org.gvsig.fmap.dataaccess.BufferFactory)
381
         */
382
        public void assign(BufferFactory bufferFactory) throws GridException {
383
                Grid window;
384
                try {
385
                        window = new Grid(bufferFactory.getDataSource(), bands, windowExtent);
386
                        write(window);
387
                        writer.setNoDataValue(window.getNoDataValue());
388
                } catch (RasterBufferInvalidException e) {
389
                        throw new GridException("Error writing buffer");
390
                }
391
        }
392

    
393
        /*
394
         *  (non-Javadoc)
395
         * @see org.gvsig.fmap.grid.IWritableGrid#assign(org.gvsig.fmap.grid.Grid)
396
         */
397
        public void assign(Grid driver) throws GridException {
398
                if (driver.getGridExtent().equals(layerExtent)){
399
                        write(driver);
400
                        writer.setNoDataValue(driver.getNoDataValue());
401
                }
402
        }
403

    
404
        /**
405
         * Sobreescribe los datos del grid actual con los datos del grid pasado por par?metro
406
         * @param g Grid desde donde se obtienen los datos
407
         */
408
        private void write(Grid g) throws GridException {
409
                try{
410
                        switch(rasterBuf.getDataType()){
411
                        case IBuffer.TYPE_BYTE: for (int x = 0; x < g.getNX(); x++) {
412
                                                                                for (int y = 0; y < g.getNY(); y++) {
413
                                                                                        writer.setCellValue(x, y, g.getCellValueAsByte(x, y));
414
                                                                                }
415
                                                                        }
416
                                                                        break;
417
                        case IBuffer.TYPE_SHORT:for (int x = 0; x < g.getNX(); x++) {
418
                                                                                for (int y = 0; y < g.getNY(); y++) {
419
                                                                                        writer.setCellValue(x, y, g.getCellValueAsShort(x, y));
420
                                                                                }
421
                                                                        }
422
                                                                        break;
423
                        case IBuffer.TYPE_INT:         for (int x = 0; x < g.getNX(); x++) {
424
                                                                                for (int y = 0; y < g.getNY(); y++) {
425
                                                                                        writer.setCellValue(x, y, g.getCellValueAsInt(x, y));
426
                                                                                }
427
                                                                        }
428
                                                                        break;
429
                        case IBuffer.TYPE_FLOAT:for (int x = 0; x < g.getNX(); x++) {
430
                                                                                for (int y = 0; y < g.getNY(); y++) {
431
                                                                                        writer.setCellValue(x, y, g.getCellValueAsFloat(x, y));
432
                                                                                }
433
                                                                        }
434
                                                                        break;
435
                        case IBuffer.TYPE_DOUBLE:for (int x = 0; x < g.getNX(); x++) {
436
                                                                                for (int y = 0; y < g.getNY(); y++) {
437
                                                                                        writer.setCellValue(x, y, g.getCellValueAsDouble(x, y));
438
                                                                                }
439
                                                                        }
440
                                                                        break;
441
                        }
442
                } catch (OutOfGridException e) {
443
                        throw new GridException("");
444
                } 
445
        }
446

    
447
        /*
448
         *  (non-Javadoc)
449
         * @see org.gvsig.fmap.grid.IWritableGrid#assignNoData()
450
         */
451
        public void assignNoData(){
452
                try {
453
                        switch(rasterBuf.getDataType()){
454
                        case IBuffer.TYPE_BYTE: writer.assign((byte)rasterBuf.getNoDataValue());break;
455
                        case IBuffer.TYPE_SHORT: writer.assign((short)rasterBuf.getNoDataValue());break;
456
                        case IBuffer.TYPE_INT: writer.assign((int)rasterBuf.getNoDataValue());break;
457
                        case IBuffer.TYPE_FLOAT: writer.assign((float)rasterBuf.getNoDataValue());break;
458
                        case IBuffer.TYPE_DOUBLE: writer.assign((double)rasterBuf.getNoDataValue());break;
459
                        }
460
                } catch (RasterBufferInvalidAccessException e) {
461
                        //No hacemos nada. El tipo de dato al que se accede no es controlado por el usuario por lo
462
                        //que no le mandamos la excepci?n hacia arriba.
463
                        e.printStackTrace();
464
                }
465
        }
466

    
467
        /*
468
         *  (non-Javadoc)
469
         * @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, byte)
470
         */
471
        public void setCellValue(int x, int y, byte value)throws OutOfGridException{
472
                writer.setCellValue(x, y, value);
473
        }
474

    
475
        /*
476
         *  (non-Javadoc)
477
         * @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, short)
478
         */
479
        public void setCellValue(int x, int y, short value)throws OutOfGridException{
480
                writer.setCellValue(x, y, value);
481
        }
482

    
483
        /*
484
         *  (non-Javadoc)
485
         * @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, int)
486
         */
487
        public void setCellValue(int x, int y, int value)throws OutOfGridException{
488
                writer.setCellValue(x, y, value);
489
        }
490

    
491
        /*
492
         *  (non-Javadoc)
493
         * @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, float)
494
         */
495
        public void setCellValue(int x, int y, float value)throws OutOfGridException{
496
                writer.setCellValue(x, y, value);
497
        }
498

    
499
        /*
500
         *  (non-Javadoc)
501
         * @see org.gvsig.fmap.grid.IWritableGrid#setCellValue(int, int, double)
502
         */
503
        public void setCellValue(int x, int y, double value)throws OutOfGridException{
504
                writer.setCellValue(x, y, value);
505
        }
506

    
507
        /*
508
         *  (non-Javadoc)
509
         * @see org.gvsig.fmap.grid.IWritableGrid#add(org.gvsig.fmap.grid.Grid)
510
         */
511
        public void add(Grid g) throws GridException {
512
                if (g.getGridExtent().equals(getGridExtent())) {
513
                        boolean interp = (reader instanceof GridInterpolated);
514
                        switchToInterpolationMethod(false);
515
                        try{
516
                                switch(rasterBuf.getDataType()){
517
                                case IBuffer.TYPE_BYTE: for (int x = 0; x < g.getNX(); x++) {
518
                                                                                        for (int y = 0; y < g.getNY(); y++) {
519
                                                                                                writer.setCellValue(x, y, reader.getCellValueAsByte(x, y) + g.getCellValueAsByte(x,y));
520
                                                                                        }
521
                                                                                }
522
                                                                                break;
523
                                case IBuffer.TYPE_SHORT:for (int x = 0; x < g.getNX(); x++) {
524
                                                                                        for (int y = 0; y < g.getNY(); y++) {
525
                                                                                                writer.setCellValue(x, y, reader.getCellValueAsShort(x, y) + g.getCellValueAsShort(x,y));
526
                                                                                        }
527
                                                                                }
528
                                                                                break;
529
                                case IBuffer.TYPE_INT:         for (int x = 0; x < g.getNX(); x++) {
530
                                                                                        for (int y = 0; y < g.getNY(); y++) {
531
                                                                                                writer.setCellValue(x, y, reader.getCellValueAsInt(x, y) + g.getCellValueAsInt(x,y));
532
                                                                                        }
533
                                                                                }
534
                                                                                break;
535
                                case IBuffer.TYPE_FLOAT:for (int x = 0; x < g.getNX(); x++) {
536
                                                                                        for (int y = 0; y < g.getNY(); y++) {
537
                                                                                                writer.setCellValue(x, y, reader.getCellValueAsFloat(x, y) + g.getCellValueAsFloat(x,y));
538
                                                                                        }
539
                                                                                }
540
                                                                                break;
541
                                case IBuffer.TYPE_DOUBLE:for (int x = 0; x < g.getNX(); x++) {
542
                                                                                        for (int y = 0; y < g.getNY(); y++) {
543
                                                                                                writer.setCellValue(x, y, reader.getCellValueAsDouble(x, y) + g.getCellValueAsDouble(x,y));
544
                                                                                        }
545
                                                                                }
546
                                                                                break;
547
                                }
548
                        } catch (OutOfGridException e) {
549
                                throw new GridException("");
550
                        } catch (RasterBufferInvalidAccessException e1) {
551
                                throw new GridException("");
552
                        } catch (RasterBufferInvalidException e) {
553
                                throw new GridException("");
554
                        }
555
                        switchToInterpolationMethod(interp);
556
                }
557
        }
558

    
559
        /*
560
         *  (non-Javadoc)
561
         * @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, byte)
562
         */
563
        public void addToCellValue(int x, int y, byte value)
564
                throws GridException {
565
                try {
566
                        writer.setCellValue(x, y, (byte)(reader.getCellValueAsByte(x, y) + value));
567
                } catch (OutOfGridException e) {
568
                        throw new GridException("");
569
                } catch (RasterBufferInvalidAccessException e) {
570
                        throw new GridException("");
571
                } catch (RasterBufferInvalidException e) {
572
                        throw new GridException("");
573
                }
574
        }
575

    
576
        /*
577
         *  (non-Javadoc)
578
         * @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, short)
579
         */
580
        public void addToCellValue(int x, int y, short value)
581
                throws GridException {
582
                try {
583
                        writer.setCellValue(x, y, (short)(reader.getCellValueAsShort(x, y) + value));
584
                } catch (OutOfGridException e) {
585
                        throw new GridException("");
586
                } catch (RasterBufferInvalidAccessException e) {
587
                        throw new GridException("");
588
                } catch (RasterBufferInvalidException e) {
589
                        throw new GridException("");
590
                }
591
        }
592

    
593
        /*
594
         *  (non-Javadoc)
595
         * @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, int)
596
         */
597
        public void addToCellValue(int x, int y, int value)
598
                throws GridException {
599
                try {
600
                        writer.setCellValue(x, y, (int)(reader.getCellValueAsInt(x, y) + value));
601
                } catch (OutOfGridException e) {
602
                        throw new GridException("");
603
                } catch (RasterBufferInvalidAccessException e) {
604
                        throw new GridException("");
605
                } catch (RasterBufferInvalidException e) {
606
                        throw new GridException("");
607
                }
608
        }
609

    
610
        /*
611
         *  (non-Javadoc)
612
         * @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, float)
613
         */
614
        public void addToCellValue(int x, int y, float value)
615
                throws GridException {
616
                try {
617
                        writer.setCellValue(x, y, (float)(reader.getCellValueAsFloat(x, y) + value));
618
                } catch (OutOfGridException e) {
619
                        throw new GridException("");
620
                } catch (RasterBufferInvalidAccessException e) {
621
                        throw new GridException("");
622
                } catch (RasterBufferInvalidException e) {
623
                        throw new GridException("");
624
                }
625
        }
626

    
627
        /*
628
         *  (non-Javadoc)
629
         * @see org.gvsig.fmap.grid.IWritableGrid#addToCellValue(int, int, double)
630
         */
631
        public void addToCellValue(int x, int y, double value)
632
                throws GridException {
633
                try {
634
                        writer.setCellValue(x, y, (double)(reader.getCellValueAsDouble(x, y) + value));
635
                } catch (OutOfGridException e) {
636
                        throw new GridException("");
637
                } catch (RasterBufferInvalidAccessException e) {
638
                        throw new GridException("");
639
                } catch (RasterBufferInvalidException e) {
640
                        throw new GridException("");
641
                }
642
        }
643

    
644
        /*
645
         *  (non-Javadoc)
646
         * @see org.gvsig.fmap.grid.IWritableGrid#multiply(double)
647
         */
648
        public void multiply(double value) throws GridException {
649
                boolean interp = (reader instanceof GridInterpolated);
650
                switchToInterpolationMethod(false);
651
                try{
652
                        switch(rasterBuf.getDataType()){
653
                        case IBuffer.TYPE_BYTE: for (int x = 0; x < getNX(); x++){
654
                                                                                for (int y = 0; y < getNY(); y++)
655
                                                                                        writer.setCellValue(x, y, (byte)(reader.getCellValueAsByte(x, y) * value));
656
                                                                        }
657
                                                                        break;
658
                        case IBuffer.TYPE_SHORT:for (int x = 0; x < getNX(); x++){
659
                                                                                for (int y = 0; y < getNY(); y++)
660
                                                                                        writer.setCellValue(x, y, (short)(reader.getCellValueAsShort(x, y) * value));
661
                                                                        }
662
                                                                        break;
663
                        case IBuffer.TYPE_INT:         for (int x = 0; x < getNX(); x++){
664
                                                                                for (int y = 0; y < getNY(); y++)
665
                                                                                        writer.setCellValue(x, y, (int)(reader.getCellValueAsInt(x, y) * value));
666
                                                                        }
667
                                                                        break;
668
                        case IBuffer.TYPE_FLOAT:for (int x = 0; x < getNX(); x++){
669
                                                                                for (int y = 0; y < getNY(); y++)
670
                                                                                        writer.setCellValue(x, y, (float)(reader.getCellValueAsFloat(x, y) * value));
671
                                                                        }
672
                                                                        break;
673
                        case IBuffer.TYPE_DOUBLE:for (int x = 0; x < getNX(); x++){
674
                                                                                for (int y = 0; y < getNY(); y++)
675
                                                                                        writer.setCellValue(x, y, (double)(reader.getCellValueAsDouble(x, y) * value));
676
                                                                        }
677
                                                                        break;
678
                        }
679
                } catch (RasterBufferInvalidException e) {
680
                        throw new GridException("");
681
                } catch (OutOfGridException e1) {
682
                        throw new GridException("");
683
                } catch (RasterBufferInvalidAccessException e) {
684
                        throw new GridException("");
685
                }
686
                //Restauramos el reader que hab?a
687
                switchToInterpolationMethod(interp);
688
        }
689

    
690
        /*
691
         *  (non-Javadoc)
692
         * @see org.gvsig.fmap.grid.IWritableGrid#setNoDataValue(double)
693
         */
694
        public void setNoDataValue(double dNoDataValue){
695
                writer.setNoDataValue((float) dNoDataValue);
696
        }
697

    
698
        /*
699
         *  (non-Javadoc)
700
         * @see org.gvsig.fmap.grid.IWritableGrid#setNoData(int, int)
701
         */
702
        public void setNoData(int x, int y){
703
                writer.setNoData(x,y);
704
        }
705

    
706
        public void ExportToArcViewASCIIFile(String sFilename){
707
                try {
708
                        writer.ExportToArcViewASCIIFile(sFilename);
709
                } catch (NumberFormatException e) {
710
                        e.printStackTrace();
711
                } catch (IOException e) {
712
                        e.printStackTrace();
713
                }
714
        }
715

    
716
        //************* Query Services *********************
717

    
718
        /*
719
         *  (non-Javadoc)
720
         * @see org.gvsig.fmap.grid.IQueryableGrid#isNoDataValue(double)
721
         */
722
        public boolean isNoDataValue(double noDataValue){
723
                return (reader.getNoDataValue() == noDataValue);
724
        }
725

    
726
        /*
727
         *  (non-Javadoc)
728
         * @see org.gvsig.fmap.grid.IQueryableGrid#isInGrid(int, int)
729
         */
730
        public boolean isInGrid(int x, int y){
731
                return reader.isCellInGrid(x, y);
732
        }
733

    
734
        /*
735
         *  (non-Javadoc)
736
         * @see org.gvsig.fmap.grid.IQueryableGrid#getCellSize()
737
         */
738
        public double getCellSize() {
739
                return reader.getCellSize();
740
        }
741

    
742
        /*
743
         *  (non-Javadoc)
744
         * @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsByte(int, int)
745
         */
746
        public byte getCellValueAsByte(int x, int y)throws GridException {
747
                try {
748
                        return  reader.getCellValueAsByte(x, y);
749
                } catch (RasterBufferInvalidAccessException e) {
750
                        throw new GridException("Position: (" + x + "," + y + ") not valid");
751
                } catch (RasterBufferInvalidException e) {
752
                        throw new GridException("Buffer not valid");
753
                }
754
        }
755

    
756
        /*
757
         *  (non-Javadoc)
758
         * @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsShort(int, int)
759
         */
760
        public short getCellValueAsShort(int x, int y)throws GridException {
761
                try {
762
                        return (short) reader.getCellValueAsShort(x, y);
763
                } catch (RasterBufferInvalidAccessException e) {
764
                        throw new GridException("Position: (" + x + "," + y + ") not valid");
765
                } catch (RasterBufferInvalidException e) {
766
                        throw new GridException("Buffer not valid");
767
                }
768
        }
769

    
770
        /*
771
         *  (non-Javadoc)
772
         * @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsInt(int, int)
773
         */
774
        public int getCellValueAsInt(int x, int y)throws GridException {
775
                try {
776
                        return (int) reader.getCellValueAsInt(x, y);
777
                } catch (RasterBufferInvalidAccessException e) {
778
                        throw new GridException("Position: (" + x + "," + y + ") not valid");
779
                } catch (RasterBufferInvalidException e) {
780
                        throw new GridException("Buffer not valid");
781
                }
782
        }
783

    
784
        /*
785
         *  (non-Javadoc)
786
         * @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsFloat(int, int)
787
         */
788
        public float getCellValueAsFloat(int x, int y)throws GridException {
789
                try {
790
                        return reader.getCellValueAsFloat(x, y);
791
                } catch (RasterBufferInvalidAccessException e) {
792
                        throw new GridException("Position: (" + x + "," + y + ") not valid");
793
                } catch (RasterBufferInvalidException e) {
794
                        throw new GridException("Buffer not valid");
795
                }
796
        }
797

    
798
        /*
799
         *  (non-Javadoc)
800
         * @see org.gvsig.fmap.grid.IQueryableGrid#getCellValueAsDouble(int, int)
801
         */
802
        public double getCellValueAsDouble(int x, int y)throws GridException {
803
                try {
804
                        return (double) reader.getCellValueAsDouble(x, y);
805
                } catch (RasterBufferInvalidAccessException e) {
806
                        throw new GridException("Position: (" + x + "," + y + ") not valid");
807
                } catch (RasterBufferInvalidException e) {
808
                        throw new GridException("Buffer not valid");
809
                }
810
        }
811

    
812
        /*
813
         *  (non-Javadoc)
814
         * @see org.gvsig.fmap.grid.IQueryableGrid#getNoDataValue()
815
         */
816
        public double getNoDataValue() {
817
                return (double) rasterBuf.getNoDataValue();
818
        }
819

    
820
        /*
821
         *  (non-Javadoc)
822
         * @see org.gvsig.fmap.grid.IQueryableGrid#getMinValue()
823
         */
824
        public double getMinValue() throws GridException {
825
                if (!statistic.isStatisticsCalculated())
826
                        statistic.calculateStatistics();
827
                return statistic.getMin();
828
        }
829

    
830
        /*
831
         *  (non-Javadoc)
832
         * @see org.gvsig.fmap.grid.IQueryableGrid#getMaxValue()
833
         */
834
        public double getMaxValue() throws GridException {
835
                if (!statistic.isStatisticsCalculated())
836
                        statistic.calculateStatistics();
837
                return statistic.getMax();
838
        }
839

    
840
        /*
841
         *  (non-Javadoc)
842
         * @see org.gvsig.fmap.grid.IQueryableGrid#getMeanValue()
843
         */
844
        public double getMeanValue() throws GridException {
845
                if (!statistic.isStatisticsCalculated())
846
                        statistic.calculateStatistics();
847
                return statistic.getMean();
848
        }
849

    
850
        /*
851
         *  (non-Javadoc)
852
         * @see org.gvsig.fmap.grid.IQueryableGrid#getVariance()
853
         */
854
        public double getVariance() throws GridException {
855
                if (!statistic.isStatisticsCalculated())
856
                        statistic.calculateStatistics();
857
                return statistic.getVariance();
858
        }
859

    
860
        /*
861
         *  (non-Javadoc)
862
         * @see org.gvsig.fmap.grid.IQueryableGrid#setInterpolationMethod(int)
863
         */
864
        public void setInterpolationMethod(int iMethod){
865
                if (reader instanceof GridInterpolated)
866
                        ((GridInterpolated) reader).setInterpolationMethod(iMethod);
867
                else{
868
                        this.switchToInterpolationMethod(true);
869
                        ((GridInterpolated) reader).setInterpolationMethod(iMethod);
870
                }
871
        }
872

    
873
        /*
874
         *  (non-Javadoc)
875
         * @see org.gvsig.fmap.grid.IQueryableGrid#getNX()
876
         */
877
        public int getNX(){
878
                return reader.getNX();
879
        }
880

    
881
        /*
882
         *  (non-Javadoc)
883
         * @see org.gvsig.fmap.grid.IQueryableGrid#getNY()
884
         */
885
        public int getNY(){
886
                return reader.getNY();
887
        }
888

    
889
        /*
890
         *  (non-Javadoc)
891
         * @see org.gvsig.fmap.grid.IQueryableGrid#getLayerNX()
892
         */
893
        public int getLayerNX(){
894
                return layerExtent.getNX();
895
        }
896

    
897
        /*
898
         *  (non-Javadoc)
899
         * @see org.gvsig.fmap.grid.IQueryableGrid#getLayerNY()
900
         */
901
        public int getLayerNY(){
902
                return layerExtent.getNY();
903
        }
904

    
905
        public int getDataType(){
906
                return dataType;
907
        }
908

    
909
        private boolean getSubMatrix3x3(int x, int y, double subMatrix[])
910
                throws GridException {
911
                int        i;
912
                int iDir;
913
                double        z, z2;
914

    
915
                z = getCellValueAsDouble(x, y);
916

    
917
                if(isNoDataValue(z)) {
918
                        return false;
919
                } else {
920
                        //SubMatrix[4]        = 0.0;
921
                        for(i = 0; i < 4; i++) {
922
                                iDir = 2 * i;
923
                                z2 = getCellValueAsDouble(x + m_iOffsetX[iDir], y + m_iOffsetY[iDir]);
924
                                if( !isNoDataValue(z2)){
925
                                        subMatrix[i] =  z2 - z;
926
                                } else {
927
                                        z2 = getCellValueAsDouble(x + m_iOffsetX[(iDir + 4) % 8], y + m_iOffsetY[(iDir  + 4) % 8]);
928
                                        if( !isNoDataValue(z2)) {
929
                                                subMatrix[i] = z - z2;
930
                                        } else {
931
                                                subMatrix[i] = 0.0;
932
                                        }
933
                                }
934
                        }
935

    
936
                        return true;
937
                }
938
        }
939

    
940
        /*
941
         * (non-Javadoc)
942
         * @see org.gvsig.raster.grid.IQueryableGrid#getSlope(int, int)
943
         */
944
        public double getSlope(int x, int y)throws GridException {
945
                double        zm[], G, H;
946

    
947
                zm = new double[4];
948

    
949
                try {
950
                        if( getSubMatrix3x3(x, y, zm) ) {
951
                                G = (zm[0] - zm[2]) / _2DX;
952
                                H = (zm[1] - zm[3]) / _2DX;
953
                                return Math.atan(Math.sqrt(G * G + H * H));
954
                        }
955
                        else {
956
                                return rasterBuf.getNoDataValue();
957
                        }
958
                } catch (GridException e) {
959
                        throw new GridException("Problems accesing 3x3 submatrix");
960
                }
961
        }
962

    
963
        /*
964
         * (non-Javadoc)
965
         * @see org.gvsig.raster.grid.IQueryableGrid#getAspect(int, int)
966
         */
967
        public double getAspect(int x, int y)throws GridException {
968
                double        zm[], G, H, dAspect;
969
                zm = new double[4];
970

    
971
                try {
972
                        if( getSubMatrix3x3(x, y, zm) ) {
973
                                G = (zm[0] - zm[2]) / _2DX;
974
                                H = (zm[1] - zm[3]) / _2DX;
975
                                if(G != 0.0)
976
                                        dAspect = DEG_180_IN_RAD + Math.atan2(H, G);
977
                                else
978
                                        dAspect = H > 0.0 ? DEG_270_IN_RAD : (H < 0.0 ? DEG_90_IN_RAD : -1.0);
979
                                return dAspect;
980
                        }
981
                        else
982
                                return rasterBuf.getNoDataValue();
983
                } catch (GridException e) {
984
                        throw new GridException("Problems accesing 3x3 submatrix");
985
                }
986
        }
987

    
988
        public static int getXOffsetInDir(int iDir){
989
                return m_iOffsetX[iDir];
990
        }
991

    
992
        public static int getYOffsetInDir(int iDir){
993
                return m_iOffsetY[iDir];
994
        }
995

    
996
        public double getDistToNeighborInDir(int iDir){
997
                return m_dDist[iDir];
998
        }
999

    
1000
        public static double getUnitDistToNeighborInDir(int iDir){
1001
                return( (iDir % 2 != 0) ? Math.sqrt(2.0)  : 1.0 );
1002
        }
1003

    
1004
        /*
1005
         *  (non-Javadoc)
1006
         * @see org.gvsig.fmap.grid.IQueryableGrid#getDirToNextDownslopeCell(int, int)
1007
         */
1008
        public int getDirToNextDownslopeCell(int x, int y)throws GridException{
1009
                return getDirToNextDownslopeCell(x, y, true);
1010
        }
1011

    
1012
        /*
1013
         *  (non-Javadoc)
1014
         * @see org.gvsig.fmap.grid.IQueryableGrid#getDirToNextDownslopeCell(int, int, boolean)
1015
         */
1016
        public int getDirToNextDownslopeCell(int x, int y, boolean bForceDirToNoDataCell)
1017
                throws GridException{
1018

    
1019
                int                i, iDir;
1020
                double        z, z2, dSlope, dMaxSlope;
1021

    
1022
                z = getCellValueAsDouble(x, y);
1023

    
1024
                if(isNoDataValue(z)){
1025
                        return -1;
1026
                }
1027

    
1028
                dMaxSlope = 0.0;
1029
                for(iDir=-1, i=0; i<8; i++) {
1030
                        z2 = getCellValueAsDouble(x + m_iOffsetX[i], y + m_iOffsetY[i]);
1031
                        if(isNoDataValue(z2)) {
1032
                                if (bForceDirToNoDataCell) {
1033
                                        return i;
1034
                                }
1035
                                else {
1036
                                        return -1;
1037
                                }
1038
                        }
1039
                        else {
1040
                                dSlope        = (z - z2) / getDistToNeighborInDir(i);
1041
                                if( dSlope > dMaxSlope ) {
1042
                                        iDir = i;
1043
                                        dMaxSlope = dSlope;
1044
                                }
1045
                        }
1046
                }
1047
                return iDir;
1048
        }
1049

    
1050
        public GridCell[] getSortedArrayOfCells()throws GridException{
1051
                int i;
1052
                int iX,iY;
1053
                int iNX =  getNX();
1054
                int iCells = getNX() * getNY();
1055
                GridCell [] cells = null;
1056
                GridCell cell = null;
1057

    
1058
                cells = new GridCell[iCells];
1059

    
1060
                for (i = 0; i < iCells; i++) {
1061
                        iX = i % iNX;
1062
                        iY = i / iNX;
1063
                        switch(getDataType()){
1064
                        case IBuffer.TYPE_BYTE: cell = new GridCell(iX, iY, getCellValueAsByte(iX, iY)); break;
1065
                        case IBuffer.TYPE_SHORT: cell = new GridCell(iX, iY, getCellValueAsShort(iX, iY)); break;
1066
                        case IBuffer.TYPE_INT: cell = new GridCell(iX, iY, getCellValueAsInt(iX, iY)); break;
1067
                        case IBuffer.TYPE_FLOAT: cell = new GridCell(iX, iY, getCellValueAsFloat(iX, iY)); break;
1068
                        case IBuffer.TYPE_DOUBLE: cell = new GridCell(iX, iY, getCellValueAsDouble(iX, iY)); break;
1069
                        }
1070

    
1071
                        cells[i] = cell;
1072
                }
1073

    
1074
                Arrays.sort(cells);
1075

    
1076
                return cells;
1077
        }
1078

    
1079
        /**
1080
         * Obtiene la paleta para el caso de un MDT. Esta funci?n evita el tener que obtener
1081
         * un array de paletas y buscar en el cuando se trata de un caso simple de MDT de una
1082
         * sola banda. Comprueba que se trata de un raster monobanda con paleta asociada antes
1083
         * de devolverla.
1084
         * @return GridPalette asociada al Grid
1085
         */
1086
        public GridPalette        getMDTPalette() {
1087
                if(        rasterBuf != null &&
1088
                        rasterBuf.getBandCount() == 1 &&
1089
                        palette != null)
1090
                        return palette[0];
1091
                return null;
1092
        }
1093

    
1094
        /**
1095
         * Obtiene la lista de paletas asociadas al grid
1096
         * @return Lista de objetos GridPalette
1097
         */
1098
        public GridPalette[] getPalettes() {
1099
                return palette;
1100
        }
1101

    
1102
        /**
1103
         * Obtiene el n?mero de bandas del grid o 0 si no tiene buffer de
1104
         * datos asociado.
1105
         * @return N?mero de bandas
1106
         */
1107
        public int getBandCount() {
1108
                if(rasterBuf != null)
1109
                        return rasterBuf.getBandCount();
1110
                return 0;
1111
        }
1112

    
1113
        /**
1114
         * Asigna la lista de paletas asociadas al grid
1115
         * @param palette Lista de objetos GridPalette
1116
         */
1117
        public void setPalettes(GridPalette[] palette) {
1118
                this.palette = palette;
1119
        }
1120

    
1121
        /**
1122
         * Obtiene la lista de filtros.
1123
         * @return Lista de filtros.
1124
         */
1125
        public RasterFilterList getFilterList(){
1126
                return filterList;
1127
        }
1128

    
1129
        /**
1130
         * Asigna la lista de filtros
1131
         * @param filterList
1132
         */
1133
        public void setFilterList(RasterFilterList filterList) {
1134
                this.filterList = filterList;
1135
        }
1136

    
1137
        /**
1138
         *Aplica la lista de filtros sobre el buffer
1139
         * @throws InterruptedException
1140
         */
1141
        public void applyFilters() throws InterruptedException {
1142
                if (filterList == null)
1143
                        return;
1144

    
1145
                filterList.setInitRasterBuf(rasterBuf);
1146
                
1147
                filterList.getEnv().put("GridExtent", getGridExtent());
1148
                filterList.getEnv().put("WindowExtent", getWindowExtent());
1149
                
1150
                filterList.execute();
1151
                rasterBuf = (RasterBuffer) filterList.getResult();
1152
                dataType = rasterBuf.getDataType();
1153
        }
1154

    
1155
        /**
1156
         * Obtiene el buffer de datos del grid
1157
         * @return RasterBuf
1158
         */
1159
        public IBuffer getRasterBuf() {
1160
                return rasterBuf;
1161
        }
1162

    
1163
        /**
1164
         * Asigna la banda sobre la que se realizan las operaciones. Por defecto es la banda 0
1165
         * con lo que para el uso de MDTs no habr? que modificar este valor.
1166
         * @param band Banda sobre la que se realizan las operaciones.
1167
         */
1168
        public void setBandToOperate(int band) {
1169
                if(writer != null)
1170
                        writer.setBandToOperate(band);
1171
                if(reader != null)
1172
                        reader.setBandToOperate(band);
1173
                if(statistic != null)
1174
                        statistic.setBandToOperate(band);
1175
        }
1176

    
1177
        /**
1178
         * Obtiene el extent de la ventana seleccionada para petici?n de datos
1179
         * @return GridExtent
1180
         */
1181
        public GridExtent getWindowExtent() {
1182
                return windowExtent;
1183
        }
1184

    
1185
        /**
1186
         * Obtiene el extent del grid para petici?n de datos
1187
         * @return GridExtent
1188
         */
1189
        public GridExtent getGridExtent() {
1190
                return layerExtent;
1191
        }
1192
}