Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / store / DefaultMosaicRasterStore.java @ 223

History | View | Annotate | Download (55.8 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.impl.store;
23

    
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.NoninvertibleTransformException;
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28
import java.io.IOException;
29
import java.util.ArrayList;
30

    
31
import org.cresques.cts.IProjection;
32
import org.gvsig.fmap.dal.coverage.RasterLibrary;
33
import org.gvsig.fmap.dal.coverage.RasterLocator;
34
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
35
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
36
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
37
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
38
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
39
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
40
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
41
import org.gvsig.fmap.dal.coverage.exception.MosaicNotValidException;
42
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
43
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
44
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
45
import org.gvsig.fmap.dal.coverage.grid.render.TileListener;
46
import org.gvsig.fmap.dal.coverage.store.MosaicRasterStore;
47
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
48
import org.gvsig.fmap.dal.coverage.store.RasterStoreParameters;
49
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
50
import org.gvsig.fmap.dal.coverage.store.props.Histogram;
51
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
52
import org.gvsig.fmap.dal.coverage.store.props.SerialInfo;
53
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
54
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
55
import org.gvsig.fmap.dal.coverage.util.MathUtils;
56
import org.gvsig.fmap.dal.coverage.util.RasterUtils;
57
import org.gvsig.fmap.dal.exception.CloseException;
58
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider;
59
import org.gvsig.metadata.exceptions.MetadataException;
60
import org.gvsig.raster.impl.DefaultRasterManager;
61
import org.gvsig.raster.impl.datastruct.BandListImpl;
62
import org.gvsig.raster.impl.datastruct.ExtentImpl;
63
import org.gvsig.raster.impl.provider.RasterProvider;
64
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
65
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
66
import org.gvsig.raster.impl.store.properties.MosaicDataStoreHistogram;
67
import org.gvsig.raster.impl.store.properties.MosaicDataStoreStatistics;
68
/**
69
 * Esta clase est? compuestas de multiples datasets formando una rejilla de NxM
70
 * rasters. Un cliente de esta clase debe tener una visi?n de la rejilla como si
71
 * fuese un solo raster, gestionando esta el acceso la imagen que corresponda en
72
 * cada petici?n de usuario.
73
 *
74
 * @version 29/08/2007
75
 * @author Nacho Brodin (nachobrodin@gmail.com)
76
 */
77
public class DefaultMosaicRasterStore extends AbstractRasterDataStore implements MosaicRasterStore {
78
        private RasterDataStore[][]           mosaic        = null;
79
        private Statistics                    stats         = null;
80
        private BandListImpl                  bandList      = null;
81
        private boolean                       readOnly      = false;
82
        /**
83
         * Flag que fuerza al buffer en memoria
84
         */            
85
        private boolean                       forceToMemory = false;
86
        private int                           percent       = 0;
87

    
88
        /**
89
         * Constructor vacio
90
         */
91
        public DefaultMosaicRasterStore() {
92
                bandList = new BandListImpl();
93
        }
94
        
95
        /**
96
         * Constructor. Genera la estructura de n filas por n columnas de rasters.
97
         * @param n N?mero de filas
98
         * @param m N?mero de columnas
99
         */
100
        public DefaultMosaicRasterStore(int n, int m) {
101
                bandList = new BandListImpl();
102
                if(n != 0 && m != 0)
103
                        mosaic = new DefaultMultiRasterStore[n][m];
104
        }
105

    
106
        /**
107
         * Constructor. Genera la estructura de n filas por n columnas de rasters y
108
         * las asigna a los raster que se le pasan por par?metro.
109
         * @param n N?mero de filas
110
         * @param m N?mero de columnas
111
         */
112
        public DefaultMosaicRasterStore(RasterDataStore[][] mos) throws MosaicNotValidException {
113
                bandList = new BandListImpl();
114
                this.mosaic = deleteNullValues(mos);
115
                init();
116
        }
117

    
118
        /**
119
         * M?todo que elimina crea un array bidimensional eliminando los nulos del que tiene
120
         * el que se le pasa por par?metro
121
         * @param values
122
         * @return MultiRasterDataset
123
         */
124
        private RasterDataStore[][] deleteNullValues(RasterDataStore[][] values) {
125
                if(mosaic == null)
126
                        return null;
127
                int n = values.length;
128
                int m = values[0].length;
129
                int posInitX = 0;
130
                int posInitY = 0;
131

    
132
                int nRows = n, nCols = m;
133
                //Contador de filas
134
                boolean first = true;
135
                for (int row = 0; row < n; row++) {
136
                        boolean isNull = true;
137
                        for (int col = 0; col < m; col++)
138
                                if(values[row][col] != null) {
139
                                        isNull = false;
140
                                        if(first) {
141
                                                posInitX = col;
142
                                                first = false;
143
                                        }
144
                                }
145
                        if(isNull)
146
                                nRows --;
147
                }
148

    
149
                //Contador de columnas
150
                first = true;
151
                for (int col = 0; col < m; col++) {
152
                        boolean isNull = true;
153
                        for (int row = 0; row < n; row++)
154
                                if(values[row][col] != null) {
155
                                        isNull = false;
156
                                        if(first) {
157
                                                posInitY = row;
158
                                                first = false;
159
                                        }
160
                                }
161
                        if(isNull)
162
                                nCols --;
163
                }
164
                //Copia de datos
165
                RasterDataStore[][] result = new DefaultMultiRasterStore[nRows][nCols];
166

    
167
                for (int row = 0; row < result.length; row++)
168
                        for (int col = 0; col < result[row].length; col++)
169
                                result[row][col] = values[row + posInitY][col + posInitX];
170
                return result;
171
        }
172
        
173
        /*
174
         * (non-Javadoc)
175
         * @see org.gvsig.fmap.dal.DataStore#getName()
176
         */
177
        public String getName() {
178
                if(mosaic != null && mosaic.length >= 1 && mosaic[0].length >= 1)  
179
                        return mosaic[0][0].getName();
180
                return null;
181
        }
182
        
183
        /*
184
         * (non-Javadoc)
185
         * @see org.gvsig.raster.impl.dataset.QueryableRaster#getProviders()
186
         */
187
        public ArrayList<RasterProvider> getProviders() {
188
                if(mosaic == null)
189
                        return null;
190
                ArrayList<RasterProvider> list = new ArrayList<RasterProvider>();
191
                int n = mosaic.length;
192
                int m = mosaic[0].length;
193
                for (int row = 0; row < n; row++) {
194
                        for (int col = 0; col < m; col++) {
195
                                list.add(((QueryableRaster)mosaic[row][col]).getProviders().get(0));
196
                        }
197
                }
198
                return list;
199
        }
200
        
201
        /*
202
         * (non-Javadoc)
203
         * @see org.gvsig.raster.impl.dataset.QueryableRaster#getProvider(int)
204
         */
205
        public RasterProvider getProvider(int i) {
206
                if(mosaic == null)
207
                        return null;
208
                return ((QueryableRaster)mosaic[i / mosaic.length][i % mosaic[0].length]).getProvider(i);
209
        }
210
        
211
        /*
212
         * (non-Javadoc)
213
         * @see org.gvsig.raster.impl.dataset.QueryableRaster#getDrawableBands()
214
         */
215
        public int[] getDrawableBands() {
216
                return getBands().getDrawableBands();
217
        }
218

    
219
        /**
220
         * Valida que los extends del mosaico sean validos, es decir, que sean correlativos
221
         * formando la matriz. Adem?s tambi?n valida que el tama?o de pixel coincida en todos los
222
         * raster que forman el mosaico.
223
         *
224
         * @param mos
225
         * @throws MosaicNotValidException
226
         */
227
        public boolean validateMosaic() {
228
                if(mosaic == null)
229
                        return false;
230
                MathUtils math = RasterLocator.getManager().getMathUtils();
231
                int n = mosaic.length;
232
                int m = mosaic[0].length;
233
                //Comprobamos en Horizontal
234
                if(m > 1)
235
                        for (int row = 0; row < n; row++)
236
                                for (int col = 0; col < m; col++)
237
                                        if(col < (m - 1) && mosaic[row][col] != null) {
238
                                                Extent a = mosaic[row][col].getExtent();
239
                                                Extent b = mosaic[row][col + 1].getExtent();
240
                                                if(((int)a.maxX()) != ((int)b.minX()))
241
                                                        return false;
242
                                                double psx = math.clipDecimals(mosaic[row][col].getPixelSizeX(), 2);
243
                                                double psx1 = math.clipDecimals(mosaic[row][col + 1].getPixelSizeX(), 2);
244
                                                double psy = math.clipDecimals(mosaic[row][col].getPixelSizeY(), 2);
245
                                                double psy1 = math.clipDecimals(mosaic[row][col + 1].getPixelSizeY(), 2);
246
                                                if(psx != psx1 || psy != psy1)
247
                                                        return false;
248
                                                if(mosaic[row][col].getBandCount() != mosaic[row][col + 1].getBandCount())
249
                                                        return false;
250
                                        }
251

    
252
                //Comprobamos en Vertical
253
                if(n > 1)
254
                        for (int col = 0; col < m; col++)
255
                                for (int row = 0; row < n; row++)
256
                                        if(row < (n - 1) && mosaic[row][col] != null) {
257
                                                Extent a = mosaic[row][col].getExtent();
258
                                                Extent b = mosaic[row + 1][col].getExtent();
259
                                                if(((int)a.minY()) != ((int)b.maxY()))
260
                                                        return false;
261
                                                double psx = math.clipDecimals(mosaic[row][col].getPixelSizeX(), 2);
262
                                                double psx1 = math.clipDecimals(mosaic[row + 1][col].getPixelSizeX(), 2);
263
                                                double psy = math.clipDecimals(mosaic[row][col].getPixelSizeY(), 2);
264
                                                double psy1 = math.clipDecimals(mosaic[row + 1][col].getPixelSizeY(), 2);
265
                                                if(psx != psx1 || psy != psy1)
266
                                                        return false;
267
                                                if(mosaic[row][col].getBandCount() != mosaic[row + 1][col].getBandCount())
268
                                                        return false;
269
                                        }
270

    
271
                return true;
272
        }
273
        
274
        public void addDataStore(RasterDataStore store) {
275
                if(store == null)
276
                        return;
277
                
278
                //Si no hay ninguno se a?ade
279
                if (mosaic == null) {
280
                        mosaic = new RasterDataStore[1][1];
281
                        mosaic[0][0] = store;
282
                        return;
283
                }
284
                
285
                //Si hay m?s de uno se inserta
286
                MathUtils math = RasterLocator.getManager().getMathUtils();
287
                int n = mosaic.length;
288
                int m = mosaic[0].length;
289
                Extent ext = store.getExtent();
290
                int posXMatrix = 0;
291
                int posYMatrix = 0;
292
                double ulx = math.clipDecimals(ext.getULX(), 1);
293
                double uly = math.clipDecimals(ext.getULY(), 1);
294
                double urx = math.clipDecimals(ext.getURX(), 1);
295
                double ury = math.clipDecimals(ext.getURY(), 1);
296
                double llx = math.clipDecimals(ext.getLLX(), 1);
297
                double lly = math.clipDecimals(ext.getLLY(), 1);
298
                double lrx = math.clipDecimals(ext.getLRX(), 1);
299
                double lry = math.clipDecimals(ext.getLRY(), 1);
300
                
301
                //Para cada tile ya colocado miramos si va en alguna de sus 8 posiciones 
302
                //posibles alrededor
303
                for (int row = 0; row < n; row++) {
304
                        for (int col = 0; col < m; col++) {
305
                                if(mosaic[row][col] == null)
306
                                        continue;
307
                                double urxLocal = math.clipDecimals(mosaic[row][col].getExtent().getURX(), 1);
308
                                double uryLocal = math.clipDecimals(mosaic[row][col].getExtent().getURY(), 1);
309
                                double ulxLocal = math.clipDecimals(mosaic[row][col].getExtent().getULX(), 1);
310
                                double ulyLocal = math.clipDecimals(mosaic[row][col].getExtent().getULY(), 1);
311
                                double lrxLocal = math.clipDecimals(mosaic[row][col].getExtent().getLRX(), 1);
312
                                double lryLocal = math.clipDecimals(mosaic[row][col].getExtent().getLRY(), 1);
313
                                double llxLocal = math.clipDecimals(mosaic[row][col].getExtent().getLLX(), 1);
314
                                double llyLocal = math.clipDecimals(mosaic[row][col].getExtent().getLLY(), 1);
315
                                
316
                                if(ulx == urxLocal && uly == uryLocal) {
317
                                        posXMatrix = col + 1;
318
                                        posYMatrix = row;
319
                                }
320
                                if(ulx == lrxLocal && uly == lryLocal) {
321
                                        posXMatrix = col + 1;
322
                                        posYMatrix = row + 1;
323
                                }
324
                                
325
                                if(ulx == llxLocal && uly == llyLocal) {
326
                                        posXMatrix = col;
327
                                        posYMatrix = row + 1;
328
                                }
329
                                
330
                                if(urx == llxLocal && ury == llyLocal) {
331
                                        posXMatrix = col - 1;
332
                                        posYMatrix = row + 1;
333
                                }
334
                                
335
                                if(urx == ulxLocal && ury == ulyLocal) {
336
                                        posXMatrix = col - 1;
337
                                        posYMatrix = row;
338
                                }
339
                                
340
                                if(lrx == ulxLocal && lry == ulyLocal) {
341
                                        posXMatrix = col - 1;
342
                                        posYMatrix = row - 1;
343
                                }
344
                                
345
                                if(llx == ulxLocal && lly == ulyLocal) {
346
                                        posXMatrix = col;
347
                                        posYMatrix = row - 1;
348
                                }
349
                                
350
                                if(llx == urxLocal && lly == uryLocal) {
351
                                        posXMatrix = col + 1;
352
                                        posYMatrix = row - 1;
353
                                }
354
                                
355
                        }
356
                }
357
                
358
                int newWidth = 0;
359
                if(posXMatrix < 0)
360
                        newWidth = m + 1;
361
                else
362
                        newWidth = Math.max(n, posXMatrix + 1);
363
                
364
                int newHeight = 0;
365
                if(posYMatrix < 0)
366
                        newHeight = n + 1;
367
                else
368
                        newHeight = Math.max(m, posYMatrix + 1);
369
                
370
                RasterDataStore[][] newMosaic = new RasterDataStore[newWidth][newHeight];
371
                newMosaic[posXMatrix < 0 ? 0 : posXMatrix][posYMatrix < 0 ? 0 : posYMatrix] = store;
372
                int rowMosaic = 0;
373
                int colMosaic = 0;
374
                for (int row = posYMatrix < 0 ? 1 : 0; row < n; row++) {
375
                        for (int col = posXMatrix < 0 ? 1 : 0; col < m; col++) {
376
                                newMosaic[row][col] = mosaic[rowMosaic][colMosaic];
377
                                colMosaic ++;
378
                        }
379
                        rowMosaic++;
380
                }
381
                mosaic = newMosaic;
382
        }
383

    
384
        /*
385
         * (non-Javadoc)
386
         * @see org.gvsig.raster.dataset.IRasterDataSource#addDataset(org.gvsig.raster.dataset.RasterDataset[])
387
         */
388
        /*public void addDataset(RasterDataStore[] f) throws FileNotFoundInListException, OperationNotSupportedException, InvalidSourceException {
389
                if(mosaic != null) {
390
                        int n = mosaic.length;
391
                        int m = mosaic[0].length;
392
                        if(f.length == (n * m))
393
                                for (int i = 0; i < n; i++)
394
                                        for (int j = 0; j < m; j++) {
395
                                                MultiRasterStore mrd = new DefaultMultiRasterStore();
396
                                                mrd.addDataStore(f[i * n + j]);
397
                                        }
398
                        init();
399
                }
400
        }*/
401

    
402
        /*
403
         * (non-Javadoc)
404
         * @see org.gvsig.raster.dataset.IRasterDataSource#addDataset(java.lang.String[])
405
         */
406
        /*public void addDataset(String[] fileName) throws FileNotFoundInListException, NotSupportedExtensionException, RasterDriverException, OperationNotSupportedException {
407
                if(mosaic != null) {
408
                        int n = mosaic.length;
409
                        int m = mosaic[0].length;
410
                        if(fileName.length == (n * m))
411
                                for (int i = 0; i < n; i++)
412
                                        for (int j = 0; j < m; j++) {
413
                                                MultiRasterStore mrd = new DefaultMultiRasterStore();
414
                                                try {
415
                                                        mrd.addDataStore(DefaultRasterManager.getInstance().open(fileName[i * n + j]));
416
                                                } catch (InvalidSourceException e) {
417
                                                }
418
                                        }
419
                        init();
420
                }
421
        }*/
422

    
423
        /**
424
         * Acciones de inicializaci?n cuando se crea el objeto o se
425
         * a?aden nuevos dataset a este
426
         */
427
        private void init() {
428
                stats = new MosaicDataStoreStatistics(mosaic);
429

    
430
                //Creamos la lista de bandas
431
                bandList = (BandListImpl)((BandListImpl)mosaic[0][0].getBands()).clone();
432
                int n = mosaic.length;
433
                int m = mosaic[0].length;
434
                for (int row = 0; row < n; row++)
435
                        for (int col = 0; col < m; col++) {
436
                                if(row != 0 && col != 0) {
437
                                        for (int i = 0; i < mosaic[0][0].getBandCount(); i++) {
438
                                                if(mosaic[row][col] != null) {
439
                                                        bandList.getBand(i).setAdditionalName(mosaic[row][col].getBands().getBand(i).getFileName());
440
                                                }
441
                                        }
442
                                }
443
                        }
444
        }
445

    
446
        /**
447
         * Obtiene la lista de nombres de los dataset
448
         * @return
449
         */
450
        public String[][] getFileNames() {
451
                if(mosaic == null)
452
                        return null;
453
                String[][] s = new String[mosaic.length][mosaic[0].length];
454
                for (int i = 0; i < s.length; i++)
455
                        for (int j = 0; j < s[i].length; j++)
456
                                if(mosaic[i][j] != null)
457
                                        s[i][j] = ((RasterStoreParameters)mosaic[i][j].getParameters()).getURI();
458
                return s;
459
        }
460

    
461
        /*
462
         * (non-Javadoc)
463
         * @see org.gvsig.raster.impl.dataset.QueryableRaster#calcSteps(double, double, double, double, double, double, int, int)
464
         */
465
        public double[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY, double nWidth, double nHeight, int bufWidth, int bufHeight) {
466
                if(mosaic != null && mosaic[0][0] != null)
467
                        return ((QueryableRaster)mosaic[0][0]).calcSteps(dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, nWidth, nHeight, bufWidth, bufHeight);
468
                return null;
469
        }
470

    
471
        /*
472
         * (non-Javadoc)
473
         * @see org.gvsig.fmap.dal.raster.impl.DefaultCoverageStore#close()
474
         */
475
        public void close() throws CloseException {
476
                if(mosaic == null)
477
                        return;
478
                int n = mosaic.length;
479
                int m = mosaic[0].length;
480
                for (int row = 0; row < n; row++)
481
                        for (int col = 0; col < m; col++)
482
                                if(mosaic[row][col] != null) {
483
                                        mosaic[row][col].close();
484
                                        mosaic[row][col] = null;
485
                                }
486
                mosaic = null;
487
                bandList.clear();
488
                bandList = null;
489
        }
490

    
491
        /*
492
         * (non-Javadoc)
493
         * @see org.gvsig.raster.dataset.IRasterDataSource#copy()
494
         */
495
        public RasterDataStore newDataStore() {
496
                if(mosaic == null)
497
                        return null;
498
                int n = mosaic.length;
499
                int m = mosaic[0].length;
500
                RasterDataStore[][] mrd = new RasterDataStore[n][m];
501
                for (int row = 0; row < n; row++)
502
                        for (int col = 0; col < m; col++)
503
                                if(mosaic[row][col] != null)
504
                                        mrd[row][col] = mosaic[row][col].newDataStore();
505

    
506
                try {
507
                        return new DefaultMosaicRasterStore(mrd);
508
                } catch (MosaicNotValidException e) {
509
                        return null;
510
                }
511
        }
512

    
513
        /*
514
         * (non-Javadoc)
515
         * @see org.gvsig.raster.dataset.IRasterDataSource#getOwnAffineTransform()
516
         */
517
        public AffineTransform getOwnAffineTransform() {
518
                if(mosaic != null && mosaic[0][0] != null)
519
                        return mosaic[0][0].getOwnAffineTransform();
520
                return new AffineTransform();
521
        }
522

    
523
        /*
524
         * (non-Javadoc)
525
         * @see org.gvsig.raster.dataset.IRasterDataSource#getAffineTransform()
526
         */
527
        public AffineTransform getAffineTransform() {
528
                if(mosaic != null && mosaic[0][0] != null)
529
                        return mosaic[0][0].getAffineTransform();
530
                return new AffineTransform();
531
        }
532

    
533
        /*
534
         * (non-Javadoc)
535
         * @see org.gvsig.raster.dataset.IRasterDataSource#getExtent()
536
         */
537
        public Extent getExtent() {
538
                if(mosaic == null)
539
                        return null;
540
                int n = mosaic.length;
541
                int m = mosaic[0].length;
542

    
543
                double ulx = 0;
544
                double uly = 0;
545
                double urx = 0;
546
                double ury = 0;
547
                double llx = 0;
548
                double lly = 0;
549
                double lrx = 0;
550
                double lry = 0;
551

    
552
                int i = 0;
553
                int j = 0;
554
                while(mosaic[i][j] == null) 
555
                        j++; 
556
                ulx = mosaic[i][j].getExtent().getULX();
557

    
558
                i = j = 0;
559
                while(mosaic[i][j] == null) 
560
                        i++;
561
                uly = mosaic[i][j].getExtent().getULY();
562

    
563
                i = n - 1;
564
                j = 0;
565
                while(mosaic[i][j] == null) 
566
                        j++;
567
                urx = mosaic[i][j].getExtent().getURX();
568

    
569
                i = n - 1;
570
                j = 0;
571
                while(mosaic[i][j] == null) 
572
                        i--;
573
                ury = mosaic[i][j].getExtent().getURY();
574

    
575
                i = 0;
576
                j = m - 1;
577
                while(mosaic[i][j] == null) 
578
                        j--;
579
                llx = mosaic[i][j].getExtent().getLLX();
580

    
581
                i = 0;
582
                j = m - 1;
583
                while(mosaic[i][j] == null) 
584
                        i++;
585
                lly = mosaic[i][j].getExtent().getLLY();
586

    
587
                i = n - 1;
588
                j = m - 1;
589
                while(mosaic[i][j] == null) 
590
                        j--;
591
                lrx = mosaic[i][j].getExtent().getLRX();
592

    
593
                i = n - 1;
594
                j = m - 1;
595
                while(mosaic[i][j] == null) 
596
                        i--;
597
                lry = mosaic[i][j].getExtent().getLRY();
598

    
599

    
600
                return new ExtentImpl(        new Point2D.Double(ulx, uly),
601
                                new Point2D.Double(lrx, lry),
602
                                new Point2D.Double(urx, ury),
603
                                new Point2D.Double(llx, lly));
604
        }
605

    
606
        /*
607
         * (non-Javadoc)
608
         * @see org.gvsig.raster.dataset.IRasterDataSource#getBandCount()
609
         */
610
        public int getBandCount() {
611
                if(mosaic != null && mosaic[0][0] != null)
612
                        return mosaic[0][0].getBandCount();
613
                return 0;
614
        }
615

    
616
        /*
617
         * (non-Javadoc)
618
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getWidth()
619
         */
620
        public double getWidth() {
621
                double wReal = (getExtent().getMax().getX() - getExtent().getMin().getX());
622
                return wReal / getPixelSizeY();
623
        }
624

    
625
        /*
626
         * (non-Javadoc)
627
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getHeight()
628
         */
629
        public double getHeight() {
630
                double hReal = (getExtent().getMax().getY() - getExtent().getMin().getY());
631
                return hReal / getPixelSizeX();
632
        }
633

    
634
        /*
635
         * (non-Javadoc)
636
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getCellSize()
637
         */
638
        public double getCellSize() {
639
                try {
640
                        Extent e = getExtent();
641
                        double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / getWidth();
642
                        return dCellsize;
643
                } catch (NullPointerException e) {
644
                        return 1;
645
                }
646
        }
647

    
648
        /*
649
         * (non-Javadoc)
650
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getDataType()
651
         */
652
        public int[] getDataType() {
653
                if(mosaic != null && mosaic[0][0] != null)
654
                        return mosaic[0][0].getDataType();
655
                return null;
656
        }
657

    
658
        /*
659
         * (non-Javadoc)
660
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getDataStoreCount()
661
         */
662
        public int getDataStoreCount() {
663
                if(mosaic != null && mosaic[0][0] != null)
664
                        return mosaic[0][0].getDataStoreCount();
665
                return 0;
666
        }
667

    
668
        /*
669
         * (non-Javadoc)
670
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getFileSize()
671
         */
672
        public long getFileSize() {
673
                if(mosaic == null)
674
                        return 0;
675
                long size = 0;
676
                int n = mosaic.length;
677
                int m = mosaic[0].length;
678
                for (int row = 0; row < n; row++)
679
                        for (int col = 0; col < m; col++)
680
                                if(mosaic[row][col] != null)
681
                                        size += mosaic[row][col].getFileSize();
682
                return size;
683
        }
684

    
685
        /**
686
         * Obtiene el dataset cuyas coordenadas contienen el punto pasado por par?meto
687
         * @param x Coordenada X a comprobar
688
         * @param y Coordenada Y a comprobar
689
         * @return Point2D Posici?n del MultiRasterDataset dentro del mosaico
690
         */
691
        public Point2D getDatasetByCoords(double x, double y) {
692
                if(mosaic == null)
693
                        return null;
694
                RasterUtils util = RasterLocator.getManager().getRasterUtils();
695
                int n = mosaic.length;
696
                int m = mosaic[0].length;
697
                for (int row = 0; row < n; row++)
698
                        for (int col = 0; col < m; col++)
699
                                if(mosaic[row][col] != null &&
700
                                                util.isInside(new Point2D.Double(x, y), mosaic[row][col].getExtent(), mosaic[row][col].getAffineTransform()))
701
                                        return new Point2D.Double(row, col);
702

    
703
                return null;
704
        }
705

    
706
        /**
707
         * Obtiene la lista de datasets del mosaico que intersectan con el extent proporcionado
708
         * @param ulx Coordenada X superior izquierda
709
         * @param uly Coordenada Y superior izquierda
710
         * @param lrx Coordenada X inferior derecha
711
         * @param lry Coordenada Y inferior derecha
712
         * @return QueryableRaster[][][]
713
         * @throws NoninvertibleTransformException
714
         */
715
        private QueryableRaster[][] getDatasetListInArea(double ulx, double uly, double lrx, double lry) throws NoninvertibleTransformException {
716
                if(mosaic == null)
717
                        return null;
718
                RasterUtils util = RasterLocator.getManager().getRasterUtils();
719
                int n = mosaic.length;
720
                int m = mosaic[0].length;
721

    
722
                QueryableRaster[][] result = new QueryableRaster[n][m];
723

    
724
                for (int row = 0; row < n; row++)
725
                        for (int col = 0; col < m; col++)
726
                                if(mosaic[row][col] != null &&
727
                                                util.intersects(new ExtentImpl(ulx, uly, lrx, lry), mosaic[row][col].getExtent(), mosaic[row][col].getAffineTransform()))
728
                                        //for (int k = 0; k < mosaic.length; k++)//???
729
                                                result[row][col] = (QueryableRaster)mosaic[row][col];
730
                return result;
731
        }
732

    
733
        /*
734
         * (non-Javadoc)
735
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isInside(java.awt.geom.Point2D)
736
         */
737
        public boolean isInside(Point2D p) {
738
                if(mosaic == null)
739
                        return false;
740
                return RasterLocator.getManager().getRasterUtils().isInside(p, getExtent(), getAffineTransform());
741
        }
742

    
743
        /*
744
         * (non-Javadoc)
745
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#rasterToWorld(java.awt.geom.Point2D)
746
         */
747
        public Point2D rasterToWorld(Point2D pt) {
748
                if(mosaic == null)
749
                        return null;
750
                Point2D p = new Point2D.Double();
751
                getAffineTransform().transform(pt, p);
752
                return p;
753
        }
754

    
755
        /*
756
         * (non-Javadoc)
757
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#worldToRaster(java.awt.geom.Point2D)
758
         */
759
        public Point2D worldToRaster(Point2D pt) {
760
                if(mosaic == null)
761
                        return null;
762
                Point2D p = new Point2D.Double();
763
                try {
764
                        getAffineTransform().inverseTransform(pt, p);
765
                } catch (NoninvertibleTransformException e) {
766
                        return pt;
767
                }
768
                return p;
769
        }
770

    
771
        /*
772
         * (non-Javadoc)
773
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isRotated()
774
         */
775
        public boolean isRotated() {
776
                if(mosaic == null)
777
                        return false;
778
                if(getAffineTransform().getShearX() != 0 || getAffineTransform().getShearY() != 0)
779
                        return true;
780
                return false;
781
        }
782

    
783
        /*
784
         * (non-Javadoc)
785
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isGeoreferenced()
786
         */
787
        public boolean isGeoreferenced() {
788
                //Este tipo de datasets siempre est? georreferenciado
789
                return true;
790
        }
791

    
792
        /*
793
         * (non-Javadoc)
794
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getBands()
795
         */
796
        public BandList getBands() {
797
                return bandList;
798
        }
799

    
800
        /**
801
         * Genera un buffer de datos ?nico a partir de una matriz de buffers donde puede haber
802
         * elementos con valor nulo.
803
         * @return
804
         */
805
        public Buffer generateBuffer(Buffer[][] bufList, int drawableBands) {
806
                if(mosaic == null)
807
                        return null;
808
                int n = mosaic.length;
809
                int m = mosaic[0].length;
810
                int nCols = 0, nRows = 0;
811
                //Contamos el n?mero de filas y columnas del buffer nuevo
812
                for (int row = 0; row < n; row++) {
813
                        for (int col = 0; col < m; col++)
814
                                if(bufList[row][col] != null)
815
                                        nCols += bufList[row][col].getWidth();
816
                        if(nCols != 0) break;
817
                }
818
                for (int col = 0; col < m; col++) {
819
                        for (int row = 0; row < n; row++)
820
                                if(bufList[row][col] != null)
821
                                        nRows += bufList[row][col].getHeight();
822
                        if(nRows != 0) break;
823
                }
824

    
825
                //Creamos el buffer
826
                Buffer raster = DefaultRasterManager.getInstance().createBuffer(bufList[0][0].getDataType(), nCols, nRows, drawableBands, true);
827

    
828
                //Hacemos la copia
829
                int[] pos = new int[2];
830
                int validCol = 0;
831
                for (int row = 0; row < n; row++) {
832
                        for (int col = 0; col < m; col++) {
833
                                pos[1] = (col == 0) ? 0 : pos[1];
834
                                if(bufList[row][col] == null)
835
                                        continue;
836
                                validCol = col;
837
                                copyTile(bufList[row][col], raster, pos[0], pos[1]);
838
                                pos[1] +=  bufList[row][col].getWidth();
839
                        }
840
                        if(bufList[row][validCol] != null)
841
                                pos[0] +=  bufList[row][validCol].getHeight();
842
                }
843
                return raster;
844
        }
845

    
846
        /**
847
         * Copia un tile en el buffer que contendr? todos los tiles
848
         * @param origin Buffer de origen
849
         * @param dest Buffer de destino
850
         * @param col Columna del buffer de destino donde se empieza a escribir
851
         * @param row Fila del buffer de destino donde se empieza a escribir
852
         * @return array con los valores que representan la ?ltima fila y
853
         * ?ltima columna que se escribieron
854
         */
855
        private void copyTile(Buffer origin, Buffer dest, int r, int c) {
856
                switch(origin.getDataType()) {
857
                case Buffer.TYPE_BYTE :
858
                        for (int band = 0; band < origin.getBandCount(); band++)
859
                                for (int row = 0; row < origin.getHeight(); row++)
860
                                        for (int col = 0; col < origin.getWidth(); col++)
861
                                                try {
862
                                                                dest.setElem(row + r, col + c, band, origin.getElemByte(row, col, band));
863
                                                        } catch (ArrayIndexOutOfBoundsException e) {break;}
864
                        break;
865
                case Buffer.TYPE_SHORT :
866
                        for (int band = 0; band < origin.getBandCount(); band++)
867
                                for (int row = 0; row < origin.getHeight(); row++)
868
                                        for (int col = 0; col < origin.getWidth(); col++)
869
                                                try {
870
                                                                dest.setElem(row + r, col + c, band, origin.getElemShort(row, col, band));
871
                                                        } catch (ArrayIndexOutOfBoundsException e) {break;}
872
                        break;
873
                case Buffer.TYPE_FLOAT :
874
                        for (int band = 0; band < origin.getBandCount(); band++)
875
                                for (int row = 0; row < origin.getHeight(); row++)
876
                                        for (int col = 0; col < origin.getWidth(); col++)
877
                                                try {
878
                                                                dest.setElem(row + r, col + c, band, origin.getElemFloat(row, col, band));
879
                                                        } catch (ArrayIndexOutOfBoundsException e) {break;}
880
                        break;
881
                case Buffer.TYPE_DOUBLE:
882
                        for (int band = 0; band < origin.getBandCount(); band++)
883
                                for (int row = 0; row < origin.getHeight(); row++)
884
                                        for (int col = 0; col < origin.getWidth(); col++)
885
                                                try {
886
                                                                dest.setElem(row + r, col + c, band, origin.getElemDouble(row, col, band));
887
                                                        } catch (ArrayIndexOutOfBoundsException e) {break;}
888
                        break;
889
                }
890
        }
891

    
892
        /*
893
         * (non-Javadoc)
894
         * @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(double, double, double, double)
895
         */
896
        public Buffer getWindowRaster(double ulx, double uly, double lrx, double lry)
897
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
898
                if(mosaic == null)
899
                        return null;
900
                try {
901
                        QueryableRaster[][] datasetList = getDatasetListInArea(ulx, uly, lrx, lry);
902
                        int n = mosaic.length;
903
                        int m = mosaic[0].length;
904
                        Buffer[][] bufferList = new Buffer[n][m];
905
                        for (int row = 0; row < n; row++)
906
                                for (int col = 0; col < m; col++)
907
                                        if(datasetList[row][col] != null)
908
                                                bufferList[row][col] = ((QueryableRaster)datasetList[row][col]).getWindowRaster(ulx, uly, lrx, lry);
909
                        Buffer endBuffer = null;
910
                        endBuffer = generateBuffer(bufferList, mosaic[0][0].getBands().getDrawableBandsCount());
911
                        for (int row = 0; row < n; row++)
912
                                for (int col = 0; col < m; col++)
913
                                        if (bufferList[row][col] != null)
914
                                                bufferList[row][col].free();
915
                        return endBuffer;
916
                } catch (NoninvertibleTransformException e) {
917
                        throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista.");
918
                }
919
        }
920

    
921
        /*
922
         * (non-Javadoc)
923
         * @see org.gvsig.raster.impl.dataset.QueryableRaster#getWindowRaster(double, double, double, double, boolean)
924
         */
925
        public Buffer getWindowRaster(double ulx, double uly, double w, double h, boolean adjustToExtent)
926
                throws InvalidSetViewException, RasterDriverException {
927
                //TODO: FUNCIONALIDAD: getWindowRaster en CompositeDataset sin implementar
928
                return null;
929
        }
930

    
931
        /*
932
         * (non-Javadoc)
933
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.grid.render.TileListener, int)
934
         */
935
        public void getWindowRaster(double ulx, double uly, double lrx, double lry, int bufWidth, int bufHeight, TileListener listener, int frameInPx)
936
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
937
                Buffer buf = getWindowRaster(ulx, uly, lrx, lry, bufWidth, bufHeight, true);
938
                buf.setDataExtent(new Rectangle2D.Double(ulx, uly, Math.abs(ulx - lrx), Math.abs(uly - lry)));
939
                listener.nextBuffer(buf, new ExtentImpl(ulx, uly, lrx, lry), this.getAffineTransform(), null, false);
940
                listener.endReading();
941
        }
942
        
943
        /*
944
         * (non-Javadoc)
945
         * @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(double, double, double, double, int, int, boolean)
946
         */
947
        public Buffer getWindowRaster(double ulx, double uly, double lrx, double lry, int bufWidth, int bufHeight, boolean adjustToExtent)
948
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
949
                if(mosaic == null)
950
                        return null;
951
                try {
952
                        Point2D p1 = new Point2D.Double(ulx, uly);
953
                        Point2D p2 = new Point2D.Double(lrx, lry);
954
                        QueryableRaster[][] datasetList = getDatasetListInArea(p1.getX(), p1.getY(), p2.getX(), p2.getY());
955
                        Point2D px1 = mosaic[0][0].worldToRaster(p1);
956
                        Point2D px2 = mosaic[0][0].worldToRaster(p2);
957
                        int n = mosaic.length;
958
                        int m = mosaic[0].length;
959
                        Buffer[][] bufferList = new Buffer[n][m];
960
                        for (int row = 0; row < n; row++) {
961
                                for (int col = 0; col < m; col++) {
962
                                        if(mosaic[row][col] == null)
963
                                                continue;
964
                                        if(datasetList[row][col] != null) {
965
                                                int[] values = getLocalRequest((int)px1.getX(), (int)px1.getY(), (int)Math.abs(px2.getX() - px1.getX()), (int)Math.abs(px2.getY() - px1.getY()), row, col);
966
                                                if(values != null) {
967
                                                        int bW = (int)Math.round((Math.abs(values[2] - values[0]) * bufWidth) / Math.abs(px2.getX() - px1.getX()));
968
                                                        int bH = (int)Math.round((Math.abs(values[3] - values[1]) * bufHeight) / Math.abs(px2.getY() - px1.getY()));
969
                                                        int wTile = (Math.abs(values[2] - values[0]) > (int)datasetList[row][col].getWidth()) ? (int)datasetList[row][col].getWidth() : (int)Math.abs(values[2] - values[0]);
970
                                                        int hTile = (Math.abs(values[3] - values[1]) > (int)datasetList[row][col].getHeight()) ? (int)datasetList[row][col].getHeight() : (int)Math.abs(values[3] - values[1]);
971
                                                        bufferList[row][col] = ((QueryableRaster)datasetList[row][col]).getWindowRaster(values[0], values[1], wTile, hTile, bW, bH);
972
                                                }
973
                                        }
974
                                }
975
                        }
976
                        Buffer endBuffer = generateBuffer(bufferList, mosaic[0][0].getBands().getDrawableBandsCount());
977
                        for (int row = 0; row < n; row++)
978
                                for (int col = 0; col < m; col++)
979
                                        if (bufferList[row][col] != null)
980
                                                bufferList[row][col].free();
981
                        return endBuffer;
982
                } catch (NoninvertibleTransformException e) {
983
                        throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista.");
984
                }
985
        }
986

    
987
        /*
988
         * (non-Javadoc)
989
         * @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(int, int, int, int)
990
         */
991
        public Buffer getWindowRaster(int x, int y, int w, int h)
992
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
993
                if(mosaic == null)
994
                        return null;
995
                try {
996
                        Point2D p1 = mosaic[0][0].rasterToWorld(new Point2D.Double(x, y));
997
                        Point2D p2 = mosaic[0][0].rasterToWorld(new Point2D.Double(x + w, y + h));
998
                        QueryableRaster[][] datasetList = getDatasetListInArea(p1.getX(), p1.getY(), p2.getX(), p2.getY());
999
                        int n = mosaic.length;
1000
                        int m = mosaic[0].length;
1001
                        Buffer[][] bufferList = new Buffer[n][m];
1002
                        for (int row = 0; row < n; row++) {
1003
                                for (int col = 0; col < m; col++) {
1004
                                        if(mosaic[row][col] == null)
1005
                                                continue;
1006
                                        if(datasetList[row][col] != null) {
1007
                                                int[] values = getLocalRequest(x, y, w, h, row, col);
1008
                                                int wTile = (Math.abs(values[2] - values[0]) > (int)datasetList[row][col].getWidth()) ? (int)datasetList[row][col].getWidth() : (int)Math.abs(values[2] - values[0]);
1009
                                                int hTile = (Math.abs(values[3] - values[1]) > (int)datasetList[row][col].getHeight()) ? (int)datasetList[row][col].getHeight() : (int)Math.abs(values[3] - values[1]);
1010
                                                if(values != null)
1011
                                                        bufferList[row][col] = ((QueryableRaster)datasetList[row][col]).getWindowRaster(values[0], values[1], wTile, hTile);
1012
                                        }
1013
                                }
1014
                        }
1015
                        Buffer endBuffer = generateBuffer(bufferList, mosaic[0][0].getBands().getDrawableBandsCount());
1016
                        for (int row = 0; row < n; row++)
1017
                                for (int col = 0; col < m; col++)
1018
                                        if (bufferList[row][col] != null)
1019
                                                bufferList[row][col].free();
1020
                        return endBuffer;
1021
                } catch (NoninvertibleTransformException e) {
1022
                        throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista.");
1023
                }
1024
        }
1025

    
1026
        /*
1027
         * (non-Javadoc)
1028
         * @see org.gvsig.raster.dataset.IRasterDataSource#getWindowRaster(int, int, int, int, int, int)
1029
         */
1030
        public Buffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight)
1031
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
1032
                if(mosaic == null && mosaic[0][0] == null)
1033
                        return null;
1034
                try {
1035
                        Point2D p1 = mosaic[0][0].rasterToWorld(new Point2D.Double(x, y));
1036
                        Point2D p2 = mosaic[0][0].rasterToWorld(new Point2D.Double(x + w, y + h));
1037
                        QueryableRaster[][] datasetList = getDatasetListInArea(p1.getX(), p1.getY(), p2.getX(), p2.getY());
1038
                        int n = mosaic.length;
1039
                        int m = mosaic[0].length;
1040
                        Buffer[][] bufferList = new Buffer[n][m];
1041
                        for (int row = 0; row < n; row++) {
1042
                                for (int col = 0; col < m; col++) {
1043
                                        if(mosaic[row][col] == null)
1044
                                                continue;
1045
                                        if(datasetList[row][col] != null) {
1046
                                                int[] values = getLocalRequest(x, y, w, h, row, col);
1047
                                                if(values != null) {
1048
                                                        int bW = Math.round((Math.abs(values[2] - values[0]) * bufWidth) / w);
1049
                                                        int bH = Math.round((Math.abs(values[3] - values[1]) * bufHeight) / h);
1050
                                                        int wTile = (Math.abs(values[2] - values[0]) > (int)datasetList[row][col].getWidth()) ? (int)datasetList[row][col].getWidth() : (int)Math.abs(values[2] - values[0]);
1051
                                                        int hTile = (Math.abs(values[3] - values[1]) > (int)datasetList[row][col].getHeight()) ? (int)datasetList[row][col].getHeight() : (int)Math.abs(values[3] - values[1]);
1052
                                                        bufferList[row][col] = ((QueryableRaster)datasetList[row][col]).getWindowRaster(values[0], values[1], wTile, hTile, bW, bH);
1053
                                                }
1054
                                        }
1055
                                }
1056
                        }
1057
                        Buffer endBuffer = generateBuffer(bufferList, mosaic[0][0].getBands().getDrawableBandsCount());
1058
                        for (int row = 0; row < n; row++)
1059
                                for (int col = 0; col < m; col++)
1060
                                        if (bufferList[row][col] != null)
1061
                                                bufferList[row][col].free();
1062
                        return endBuffer;
1063
                } catch (NoninvertibleTransformException e) {
1064
                        throw new InvalidSetViewException("No se ha podido aplicar la transformaci?n inversa para esa vista.");
1065
                }
1066
        }
1067

    
1068
        /**
1069
         * Convierte una petici?n global del mosaico en coordenadas pixel a una local al tile
1070
         * concreto que se est? tratando
1071
         * @param x Posici?n X de la petici?n a comprobar
1072
         * @param y Posici?n Y de la petici?n a comprobar
1073
         * @param w Ancho de la petici?n a comprobar
1074
         * @param h Alto de la petici?n a comprobar
1075
         * @param r File del tile
1076
         * @param c Columna del tile
1077
         * @return cuatro valores correspondientes a la x1, y1, x2, y2 de la petici?n referente al tile.
1078
         */
1079
        private int[] getLocalRequest(int x, int y, int w, int h, int r, int c) {
1080
                Point2D p1 = null, p2 = null;
1081

    
1082
                if(!requestGoThroughTile(x, y, w, h, r, c))
1083
                        return null;
1084

    
1085
                if(isInside(x, y, r, c))
1086
                        p1 = getLocalPixel(x, y);
1087
                else if(getTileFromPixelPoint(x, y)[0] == r)  //Est? en la misma fila
1088
                        p1 = new Point2D.Double(0, getLocalPixel(x, y).getY());
1089
                else if(getTileFromPixelPoint(x, y)[1] == c) //Est? en la misma columna
1090
                        p1 = new Point2D.Double(getLocalPixel(x, y).getX(), 0);
1091
                else
1092
                        p1 = new Point2D.Double(0, 0);
1093
                int fx = x + w;
1094
                int fy = y + h;
1095
                if(isInside(fx, fy, r, c))
1096
                        p2 = getLocalPixel(fx, fy);
1097
                else if(getTileFromPixelPoint(fx, fy)[0] == r)
1098
                        p2 = new Point2D.Double(mosaic[r][c].getWidth(), getLocalPixel(fx, fy).getY());
1099
                else if(getTileFromPixelPoint(fx, fy)[1] == c)
1100
                        p2 = new Point2D.Double(getLocalPixel(fx, fy).getX(), mosaic[r][c].getHeight());
1101
                else
1102
                        p2 = new Point2D.Double(mosaic[r][c].getWidth(), mosaic[r][c].getHeight());
1103
                if(p1 != null && p2 != null)
1104
                        return new int[]{(int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY()};
1105
                return null;
1106
        }
1107

    
1108
        /**
1109
         * Consulta si una petici?n en coordenadas pixel de la imagen completa pasa a trav?s de un
1110
         * tile de posici?n r, c
1111
         * @param x Posici?n X de la petici?n a comprobar
1112
         * @param y Posici?n Y de la petici?n a comprobar
1113
         * @param w Ancho de la petici?n a comprobar
1114
         * @param h Alto de la petici?n a comprobar
1115
         * @param r File del tile
1116
         * @param c Columna del tile
1117
         * @return true si la petici?n pasa a trav?s del tile y false si no pasa.
1118
         */
1119
        private boolean requestGoThroughTile(int x, int y, int w, int h, int r, int c) {
1120
                if(isInside(x, y, r, c) || isInside(w, h, r, c))
1121
                        return true;
1122
                Point2D p1 = getGlobalPixel(x, y, r, c);
1123
                Point2D p2 = getGlobalPixel(w, h, r, c);
1124

    
1125
                //Intersecci?n entre el ?rea pedida y el tile. Si intersectan se devuelve true
1126
                if(((x <= p1.getX() && w >= p1.getX()) || (x <= p2.getX() && w >= p2.getX())) &&
1127
                         ((y <= p1.getY() && h >= p1.getY()) || (y <= p2.getY() && h >= p2.getY())))
1128
                        return true;
1129
                return false;
1130
        }
1131

    
1132
        /**
1133
         * Obtiene el tile correspondiente a un pixel dado
1134
         * @param x Posici?n X del punto a comprobar
1135
         * @param y Posici?n Y del punto a comprobar
1136
         * @return Posici?n en fila-columna
1137
         */
1138
        public int[] getTileFromPixelPoint(int x, int y) {
1139
                if(mosaic == null)
1140
                        return null;
1141
                int n = mosaic.length;
1142
                int m = mosaic[0].length;
1143
                for (int row = 0; row < n; row++)
1144
                        for (int col = 0; col < m; col++)
1145
                                if(isInside(x, y, row, col))
1146
                                        return new int[]{row, col};
1147
                return null;
1148
        }
1149

    
1150
        /**
1151
         * Comprueba si un punto (x, y) cae dentro de un Tile (r, c)
1152
         * @param x Posici?n X del punto a comprobar
1153
         * @param y Posici?n Y del punto a comprobar
1154
         * @param r Fila del tile a comprobar
1155
         * @param c Columna del tile a comprobar
1156
         * @return true si el punto cae dentro del tile y false si no cae
1157
         */
1158
        private boolean isInside(int x, int y, int r, int c) {
1159
                int posR = -1, posC = -1;
1160
                int sum = 0;
1161
                for (int row = 0; row < mosaic.length; row++) {
1162
                        sum += mosaic[row][0].getHeight();
1163
                        if(sum >= y) {
1164
                                posR = row;
1165
                                break;
1166
                        }
1167
                }
1168
                sum = 0;
1169
                for (int col = 0; col < mosaic[0].length; col++) {
1170
                        sum += mosaic[0][col].getWidth();
1171
                        if(sum >= x) {
1172
                                posC = col;
1173
                                break;
1174
                        }
1175
                }
1176
                return (posR == r && posC == c) ? true : false;
1177
        }
1178

    
1179

    
1180
        /**
1181
         * Obtiene la coordenada pixel local para un raster dada la coordenada pixel global
1182
         * @param x Coordenada X global
1183
         * @param y Coordenada Y global
1184
         * @return Coordenada local
1185
         */
1186
        private Point2D getLocalPixel(int x, int y) {
1187
                int w = 0, h = 0;
1188
                int sum = 0;
1189
                for (int row = 0; row < mosaic.length; row++) {
1190
                        sum += mosaic[row][0].getHeight();
1191
                        if(sum >= y) {
1192
                                h = y - ((int)(sum - mosaic[row][0].getHeight()));
1193
                                break;
1194
                        }
1195
                }
1196
                sum = 0;
1197
                for (int col = 0; col < mosaic[0].length; col++) {
1198
                        sum += mosaic[0][col].getWidth();
1199
                        if(sum >= x) {
1200
                                w = x - ((int)(sum - mosaic[0][col].getWidth()));
1201
                                break;
1202
                        }
1203
                }
1204
                return new Point2D.Double(w, h);
1205
        }
1206

    
1207
        /**
1208
         * Obtiene la coordenada pixel global para un raster dada la coordenada pixel local
1209
         * @param x Coordenada X local
1210
         * @param y Coordenada Y local
1211
         * @param r Fila del tile
1212
         * @param c Columna del tile
1213
         * @return Coordenada global
1214
         */
1215
        private Point2D getGlobalPixel(int x, int y, int r, int c) {
1216
                int sumX = 0, sumY = 0;
1217
                for (int row = 0; row < (r - 1); row++)
1218
                        sumY += mosaic[row][0].getHeight();
1219
                sumY += y;
1220
                for (int col = 0; col < (c - 1); col++)
1221
                        sumX += mosaic[0][col].getWidth();
1222
                sumX += x;
1223
                return new Point2D.Double(sumX, sumY);
1224
        }
1225
        
1226
        /*
1227
         * (non-Javadoc)
1228
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeX()
1229
         */
1230
        public double getPixelSizeX() {
1231
                if(mosaic == null && mosaic[0][0] != null)
1232
                        return 0;
1233
                return mosaic[0][0].getPixelSizeX();
1234
        }
1235

    
1236
        /*
1237
         * (non-Javadoc)
1238
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeY()
1239
         */
1240
        public double getPixelSizeY() {
1241
                if(mosaic == null && mosaic[0][0] != null)
1242
                        return 0;
1243
                return mosaic[0][0].getPixelSizeY();
1244
        }
1245

    
1246
        /*
1247
         * (non-Javadoc)
1248
         * @see org.gvsig.raster.impl.store.QueryableRaster#setDrawableBands(int[])
1249
         */
1250
        public void setDrawableBands(int[] db) {
1251
                if(mosaic == null)
1252
                        return;
1253
                int n = mosaic.length;
1254
                int m = mosaic[0].length;
1255
                for (int row = 0; row < n; row++) {
1256
                        for (int col = 0; col < m; col++) {
1257
                                if(mosaic[row][col] == null)
1258
                                        continue;
1259
                                ((QueryableRaster)mosaic[row][col]).setDrawableBands(db);
1260
                        }
1261
                }
1262
        }
1263

    
1264
        /*
1265
         * (non-Javadoc)
1266
         * @see org.gvsig.raster.impl.dataset.QueryableRaster#clearDrawableBands()
1267
         */
1268
        public void clearDrawableBands() {
1269
                if(mosaic == null)
1270
                        return;
1271
                int n = mosaic.length;
1272
                int m = mosaic[0].length;
1273
                for (int row = 0; row < n; row++) {
1274
                        for (int col = 0; col < m; col++) {
1275
                                if(mosaic[row][col] == null)
1276
                                        continue;
1277
                                ((QueryableRaster)mosaic[row][col]).clearDrawableBands();
1278
                        }
1279
                }
1280
        }
1281

    
1282
        /*
1283
         * (non-Javadoc)
1284
         * @see org.gvsig.raster.impl.store.QueryableRaster#addDrawableBand(int, int)
1285
         */
1286
        public void addDrawableBand(int posRasterBuf, int imageBand) {
1287
                if(mosaic == null)
1288
                        return;
1289
                int n = mosaic.length;
1290
                int m = mosaic[0].length;
1291
                for (int row = 0; row < n; row++) {
1292
                        for (int col = 0; col < m; col++) {
1293
                                if(mosaic[row][col] == null)
1294
                                        continue;
1295
                                ((QueryableRaster)mosaic[row][col]).addDrawableBand(posRasterBuf, imageBand);
1296
                        }
1297
                }
1298
        }
1299

    
1300
        /*
1301
         * (non-Javadoc)
1302
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getTransparency()
1303
         */
1304
        public Transparency getTransparency() {
1305
                if(mosaic != null && mosaic[0][0] != null)
1306
                        return mosaic[0][0].getTransparency();
1307
                return new DataStoreTransparency();
1308
        }
1309

    
1310
        /*
1311
         * (non-Javadoc)
1312
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getColorTable()
1313
         */
1314
        public ColorTable getColorTable() {
1315
                if(mosaic != null && mosaic[0][0] != null)
1316
                        return mosaic[0][0].getColorTable();
1317
                return null;
1318
        }
1319

    
1320
        /*
1321
         * (non-Javadoc)
1322
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getHistogram()
1323
         */
1324
        public Histogram getHistogram() throws HistogramException {
1325
                if(mosaic == null)
1326
                        return null;
1327
                percent = 0;
1328
                Histogram[] histogram = new Histogram[mosaic.length * mosaic[0].length];
1329
                double parc = 100 / (double)(mosaic.length + mosaic[0].length);
1330
                int cont = 0;
1331
                for (int i = 0; i < mosaic.length; i++) {
1332
                        for (int j = 0; j < mosaic[0].length; j++) {
1333
                                if(mosaic[i][j] != null)
1334
                                        histogram[cont] = mosaic[i][j].getHistogram();
1335
                                percent += cont * parc; 
1336
                                cont ++;
1337
                        }
1338
                }
1339
                MosaicDataStoreHistogram histRes = new MosaicDataStoreHistogram(histogram, this);
1340
                return histRes;
1341
        }
1342

    
1343
        /*
1344
         * (non-Javadoc)
1345
         * @see org.gvsig.raster.impl.store.QueryableRaster#getColorTable(int)
1346
         */
1347
        public ColorTable getColorTable(int i){
1348
                return (mosaic != null && mosaic[0][0] != null) ? ((QueryableRaster)mosaic[0][0]).getColorTable(i) : null;
1349
        }
1350

    
1351
        /*
1352
         * (non-Javadoc)
1353
         * @see org.gvsig.raster.impl.store.QueryableRaster#getColorTable(java.lang.String)
1354
         */
1355
        public ColorTable getColorTable(String fileName){
1356
                return (mosaic != null && mosaic[0][0] != null) ? ((QueryableRaster)mosaic[0][0]).getColorTable(fileName) : null;
1357
        }
1358

    
1359
        /*
1360
         * (non-Javadoc)
1361
         * @see org.gvsig.raster.dataset.MultiRasterStore#getData(int, int, int)
1362
         */
1363
        public Object getData(int x, int y, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
1364
                if(mosaic == null)
1365
                        return null;
1366
                int[] posTile = getTileFromPixelPoint(x, y);
1367
                if(mosaic[posTile[0]][posTile[1]] == null)
1368
                        return null;
1369
                if(posTile != null) {
1370
                        QueryableRaster dataset = (QueryableRaster)mosaic[posTile[0]][posTile[1]];
1371
                        Point2D localPixel = getLocalPixel(x, y);
1372
                        return ((DefaultMultiRasterStore)dataset).getData((int)localPixel.getX(), (int)localPixel.getY(), band);
1373
                }
1374
                return null;
1375
        }
1376

    
1377
        /*
1378
         * (non-Javadoc)
1379
         * @see org.gvsig.raster.dataset.IRasterDataSource#isReadOnly()
1380
         */
1381
        public boolean isReadOnly() {
1382
                return readOnly;
1383
        }
1384

    
1385
        /*
1386
         * (non-Javadoc)
1387
         * @see org.gvsig.raster.dataset.IRasterDataSource#setReadOnly(boolean)
1388
         */
1389
        public void setReadOnly(boolean readOnly) {
1390
                this.readOnly = readOnly;
1391
        }
1392

    
1393
        /*
1394
         * (non-Javadoc)
1395
         * @see org.gvsig.raster.dataset.IRasterDataSource#isMemoryBuffer()
1396
         */
1397
        public boolean isMemoryBuffer() {
1398
                return forceToMemory;
1399
        }
1400

    
1401
        /*
1402
         * (non-Javadoc)
1403
         * @see org.gvsig.raster.impl.store.QueryableRaster#setMemoryBuffer(boolean)
1404
         */
1405
        public void setMemoryBuffer(boolean memory) {
1406
                this.forceToMemory = memory;
1407
                if(memory)
1408
                        this.readOnly = false;
1409
        }
1410

    
1411
        /*
1412
         * (non-Javadoc)
1413
         * @see org.gvsig.raster.dataset.RasterDataset#getOverviewCount(int)
1414
         */
1415
        public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
1416
                if(band >= getBandCount())
1417
                        throw new BandAccessException("Wrong band");
1418
                return 0;
1419
        }
1420

    
1421
        /*
1422
         * (non-Javadoc)
1423
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#overviewsSupport()
1424
         */
1425
        public boolean overviewsSupport() {
1426
                return false;
1427
        }
1428
        
1429
        /*
1430
         * (non-Javadoc)
1431
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewWidth(int, int)
1432
         */
1433
        public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
1434
                if(mosaic == null || mosaic[0][0] == null)
1435
                        return 0;
1436
                int[] providerBand = ((DefaultMultiRasterStore)mosaic[0][0]).getProviderFromBandNumber(band);
1437
                RasterProvider prov = ((DefaultMultiRasterStore)mosaic[0][0]).getProvider(providerBand[0]);
1438
                return prov.getOverviewWidth(providerBand[1], overview);
1439
        }
1440

    
1441
        /*
1442
         * (non-Javadoc)
1443
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewHeight(int, int)
1444
         */
1445
        public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
1446
                if(mosaic == null || mosaic[0][0] == null)
1447
                        return 0;
1448
                int[] providerBand = ((DefaultMultiRasterStore)mosaic[0][0]).getProviderFromBandNumber(band);
1449
                RasterProvider prov = ((DefaultMultiRasterStore)mosaic[0][0]).getProvider(providerBand[0]);
1450
                return prov.getOverviewHeight(providerBand[1], overview);
1451
        }
1452

    
1453
        /*
1454
         * (non-Javadoc)
1455
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getNoDataValue()
1456
         */
1457
        public double getNoDataValue() {
1458
                if(mosaic == null)
1459
                        return 0;
1460
                int n = mosaic.length;
1461
                int m = mosaic[0].length;
1462
                if ((n == 0) || (m == 0) || mosaic[0][0] == null)
1463
                        return RasterLibrary.defaultNoDataValue;
1464
                return mosaic[0][0].getNoDataValue();
1465
        }
1466

    
1467
        /*
1468
         * (non-Javadoc)
1469
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#resetNoDataValue()
1470
         */
1471
        public void resetNoDataValue() {
1472
                if(mosaic == null)
1473
                        return;
1474
                int n = mosaic.length;
1475
                int m = mosaic[0].length;
1476
                for (int row = 0; row < n; row++) {
1477
                        for (int col = 0; col < m; col++) {
1478
                                if(mosaic[row][col] == null)
1479
                                        continue;
1480
                                mosaic[row][col].resetNoDataValue();
1481
                        }
1482
                }
1483
        }
1484

    
1485
        /*
1486
         * (non-Javadoc)
1487
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setNoDataValue(double)
1488
         */
1489
        public void setNoDataValue(double value) {
1490
                if(mosaic == null)
1491
                        return;
1492
                int n = mosaic.length;
1493
                int m = mosaic[0].length;
1494
                for (int row = 0; row < n; row++) {
1495
                        for (int col = 0; col < m; col++) {
1496
                                if(mosaic[row][col] == null)
1497
                                        continue;
1498
                                mosaic[row][col].setNoDataValue(value);
1499
                        }
1500
                }
1501
        }
1502

    
1503
        /*
1504
         * (non-Javadoc)
1505
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isNoDataEnabled()
1506
         */
1507
        public boolean isNoDataEnabled() {
1508
                if(mosaic == null)
1509
                        return false;
1510
                int n = mosaic.length;
1511
                int m = mosaic[0].length;
1512
                if ((n == 0) || (m == 0) || mosaic[0][0] == null)
1513
                        return false;
1514
                return mosaic[0][0].isNoDataEnabled();
1515
        }
1516

    
1517
        /*
1518
         * (non-Javadoc)
1519
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setNoDataEnabled(boolean)
1520
         */
1521
        public void setNoDataEnabled(boolean enabled) {
1522
                if(mosaic == null)
1523
                        return;
1524
                int n = mosaic.length;
1525
                int m = mosaic[0].length;
1526
                for (int row = 0; row < n; row++) {
1527
                        for (int col = 0; col < m; col++) {
1528
                                if(mosaic[row][col] == null)
1529
                                        continue;
1530
                                mosaic[row][col].setNoDataEnabled(enabled);
1531
                        }
1532
                }
1533
        }
1534

    
1535
        /*
1536
         * (non-Javadoc)
1537
         * @see org.gvsig.raster.impl.store.QueryableRaster#getDataStore()
1538
         */
1539
        public RasterDataStore getDataStore() {
1540
                return this;
1541
        }
1542
        
1543
        /*
1544
         * (non-Javadoc)
1545
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getProjection()
1546
         */
1547
        public IProjection getProjection() {
1548
                if(mosaic == null && mosaic[0][0] != null)
1549
                        return null;
1550
                return mosaic[0][0].getProjection();
1551
        }
1552
        
1553
        /*
1554
         * (non-Javadoc)
1555
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getView()
1556
         */
1557
        public Extent getView() {
1558
                //TODO:Sin implementar
1559
                return null;
1560
        }
1561
        
1562
        /*
1563
         * (non-Javadoc)
1564
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getExtentWithoutRot()
1565
         */
1566
        public Extent getExtentWithoutRot() {
1567
                //TODO:Sin implementar
1568
                return null;
1569
        }
1570
        
1571
        /*
1572
         * (non-Javadoc)
1573
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getMetadata()
1574
         */
1575
        public Metadata getMetadata() {
1576
                //TODO:Sin implementar
1577
                return null;
1578
        }
1579
        
1580
        /*
1581
         * (non-Javadoc)
1582
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getWktProjection()
1583
         */
1584
        public String getWktProjection() throws RasterDriverException {
1585
                return null;
1586
        }
1587

    
1588
        /*
1589
         * (non-Javadoc)
1590
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getColorInterpretation()
1591
         */
1592
        public DataStoreColorInterpretation getColorInterpretation() {
1593
                return null;
1594
        }
1595
        
1596
        /*
1597
         * (non-Javadoc)
1598
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getStatistics()
1599
         */
1600
        public Statistics getStatistics() {
1601
                return stats;
1602
        }
1603
        
1604
        /*
1605
         * (non-Javadoc)
1606
         * @see org.gvsig.fmap.dal.coverage.store.MosaicRasterStore#getTile(int, int)
1607
         */
1608
        public RasterDataStore getTile(int row, int col) {
1609
                if(mosaic == null)
1610
                        return null;
1611
                if(row < mosaic.length && col < mosaic[0].length)
1612
                        if(mosaic[row][col] != null)
1613
                                return (RasterDataStore)mosaic[row][col];
1614
                return null;
1615
        }
1616
        
1617
        /*
1618
         * (non-Javadoc)
1619
         * @see org.gvsig.fmap.dal.coverage.store.MosaicRasterStore#getTile(int)
1620
         */
1621
        public RasterDataStore getTile(int i) {
1622
                if(mosaic == null)
1623
                        return null;
1624
                return (RasterDataStore)mosaic[i /  mosaic.length][i %  mosaic.length];
1625
        }
1626
        
1627
        /*
1628
         * (non-Javadoc)
1629
         * @see org.gvsig.fmap.dal.coverage.store.MosaicRasterStore#getNumberOfTiles()
1630
         */
1631
        public int getNumberOfTiles() {
1632
                if(mosaic != null)
1633
                        return (mosaic.length + mosaic[0].length);
1634
                return 0;
1635
        }
1636
        
1637
        /*
1638
         * (non-Javadoc)
1639
         * @see org.gvsig.fmap.dal.coverage.store.MosaicRasterStore#getCols()
1640
         */
1641
        public int getCols() {
1642
                if(mosaic != null)
1643
                        return mosaic[0].length;
1644
                return 0;
1645
        }
1646
        
1647
        /*
1648
         * (non-Javadoc)
1649
         * @see org.gvsig.fmap.dal.coverage.store.MosaicRasterStore#getRows()
1650
         */
1651
        public int getRows() {
1652
                if(mosaic != null)
1653
                        return mosaic.length;
1654
                return 0;
1655
        }
1656
        
1657
        /*
1658
         * (non-Javadoc)
1659
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isReproyectable()
1660
         */
1661
        public boolean isReproyectable() {
1662
                return false;
1663
        }
1664
        
1665
        /*
1666
         * (non-Javadoc)
1667
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isOpen()
1668
         */
1669
        public boolean isOpen() {
1670
                if(mosaic == null)
1671
                        return false;
1672
                int n = mosaic.length;
1673
                int m = mosaic[0].length;
1674
                for (int row = 0; row < n; row++) {
1675
                        for (int col = 0; col < m; col++) {
1676
                                if(mosaic[row][col] == null)
1677
                                        continue;
1678
                                if(!mosaic[row][col].isOpen())
1679
                                        return false;
1680
                        }
1681
                }
1682
                return true;
1683
        }
1684
        
1685
        /*
1686
         * (non-Javadoc)
1687
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getTransparencyFilesStatus()
1688
         */
1689
        public Transparency getTransparencyFilesStatus() {
1690
                if(mosaic == null)
1691
                        return null;
1692
                int n = mosaic.length;
1693
                int m = mosaic[0].length;
1694
                Transparency t = null;
1695
                for (int row = 0; row < n; row++) {
1696
                        for (int col = 0; col < m; col++) {
1697
                                if(mosaic[row][col] == null)
1698
                                        continue;
1699
                                if(t != null) {
1700
                                        Transparency t1 = mosaic[row][col].getTransparencyFilesStatus();
1701
                                        t.merge(t1);
1702
                                } else 
1703
                                        t = mosaic[row][col].getTransparencyFilesStatus();
1704
                        }
1705
                }
1706
                return t;
1707
        }
1708
        
1709
        /*
1710
         * (non-Javadoc)
1711
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#saveGeoreferencingToRmf()
1712
         */
1713
        public void saveGeoreferencingToRmf() throws RmfSerializerException {
1714
                if(mosaic == null)
1715
                        return;
1716
                int n = mosaic.length;
1717
                int m = mosaic[0].length;
1718
                for (int row = 0; row < n; row++) {
1719
                        for (int col = 0; col < m; col++) {
1720
                                if(mosaic[row][col] == null)
1721
                                        continue;
1722
                                mosaic[row][col].saveGeoreferencingToRmf();
1723
                        }
1724
                }
1725
        }
1726
        
1727
        /*
1728
         * (non-Javadoc)
1729
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#cloneDataStore()
1730
         */
1731
        public RasterDataStore cloneDataStore() {
1732
                if(mosaic == null)
1733
                        return null;
1734
                int n = mosaic.length;
1735
                int m = mosaic[0].length;
1736
                
1737
                RasterDataStore[][] mos = new RasterDataStore[n][m];
1738
                for (int row = 0; row < n; row++) {
1739
                        for (int col = 0; col < m; col++) {
1740
                                if(mosaic[row][col] == null)
1741
                                        continue;
1742
                                mos[row][col] = mosaic[row][col].cloneDataStore();
1743
                        }
1744
                }
1745
                DefaultMosaicRasterStore result = null;
1746
                try {
1747
                        result = new DefaultMosaicRasterStore(mos);
1748
                } catch (MosaicNotValidException e) {
1749
                        return null;
1750
                }
1751
                return result;
1752
        }
1753

    
1754
        /*
1755
         * (non-Javadoc)
1756
         * @see org.gvsig.metadata.Metadata#getMetadataName()
1757
         */
1758
        public String getMetadataName() {
1759
                if(mosaic != null && mosaic[0][0] != null)
1760
                        try {
1761
                                return mosaic[0][0].getMetadataName();
1762
                        } catch (MetadataException e) {
1763
                                return null;
1764
                        }
1765
                return null;
1766
        }
1767
        
1768
        /*
1769
         * (non-Javadoc)
1770
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#saveSerialInfoToRmf(org.gvsig.fmap.dal.coverage.store.props.SerialInfo)
1771
         */
1772
        public void saveSerialInfoToRmf(SerialInfo serialInfo) throws RmfSerializerException {
1773
                if(mosaic == null)
1774
                        return;
1775
                int n = mosaic.length;
1776
                int m = mosaic[0].length;
1777
                for (int row = 0; row < n; row++) {
1778
                        for (int col = 0; col < m; col++) {
1779
                                if(mosaic[row][col] == null)
1780
                                        continue;
1781
                                ((AbstractRasterDataStore)mosaic[row][col]).saveSerialInfoToRmf(serialInfo);
1782
                        }
1783
                }
1784
        }
1785
        
1786
        /*
1787
         * (non-Javadoc)
1788
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#saveColorTableToRmf(org.gvsig.fmap.dal.coverage.store.props.ColorTable)
1789
         */
1790
        public void saveColorTableToRmf(ColorTable table) throws RmfSerializerException {
1791
                if(mosaic == null)
1792
                        return;
1793
                int n = mosaic.length;
1794
                int m = mosaic[0].length;
1795
                for (int row = 0; row < n; row++) {
1796
                        for (int col = 0; col < m; col++) {
1797
                                if(mosaic[row][col] == null)
1798
                                        continue;
1799
                                ((AbstractRasterDataStore)mosaic[row][col]).saveColorTableToRmf(table);
1800
                        }
1801
                }
1802
        }
1803
        
1804
        /*
1805
         * (non-Javadoc)
1806
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#loadSerialInfoFromRmf(org.gvsig.fmap.dal.coverage.store.props.SerialInfo)
1807
         */
1808
        public boolean loadSerialInfoFromRmf(SerialInfo serialInfo) {
1809
                int n = mosaic.length;
1810
                int m = mosaic[0].length;
1811
                for (int row = 0; row < n; row++) {
1812
                        for (int col = 0; col < m; col++) {
1813
                                if(mosaic[row][col] == null)
1814
                                        continue;
1815
                                if(((AbstractRasterDataStore)mosaic[row][col]).loadSerialInfoFromRmf(serialInfo))
1816
                                        return true;
1817
                        }
1818
                }
1819
                return false;
1820
        }
1821
        
1822
        /*
1823
         * (non-Javadoc)
1824
         * @see org.gvsig.raster.util.IHistogramable#getPercent()
1825
         */
1826
        public int getPercent() {
1827
                return percent;
1828
        }
1829

    
1830
        /*
1831
         * (non-Javadoc)
1832
         * @see org.gvsig.raster.util.IHistogramable#resetPercent()
1833
         */
1834
        public void resetPercent() {
1835
                percent = 0;
1836
        }
1837
        
1838
        /*
1839
         * (non-Javadoc)
1840
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#getProvider()
1841
         */
1842
        public CoverageStoreProvider getProvider() {
1843
                if(mosaic == null && mosaic[0][0] != null)
1844
                        return null;
1845
                return mosaic[0][0].getProvider();
1846
        }
1847

    
1848
        public void removeDataset(String fileName) {}
1849
        public void removeDataset(RasterDataStore file) {}
1850
        public void saveGeoToRmf() throws IOException {}
1851
        public void saveRmfModification() throws IOException {}
1852
        public void setAffineTransform(AffineTransform transf) {}
1853
}