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 / DefaultMultiRasterStore.java @ 633

History | View | Annotate | Download (57.9 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.Point2D;
26
import java.awt.geom.Rectangle2D;
27
import java.io.File;
28
import java.util.ArrayList;
29

    
30
import org.cresques.cts.IProjection;
31
import org.gvsig.compat.net.ICancellable;
32
import org.gvsig.fmap.dal.DataStoreParameters;
33
import org.gvsig.fmap.dal.coverage.RasterLibrary;
34
import org.gvsig.fmap.dal.coverage.RasterLocator;
35
import org.gvsig.fmap.dal.coverage.RasterManager;
36
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
37
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
38
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand;
39
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
40
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
41
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
42
import org.gvsig.fmap.dal.coverage.exception.CloneException;
43
import org.gvsig.fmap.dal.coverage.exception.FileNotExistsException;
44
import org.gvsig.fmap.dal.coverage.exception.FileNotFoundInListException;
45
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
46
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
47
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
48
import org.gvsig.fmap.dal.coverage.exception.OperationNotSupportedException;
49
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
50
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
51
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
52
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
53
import org.gvsig.fmap.dal.coverage.exception.TimeException;
54
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
55
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
56
import org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters;
57
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
58
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
59
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
60
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
61
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
62
import org.gvsig.fmap.dal.coverage.store.props.TimeSeries;
63
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
64
import org.gvsig.fmap.dal.exception.InitializeException;
65
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider;
66
import org.gvsig.raster.cache.tile.TileCacheLocator;
67
import org.gvsig.raster.cache.tile.TileCacheManager;
68
import org.gvsig.raster.cache.tile.exception.TileGettingException;
69
import org.gvsig.raster.cache.tile.provider.TileListener;
70
import org.gvsig.raster.impl.DefaultRasterManager;
71
import org.gvsig.raster.impl.buffer.cache.RasterReadOnlyBuffer;
72
import org.gvsig.raster.impl.datastruct.BandListImpl;
73
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
74
import org.gvsig.raster.impl.datastruct.ExtentImpl;
75
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
76
import org.gvsig.raster.impl.provider.RasterProvider;
77
import org.gvsig.raster.impl.provider.TiledRasterProvider;
78
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
79
import org.gvsig.raster.impl.store.properties.MultiDataStoreHistogramComputer;
80
import org.gvsig.raster.impl.store.properties.MultiDataStoreMetadata;
81
import org.gvsig.raster.impl.store.properties.MultiDataStoreStatistics;
82
import org.gvsig.timesupport.Time;
83

    
84
/**
85
 * Clase que representa una imagen de raster georreferenciada formada por varias
86
 * imagenes de disco que tienen la misma extensi?n. Contiene funcionalidades
87
 * para abrir ficheros, gestionar el extent, pintar el raster sobre un DataImage
88
 * con su gesti?n de bandas correspondiente.
89
 *
90
 * @author Nacho Brodin (nachobrodin@gmail.com)
91
 */
92
public class DefaultMultiRasterStore extends AbstractRasterDataStore {
93
        protected ArrayList<RasterProvider>     providers     = new ArrayList<RasterProvider>();
94
        protected BandListImpl                  bandList      = new BandListImpl();
95
        protected MultiDataStoreStatistics      stats         = null;
96
        protected HistogramComputer             histogram     = null;
97
        protected MultiDataStoreMetadata        metadata      = null;
98
        private RasterManager                   rManager      = RasterLocator.getManager();
99
        
100
        /**
101
         * Flag que fuerza al buffer de solo lectura
102
         */
103
        protected boolean                       readOnly      = false;
104
        /**
105
         * Flag que fuerza al buffer en memoria
106
         */
107
        protected boolean                       forceToMemory = false;
108
        
109

    
110
        //TODO: FUNCIONALIDAD: Contructores igual a RasterDataset + String[] nameFiles
111
        public DefaultMultiRasterStore() {
112
                super();
113
        }
114

    
115
        /**
116
         * Crea un objeto MultiRasterDataset nuevo con los mismos ficheros
117
         * que el actual.
118
         * @return MultiRasterDataset
119
         */
120
        public RasterDataStore newDataStore() {
121
                if(providers.size() > 0 && providers.get(0).getDataParameters() instanceof TileDataParameters) {
122
                        RasterManager manager = (DefaultRasterManager)RasterLocator.getManager();
123
                        try {
124
                                return manager.open((DataStoreParameters)parameters);
125
                        } catch (NotSupportedExtensionException e) {
126
                                return null;
127
                        } catch (RasterDriverException e) {
128
                                return null;
129
                        }
130
                }
131
                
132
                try {
133
                        String[] fileList = getNameDatasetStringList();
134
                        DefaultMultiRasterStore multiRasterDataset = (DefaultMultiRasterStore)DefaultRasterManager.getInstance().open(fileList[0]);
135
                        for (int j = 1; j < fileList.length; j++)
136
                                multiRasterDataset.addDataStore(new String[] { fileList[j] });
137
                        return multiRasterDataset;
138
                } catch (FileNotFoundInListException e) {
139
                        return null;
140
                } catch (NotSupportedExtensionException e) {
141
                        return null;
142
                } catch (RasterDriverException e) {
143
                        return null;
144
                } catch (OperationNotSupportedException e) {
145
                        //No puede darse. El metodo es @override 
146
                }
147
                return null;
148
        }
149
        
150
        /*
151
         * (non-Javadoc)
152
         * @see org.gvsig.raster.impl.dataset.QueryableRaster#getProviders()
153
         */
154
        public ArrayList<RasterProvider> getProviders() {
155
                return providers;
156
        }
157
        
158
        /*
159
         * (non-Javadoc)
160
         * @see org.gvsig.raster.impl.store.QueryableRaster#getProvider(int)
161
         */
162
        public RasterProvider getProvider(int i) {
163
                if(providers == null || 
164
                        providers.size() == 0 || 
165
                        i < 0 || 
166
                        i >= providers.size())
167
                        return null;
168
                return providers.get(i);
169
        }
170
        
171
        /*
172
         * (non-Javadoc)
173
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getName()
174
         */
175
        public String getName() {
176
                if(providers != null && providers.size() >= 1)
177
                        return providers.get(0).getFName();
178
                return null;
179
        }
180
        
181
        /*
182
         * (non-Javadoc)
183
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#getFName(int)
184
         */
185
        public String getFName(int i) {
186
                if(providers != null && providers.size() >= (i + 1))
187
                        return providers.get(i).getFName();
188
                return null;
189
        }
190

    
191
        /*
192
         * (non-Javadoc)
193
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#addDataStore(org.gvsig.fmap.dal.coverage.store.RasterDataStore)
194
         */
195
        public void addDataStore(RasterDataStore f) throws OperationNotSupportedException {
196
                if(f instanceof DefaultMultiRasterStore) {
197
                        for (int i = 0; i < ((DefaultMultiRasterStore)f).providers.size(); i++) {
198
                                RasterProvider prov = providers.get(i);
199
                                providers.add(prov);
200
                                addBands(prov);
201
                                if(stats == null)
202
                                        stats = new MultiDataStoreStatistics(((QueryableRaster)f).getProviders());
203
                                else
204
                                        stats.addProvider(prov);
205
                        }
206
                }
207
        }
208

    
209
        /*
210
         * 
211
         */
212
        public void addDataStore(RasterProvider provider) throws OperationNotSupportedException {
213
                providers.add(provider);
214
                addBands(provider);
215
                if(stats == null) 
216
                        stats = new MultiDataStoreStatistics(providers);
217
                else
218
                        stats.addProvider(provider);
219
        }
220
        
221
        /*
222
         * (non-Javadoc)
223
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#addDataStore(java.lang.String[])
224
         */
225
        public void addDataStore(String[] fileName)throws FileNotFoundInListException, NotSupportedExtensionException, RasterDriverException, OperationNotSupportedException {
226
                if(fileName == null || fileName.length < 1)
227
                        throw new FileNotFoundInListException("Error in list.");
228
                if(findDataset(fileName[0]))
229
                        throw new FileNotFoundInListException("The file already is in list.");
230
                for (int i = 0; i < fileName.length; i++) {
231
                        DefaultRasterProvider ds = DefaultRasterProvider.singleDatasetInstance(this, fileName[i]);
232
                        addDataStore(ds);
233
                }
234
        }
235
        
236
        /*
237
         * (non-Javadoc)
238
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#addDataStore(java.lang.String)
239
         */
240
        public void addDataStore(String fileName)throws FileNotFoundInListException, NotSupportedExtensionException, RasterDriverException, OperationNotSupportedException {
241
                addDataStore(new String[]{fileName});
242
        }
243
        
244
        /**
245
         * A?ade el fichero a lista de georrasterfiles y sus bandas a la lista de bandas
246
         * @param grf
247
         */
248
        public void addBands(RasterProvider prov) {
249
                if(prov == null)
250
                        return;
251

    
252
                for(int i = 0; i < prov.getBandCount(); i++)
253
                        try {
254
                                int dataType = prov.getDataType()[i];
255
                                DatasetBand band = new DatasetBandImpl(prov.getFName(), i, dataType, prov.getBandCount());
256
                                bandList.addBand(band, i);
257
                        } catch(BandNotFoundInListException ex) {
258
                                //No a?adimos la banda
259
                        }
260
        }
261

    
262
        /*
263
         * (non-Javadoc)
264
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#removeDataStore(java.lang.String)
265
         */
266
        public void removeDataStore(String fileName) throws OperationNotSupportedException {
267
                for(int i = 0; i < providers.size(); i++)
268
                        if(providers.get(i).getFName().equals(fileName)) {
269
                                providers.remove(i);
270
                                bandList.removeBands(fileName);
271
                                return;
272
                        }
273
        }
274

    
275
        /*
276
         * (non-Javadoc)
277
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#removeDataStore(org.gvsig.fmap.dal.coverage.store.RasterDataStore)
278
         */
279
        public void removeDataStore(RasterDataStore file) throws OperationNotSupportedException {
280
                for(int i = 0; i < providers.size(); i++)
281
                        if(providers.get(i).getFName().equals(file.getName())) {
282
                                providers.remove(i);
283
                                bandList.removeBands(file.getName());
284
                                return;
285
                        }
286
        }
287

    
288
        /*
289
         * (non-Javadoc)
290
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getDataStoreCount()
291
         */
292
        public int getDataStoreCount() {
293
                return providers.size();
294
        }
295

    
296
        /**
297
         * Encuentra un fichero en la lista.
298
         * @param file Fichero b?scado.
299
         * @return true si se ha hallado el fichero y false si no se
300
         * ha encontrado
301
         */
302
        public boolean findDataset(RasterDataStore file) {
303
                for(int i = 0; i < providers.size(); i++) {
304
                        RasterProvider prov = providers.get(i);
305
                        if(        prov.getFName().equals(file.getName()))
306
                                return true;
307
                }
308
                return false;
309
        }
310

    
311
        /**
312
         * Encuentra un fichero en la lista.
313
         * @param file Fichero b?scado.
314
         * @return true si se ha hallado el fichero y false si no se
315
         * ha encontrado
316
         */
317
        public boolean findDataset(String fileName) {
318
                for(int i = 0; i < providers.size(); i++)
319
                        if(providers.get(i).getFName().equals(fileName))
320
                                return true;
321
                return false;
322
        }
323

    
324
        /*
325
         * (non-Javadoc)
326
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#close()
327
         */
328
        public void close() {
329
                for(int i = 0; i < providers.size(); i++)
330
                        providers.get(i).close();
331
                providers.clear();
332
                bandList.clear();
333
        }
334

    
335
        /*
336
         * (non-Javadoc)
337
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#getNameDatasetStringList()
338
         */
339
        public String[] getNameDatasetStringList() {
340
                String[] list = new String[providers.size()];
341
                for(int k = 0; k < providers.size(); k++)
342
                        list[k] = providers.get(k).getOpenParameters();
343
                return list;
344
        }
345

    
346
        /**
347
         * Inicializa el buffer a valores NoData
348
         * @param raster Buffer a inicializar
349
         * @param bandList Lista de bandas
350
         */
351
        private void initBufferToNoData(Buffer raster, BandList bandList) {
352
                for(int i = 0; i < bandList.getDrawableBandsCount(); i++)
353
                        switch(getDataType()[0]) {
354
                        case Buffer.TYPE_BYTE:raster.assign(i, raster.getByteNoDataValue());break;
355
                        case Buffer.TYPE_SHORT:raster.assign(i, raster.getShortNoDataValue());break;
356
                        case Buffer.TYPE_INT:raster.assign(i, raster.getIntNoDataValue());break;
357
                        case Buffer.TYPE_FLOAT:raster.assign(i, raster.getFloatNoDataValue());break;
358
                        case Buffer.TYPE_DOUBLE:raster.assign(i, raster.getNoDataValue());break;
359
                        }
360
        }
361

    
362
        /**
363
         * A partir de la lista de bandas que dice como cargar el buffer se crean tantos Buffer como ficheros intervienen
364
         * . Cada Buffer corresponde a un dataset del RasterMultiDataset y en ellos se reserva memoria solo para las
365
         * bandas que vayan a ser cargadas. Las otras se asignaran a la banda NotValid.
366
         * @param bl Lista de bandas
367
         * @param width Ancho
368
         * @param height Alto
369
         * @return Lista de buffers en el que cada uno corresponde a un dataset.
370
         */
371
        @SuppressWarnings("unused")
372
        private Buffer[] mallocBuffersDatasets(BandList bl, int width, int height) {
373
                Buffer[] buffers = new Buffer[getDataStoreCount()];
374
                for(int i = 0; i < getDataStoreCount(); i++) {
375
                        if(forceToMemory)
376
                                buffers[i] =  DefaultRasterManager.getInstance().createMemoryBuffer(getProvider(i).getDataType()[0], width, height, getProvider(i).getBandCount(), false);
377
                        else
378
                                buffers[i] =  DefaultRasterManager.getInstance().createBuffer(getProvider(i).getDataType()[0], width, height, getProvider(i).getBandCount(), false);
379

    
380
                        //Asignamos las bandas de cada fichero que no se pintan a null y las que se pintan se reserva memoria
381
                        String name = getProvider(i).getName();
382
                        for(int j = 0; j < getProvider(i).getBandCount(); j ++)
383
                                if(bl.getBufferBandToDraw(name, j) == null)
384
                                        buffers[i].assignBandToNotValid(j);
385
                                else
386
                                        buffers[i].mallocOneBand(getProvider(i).getDataType()[0], width, height, j);
387
                }
388
                return buffers;
389
        }
390

    
391
        /**
392
         * Mezcla los buffers de los dataset que forman el RasterMultiDataset sobre un solo buffer
393
         * con las directrices que marca la lista de bandas. Esta funci?n es la que realiza el switch
394
         * de las bandas.
395
         * @param b Buffer sobre el que se mezcla
396
         * @param bDataset Buffers que corresponden a los datasets
397
         * @param bandList Objeto que contiene la informaci?n de que bandas de los dataset se escriben sobre
398
         * que banda del buffer.
399
         */
400
        @SuppressWarnings("unused")
401
        private void mergeBuffers(Buffer b, Buffer[] bDataset, BandList bandList) {
402
                for(int iDataset = 0; iDataset < getDataStoreCount(); iDataset++){ //Ojo! Los datasets est?n en la misma posici?n que se han metido en mallocBuffersDatasets
403
                        String name = getProvider(iDataset).getFName();
404

    
405
                        for(int iBand = 0; iBand < getProvider(iDataset).getBandCount(); iBand ++) {
406
                                int[] posToDraw = bandList.getBufferBandToDraw(name, iBand);
407
                                if(posToDraw != null)
408
                                        for(int i = 0; i < posToDraw.length; i ++)
409
                                                switch(getDataType()[iDataset]) {
410
                                                case Buffer.TYPE_BYTE: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
411
                                                case Buffer.TYPE_SHORT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
412
                                                case Buffer.TYPE_INT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
413
                                                case Buffer.TYPE_FLOAT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
414
                                                case Buffer.TYPE_DOUBLE: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
415
                                                }
416
                        }
417
                }
418
        }
419
        
420
        /*
421
         * (non-Javadoc)
422
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isTiled()
423
         */
424
        public boolean isTiled() {
425
                boolean isTiled = true;
426
                for (int i = 0; i < providers.size(); i++) {
427
                        if(!(providers.get(i) instanceof TiledRasterProvider))
428
                                return false;
429
                }
430
                return isTiled;
431
        }
432

    
433
        /*
434
         * (non-Javadoc)
435
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double)
436
         */
437
        public Buffer getWindow(double ulx, double uly, double lrx, double lry)
438
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
439
                //Extent selectedExtent = new Extent(ulx, uly, lrx, lry);
440

    
441
                //Leemos pixels completos aunque el valor obtenido sea decimal. Esto se consigue redondeando
442
                //por arriba el m?s alto y por abajo el menor y luego restandolos
443

    
444
                Point2D p1 = providers.get(0).worldToRaster(new Point2D.Double(ulx, uly));
445
                Point2D p2 = providers.get(0).worldToRaster(new Point2D.Double(lrx, lry));
446

    
447
                //Para el valor mayor redondeamos por arriba. Para el valor menor redondeamos por abajo.
448
                double p1X = (p1.getX() > p2.getX()) ? Math.ceil(p1.getX()) : Math.floor(p1.getX());
449
                double p1Y = (p1.getY() > p2.getY()) ? Math.ceil(p1.getY()) : Math.floor(p1.getY());
450
                double p2X = (p2.getX() > p1.getX()) ? Math.ceil(p2.getX()) : Math.floor(p2.getX());
451
                double p2Y = (p2.getY() > p1.getY()) ? Math.ceil(p2.getY()) : Math.floor(p2.getY());
452

    
453
                int width = (int)Math.abs(p1X - p2X);
454
                int height = (int)Math.abs(p1Y - p2Y);
455

    
456
                //Ajustamos por si nos hemos salido del raster
457
                if(((int)(Math.min(p1X, p2X) + width)) > getWidth())
458
                        width = (int)(getWidth() - Math.min(p1X, p2X));
459
                if(((int)(Math.min(p1Y, p2Y) + height)) > getHeight())
460
                        height = (int)(getHeight() - Math.min(p1Y, p2Y));
461

    
462
                if (p1X < 0)
463
                        p1X = 0;
464
                if (p1Y < 0)
465
                        p1Y = 0;
466
                if (p2X > getWidth())
467
                        p2X = getWidth();
468
                if (p2Y > getHeight())
469
                        p2Y = getHeight();
470

    
471
                int mallocNBands = 0;
472
                if(bandList.getDrawableBands() != null)
473
                        mallocNBands = bandList.getDrawableBands().length;
474
                else
475
                        mallocNBands = bandList.getDrawableBandsCount();
476

    
477
                //Buffer ReadOnly
478

    
479
                if(isReadOnly()) {
480
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], width, height, getBandCount());
481
                        if(rb instanceof RasterReadOnlyBuffer) {
482
                                try {
483
                                        ((RasterReadOnlyBuffer)rb).setBufferParams(this, (int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), bandList);
484
                                } catch (FileNotExistsException e) {
485
                                        //Esto no debe darse ya que se comprueba al hacer el open.
486
                                        return null;
487
                                } catch (NotSupportedExtensionException e) {
488
                                        //Esto no debe darse ya que se comprueba al hacer el open
489
                                        return null;
490
                                }
491
                                return rb;
492
                        }
493
                }
494

    
495
                //Buffer RW
496
                Buffer raster = null;
497
                
498
                //Si hemos redondeado los pixeles de la petici?n (p1 y p2) por arriba y por abajo deberemos calcular un extent mayor
499
                //equivalente a los pixeles redondeados.
500
                Point2D wc1 = providers.get(0).rasterToWorld(new Point2D.Double(p1X, p1Y));
501
                Point2D wc2 = providers.get(0).rasterToWorld(new Point2D.Double(p2X, p2Y));
502
                
503
                if(forceToMemory) //Fuerza siempre buffer en memoria
504
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], width, height, mallocNBands, true);
505
                else
506
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], width, height, mallocNBands, true);
507
                
508
                Extent ex = rManager.getDataStructFactory().createExtent(wc1.getX(), wc1.getY(), wc2.getX(), wc2.getY());
509
                for(int i = 0; i < getDataStoreCount(); i++) 
510
                        raster = ((DefaultRasterProvider)providers.get(i)).getWindow(ex, bandList, raster);
511

    
512
                return raster;
513
        }
514

    
515
        /*
516
         * (non-Javadoc)
517
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double, boolean)
518
         */
519
        public Buffer getWindow(double ulx, double uly, double w, double h, boolean adjustToExtent)
520
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
521
                //El incremento o decremento de las X e Y depende de los signos de rotaci?n y escala en la matriz de transformaci?n. Por esto
522
                //tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h
523
                Extent ext = getExtent();
524
                Point2D pInit = providers.get(0).rasterToWorld(new Point2D.Double(0, 0));
525
                Point2D pEnd = providers.get(0).rasterToWorld(new Point2D.Double((int)getWidth(), (int)getHeight()));
526
                double wRaster = Math.abs(pEnd.getX() - pInit.getX());
527
                double hRaster = Math.abs(pEnd.getY() - pInit.getY());
528
                double lrx = (((int)(ext.getULX() - wRaster)) == ((int)ext.getLRX())) ? (ulx - w) : (ulx + w);
529
                double lry = (((int)(ext.getULY() - hRaster)) == ((int)ext.getLRY())) ? (uly - h) : (uly + h);
530

    
531
                //Extent selectedExtent = new Extent(ulx, uly, lrx, lry);
532

    
533
                //Leemos pixels completos aunque el valor obtenido sea decimal. Esto se consigue redondeando
534
                //por arriba el m?s alto y por abajo el menor y luego restandolos
535

    
536
                Point2D p1 = providers.get(0).worldToRaster(new Point2D.Double(ulx, uly));
537
                Point2D p2 = providers.get(0).worldToRaster(new Point2D.Double(lrx, lry));
538
                int width = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX()));
539
                int height = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY()));
540

    
541
                //Ajustamos por si nos hemos salido del raster
542
                if(((int)(p1.getX() + width)) > getWidth())
543
                        width = (int)(getWidth() - p1.getX());
544
                if(((int)(p1.getY() + height)) > getHeight())
545
                        height = (int)(getHeight() - p1.getY());
546

    
547
                if (p1.getX() < 0)
548
                        p1.setLocation(0, p1.getY());
549
                if (p1.getY() < 0)
550
                        p1.setLocation(p1.getX(), 0);
551
                if (p2.getX() > getWidth())
552
                        p2.setLocation(getWidth(), p2.getY());
553
                if (p2.getY() > getHeight())
554
                        p2.setLocation(p2.getX(), getHeight());
555

    
556
                int mallocNBands = 0;
557
                if(bandList.getDrawableBands() != null)
558
                        mallocNBands = bandList.getDrawableBands().length;
559
                else
560
                        mallocNBands = bandList.getDrawableBandsCount();
561

    
562
                //Buffer ReadOnly
563

    
564
                if(isReadOnly()) {
565
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], width, height, getBandCount());
566
                        if(rb instanceof RasterReadOnlyBuffer) {
567
                                try {
568
                                        ((RasterReadOnlyBuffer)rb).setBufferParams(this, (int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), bandList);
569
                                } catch (FileNotExistsException e) {
570
                                        //Esto no debe darse ya que se comprueba al hacer el open.
571
                                        return null;
572
                                } catch (NotSupportedExtensionException e) {
573
                                        //Esto no debe darse ya que se comprueba al hacer el open
574
                                        return null;
575
                                }
576
                                return rb;
577
                        }
578
                }
579
                
580
                //Si hemos redondeado los pixeles de la petici?n (p1 y p2) por arriba y por abajo deberemos calcular un extent mayor
581
                //equivalente a los pixeles redondeados.
582
                Point2D wc1 = providers.get(0).rasterToWorld(new Point2D.Double(Math.floor(p1.getX()), Math.floor(p1.getY())));
583
                Point2D wc2 = providers.get(0).rasterToWorld(new Point2D.Double(Math.ceil(p2.getX()), Math.ceil(p2.getY())));
584

    
585
                //Buffer RW
586
                Buffer raster = null;
587
                
588
                if(forceToMemory) //Fuerza siempre buffer en memoria
589
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], width, height, mallocNBands, true);
590
                else
591
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], width, height, mallocNBands, true);
592

    
593
                if(!adjustToExtent)
594
                         initBufferToNoData(raster, bandList);
595
                
596
                for(int i = 0; i < getDataStoreCount(); i++)
597
                        raster = ((DefaultRasterProvider)providers.get(i)).getWindow(wc1.getX(), wc1.getY(), Math.abs(wc2.getX() - wc1.getX()), Math.abs(wc2.getY() - wc1.getY()), bandList, raster, adjustToExtent);
598

    
599
                return raster;
600
        }
601
        
602
        /*
603
         * (non-Javadoc)
604
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.grid.render.TileListener, int)
605
         */
606
        public void getWindow(double ulx, double uly, double lrx, double lry, 
607
                int bufWidth, int bufHeight, TileListener listener)
608
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
609
                if(isTiled() && providers.size() == 1 /*No valido para multi ficheros*/) { 
610
                        Extent ex = new ExtentImpl(ulx, uly, lrx, lry);
611
                        ((DefaultRasterProvider)providers.get(0)).getWindow(ex, bufWidth, bufHeight, bandList, listener);
612
                        return;
613
                }
614
                                
615
                double[] step = null;
616
                Buffer buf = null;
617
                
618
                //Esta secci?n es para que no supersamplee el driver y pueda hacerse en el cliente
619
                if(!currentQuery.isSupersamplingLoadingBuffer()) {
620
                        //nWidth = ((adjustedDataExtent.width() * mDataset.getDataset(0).getWidth()) / mDataset.getExtentForRequest().width());
621
                        //nHeight = ((adjustedDataExtent.height() * mDataset.getDataset(0).getHeight()) / mDataset.getExtentForRequest().height());
622
                        Point2D p1 = worldToRaster(new Point2D.Double(ulx, uly));
623
                        Point2D p2 = worldToRaster(new Point2D.Double(lrx, lry));
624
                        nWidth = Math.abs(p1.getX() - p2.getX());
625
                        nHeight = Math.abs(p1.getY() - p2.getY());
626

    
627
                        if(bufWidth > Math.ceil(nWidth) && bufHeight > Math.ceil(nHeight)) {
628
                                step = calcSteps(ulx, uly, lrx, lry, nWidth, nHeight, bufWidth, bufHeight);
629
                                buf = getWindow(ulx, uly, lrx, lry);
630
                        }
631
                } 
632
                
633
                if(buf == null)
634
                        buf = getWindow(ulx, uly, lrx, lry, bufWidth, bufHeight, true);
635
                
636
                buf.setDataExtent(new Rectangle2D.Double(ulx, uly, Math.abs(ulx - lrx), Math.abs(uly - lry)));
637
                
638
                Buffer alphaBand = null;
639
                if(currentQuery.getAlphaBandNumber() != -1) {
640
                        int[] drawableBands = bandList.getDrawableBands();
641
                        bandList.setDrawableBands(new int[]{currentQuery.getAlphaBandNumber(), -1, -1});
642
                        for(int i = 0; i < getDataStoreCount(); i++)
643
                                ((AbstractRasterDataParameters)((DefaultRasterProvider)providers.get(i)).getDataParameters()).setAlphaBand(currentQuery.getAlphaBandNumber());
644
                        alphaBand = getWindow(ulx, uly, lrx, lry, bufWidth, bufHeight, true);
645
                        bandList.setDrawableBands(drawableBands);
646
                }
647
                
648
                TileCacheManager m = TileCacheLocator.getManager();
649
                org.gvsig.raster.cache.tile.Tile t = m.createTile(-1, 0, 0);
650
                t.setData(new Object[]{buf, alphaBand});
651
                t.setUl(new Point2D.Double(ulx, uly));
652
                t.setLr(new Point2D.Double(lrx, lry));
653
                t.setDownloaderParams("AffineTransform", getAffineTransform());
654
                t.setDownloaderParams("Tiling", new Boolean(true));
655
                t.setDownloaderParams("Step", step);
656
                try {
657
                        listener.tileReady(t);
658
                } catch (TileGettingException e) {
659
                        throw new RasterDriverException("Error getting a tile", e);
660
                }
661
                
662
                //listener.nextBuffer(buf, alphaBand, new ExtentImpl(ulx, uly, lrx, lry), this.getAffineTransform(), step, false);
663
                listener.endReading();
664
        }
665

    
666
        /*
667
         * (non-Javadoc)
668
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double, int, int, boolean)
669
         */
670
        public Buffer getWindow(double ulx, double uly, double lrx, double lry, int bufWidth, int bufHeight, boolean adjustToExtent)
671
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
672

    
673
                Point2D p1 = worldToRaster(new Point2D.Double(ulx, uly));
674
                Point2D p2 = worldToRaster(new Point2D.Double(lrx, lry));
675
                
676
                if(p1.getX() > p2.getX())
677
                        p1.setLocation(p1.getX() - 1, p1.getY());
678
                else
679
                        p2.setLocation(p2.getX() - 1, p2.getY());
680
                
681
                if(p1.getY() > p2.getY())
682
                        p1.setLocation(p1.getX(), p1.getY() - 1);
683
                else
684
                        p2.setLocation(p2.getX(), p2.getY() - 1);
685
                
686
                if(        ((int)p1.getX()) < 0 || ((int)p2.getX()) > getWidth() ||
687
                                ((int)p2.getY()) > getHeight() || ((int)p2.getY()) < 0)
688
                                throw new InvalidSetViewException("");
689

    
690
                int mallocNBands = 0;
691
                if(bandList.getDrawableBands() != null)
692
                        mallocNBands = bandList.getDrawableBands().length;
693
                else
694
                        mallocNBands = bandList.getDrawableBandsCount();
695

    
696
                //Buffer ReadOnly
697

    
698
                if(isReadOnly()) {
699
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], bufWidth, bufHeight, getBandCount());
700
                        if(rb instanceof RasterReadOnlyBuffer) {
701
                                try {
702
                                        ((RasterReadOnlyBuffer)rb).setBufferParams(this, (int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), bandList);
703
                                } catch (FileNotExistsException e) {
704
                                        //Esto no debe darse ya que se comprueba al hacer el open.
705
                                        return null;
706
                                } catch (NotSupportedExtensionException e) {
707
                                        //Esto no debe darse ya que se comprueba al hacer el open
708
                                        return null;
709
                                }
710
                                return rb;
711
                        }
712
                }
713

    
714
                //Buffer RW
715
                Buffer raster = null;
716
                
717
                if(forceToMemory) //Fuerza siempre buffer en memoria
718
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], bufWidth, bufHeight, mallocNBands, true);
719
                else
720
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, mallocNBands, true);
721
                
722
                Extent ex = rManager.getDataStructFactory().createExtent(ulx, uly, lrx, lry);
723
                for(int i = 0; i < getDataStoreCount(); i++) 
724
                        raster = ((DefaultRasterProvider)providers.get(i)).getWindow(ex, bufWidth, bufHeight, bandList, raster, adjustToExtent);
725

    
726
                return raster;
727
        }
728

    
729
        /*
730
         * (non-Javadoc)
731
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(int, int, int, int)
732
         */
733
        public Buffer getWindow(int x, int y, int w, int h)
734
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
735
                if(x < 0 || y < 0 || w > providers.get(0).getWidth() || h > providers.get(0).getHeight())
736
                        throw new InvalidSetViewException("Out of image");
737

    
738
                //Buffer ReadOnly
739

    
740
                if(isReadOnly()) {
741
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], w, h, getBandCount());
742
                        if(rb instanceof RasterReadOnlyBuffer) {
743
                                try {
744
                                        ((RasterReadOnlyBuffer)rb).setBufferParams(this, x, y, x + w, y + h, bandList);
745
                                } catch (FileNotExistsException e) {
746
                                        //Esto no debe darse ya que se comprueba al hacer el open.
747
                                        return null;
748
                                } catch (NotSupportedExtensionException e) {
749
                                        //Esto no debe darse ya que se comprueba al hacer el open
750
                                        return null;
751
                                }
752
                                return rb;
753
                        }
754
                }
755

    
756
                //Buffer RW
757
                Buffer raster = null;
758
                
759
                if(forceToMemory) //Fuerza siempre buffer en memoria
760
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], w, h, bandList.getDrawableBandsCount(), true);
761
                else
762
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], w, h, bandList.getDrawableBandsCount(), true);
763
                
764
                for(int i = 0; i < getDataStoreCount(); i++)
765
                        ((DefaultRasterProvider)providers.get(i)).getWindow(x, y, bandList, raster);
766
        
767
                return raster;
768
        }
769

    
770
        /*
771
         * (non-Javadoc)
772
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(int, int, int, int, int, int)
773
         */
774
        public Buffer getWindow(int x, int y, int w, int h, int bufWidth, int bufHeight)
775
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
776
                if(x < 0 || y < 0 || w > providers.get(0).getWidth() || h > providers.get(0).getHeight())
777
                        throw new InvalidSetViewException("Out of image");
778

    
779
                //Buffer ReadOnly
780

    
781
                if(isReadOnly()) {
782
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], bufWidth, bufHeight, getBandCount());
783
                        if(rb instanceof RasterReadOnlyBuffer) {
784
                                try {
785
                                        ((RasterReadOnlyBuffer)rb).setBufferParams((QueryableRaster)this, x, y, x + w, y + h, bandList);
786
                                } catch (FileNotExistsException e) {
787
                                        //Esto no debe darse ya que se comprueba al hacer el open.
788
                                        return null;
789
                                } catch (NotSupportedExtensionException e) {
790
                                        //Esto no debe darse ya que se comprueba al hacer el open
791
                                        return null;
792
                                }
793
                                return rb;
794
                        }
795
                }
796

    
797
                //Buffer RW
798
                Buffer raster = null;
799
                
800
                if(forceToMemory) //Fuerza siempre buffer en memoria
801
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], bufWidth, bufHeight, bandList.getDrawableBandsCount(), true);
802
                else
803
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, bandList.getDrawableBandsCount(), true);
804
                
805
                for(int i = 0; i < getDataStoreCount(); i++)
806
                        raster = ((DefaultRasterProvider)providers.get(i)).getWindow(x, y, w, h, bufWidth, bufHeight, bandList, raster);
807

    
808
                return raster;
809
        }
810

    
811
        //******************************
812
        //Setters and Getters
813
        //******************************
814

    
815
        /**
816
         * Calcula el tama?o de los ficheros en disco
817
         * @return tama?o en bytes de todos los ficheros de la lista
818
         */
819
        public long getFileSize() {
820
                int len = 0;
821
                for(int i = 0; i < providers.size();i++)
822
                        if(providers.get(i) != null) {
823
                                File f = new File(providers.get(i).getFName());
824
                                len += f.length();
825
                        }
826
                return len;
827
        }
828

    
829
        /*
830
         * (non-Javadoc)
831
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getHeight()
832
         */
833
        public double getHeight() {
834
                double[] lenghts = new double[getDataStoreCount()];
835
                for(int i = 0; i < getDataStoreCount(); i++)
836
                        if(providers.get(i) != null)
837
                                lenghts[i] = providers.get(i).getHeight();
838
                return lenghts[0];
839
        }
840

    
841
        /*
842
         * (non-Javadoc)
843
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getWidth()
844
         */
845
        public double getWidth() {
846
                double[] lenghts = new double[getDataStoreCount()];
847
                for(int i = 0; i < getDataStoreCount(); i++)
848
                        if(providers.get(i) != null)
849
                                lenghts[i] = providers.get(i).getWidth();
850
                return lenghts[0];
851
        }
852

    
853
        /*
854
         * (non-Javadoc)
855
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getCellSize()
856
         */
857
        public double getCellSize() {
858
                try {
859
                        Extent e = getExtent();
860
                        double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / getWidth();
861
                        return dCellsize;
862
                } catch (NullPointerException e) {
863
                        return 1;
864
                }
865
        }
866

    
867
        /*
868
         * (non-Javadoc)
869
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getBandCount()
870
         */
871
        public int getBandCount() {
872
                return bandList.getBandCount();
873
        }
874

    
875
        /*
876
         * (non-Javadoc)
877
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getDataType()
878
         */
879
        public int[] getDataType() {
880
                int[] dt = new int[getBandCount()];
881

    
882
                if (dt.length == 0)
883
                        return null;
884

    
885
                int k = 0;
886
                for(int i = 0; i < providers.size(); i++) {
887
                        int[] types = providers.get(i).getDataType();
888
                        for (int j = 0; j < types.length; j++) {
889
                                dt[k] = types[j];
890
                                k ++;
891
                        }
892
                }
893

    
894
                return dt;
895
        }
896

    
897
        /*
898
         * (non-Javadoc)
899
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#getDataStore(int)
900
         */
901
        public RasterDataStore getDataStore(int i) {
902
                try {
903
                        DefaultMultiRasterStore store = new DefaultMultiRasterStore();
904
                        store.addDataStore(providers.get(i));
905
                        store.intializePhase1(null, (DataStoreParameters)providers.get(i).getDataParameters());
906
                        return store;
907
                } catch (ArrayIndexOutOfBoundsException e) {
908
                        return null;
909
                } catch (InitializeException e) {
910
                        return null;
911
                } catch (OperationNotSupportedException e) {
912
                        DefaultMultiRasterStore store = new DefaultMultiRasterStore();
913
                        providers.add(providers.get(0));
914
                        addBands(providers.get(0));
915
                        if(stats == null) 
916
                                stats = new MultiDataStoreStatistics(providers);
917
                        else
918
                                stats.addProvider(providers.get(0));
919
                        try {
920
                                store.intializePhase1(null, (DataStoreParameters)providers.get(0).getDataParameters());
921
                        } catch (InitializeException e1) {
922
                                return null;
923
                        }
924
                        return store;
925
                }
926
        }
927

    
928
        /*
929
         * (non-Javadoc)
930
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#getDataStore(java.lang.String)
931
         */
932
        public RasterDataStore getDataStore(String fileName) {
933
                DefaultMultiRasterStore store = new DefaultMultiRasterStore();
934
                boolean exists = false;
935
                try {
936
                        for(int i = 0; i < providers.size(); i++) {
937
                                if(providers.get(i).getFName().equals(fileName)) {
938
                                        store.addDataStore(providers.get(i));
939
                                        exists = true;
940
                                }
941
                        }
942
                } catch (OperationNotSupportedException e) {
943
                        providers.add(providers.get(0));
944
                        addBands(providers.get(0));
945
                        if(stats == null) 
946
                                stats = new MultiDataStoreStatistics(providers);
947
                        else
948
                                stats.addProvider(providers.get(0));
949
                        try {
950
                                store.intializePhase1(null, (DataStoreParameters)providers.get(0).getDataParameters());
951
                        } catch (InitializeException e1) {
952
                                return null;
953
                        }
954
                }
955
                if(exists)
956
                        return store;
957
                else
958
                        return null;
959
        }
960

    
961
        /*
962
         * (non-Javadoc)
963
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getBands()
964
         */
965
        public BandList getBands() {
966
                return bandList;
967
        }
968

    
969
        /**
970
         * Obtiene la coordenada X m?nima de toda la lista
971
         * @return Coordenada X m?nima
972
         */
973
        public double getMinX() {
974
                double minx = Double.MAX_VALUE;
975
                for(int i = 0; i < providers.size(); i++) {
976
                        double aux = providers.get(i).getExtent().getMin().getX();
977
                        if(aux < minx)
978
                                minx = aux;
979
                }
980
                return minx;
981
        }
982

    
983
        /**
984
         * Obtiene la coordenada Y m?nima de toda la lista
985
         * @return Coordenada Y m?nima
986
         */
987
        public double getMinY() {
988
                double miny = Double.MAX_VALUE;
989
                for(int i = 0; i < providers.size(); i++) {
990
                        double aux = providers.get(i).getExtent().getMin().getY();
991
                        if(aux < miny)
992
                                miny = aux;
993
                }
994
                return miny;
995
        }
996

    
997
        /**
998
         * Obtiene la coordenada Y m?xima de toda la lista
999
         * @return Coordenada Y m?xima
1000
         */
1001
        public double getMaxX() {
1002
                double maxx = Double.NEGATIVE_INFINITY;
1003
                for(int i = 0; i < providers.size(); i++) {
1004
                        double aux = providers.get(i).getExtent().getMax().getY();
1005
                        if(aux > maxx)
1006
                                maxx = aux;
1007
                }
1008
                return maxx;
1009
        }
1010

    
1011
        /**
1012
         * Obtiene la coordenada Y m?xima de toda la lista
1013
         * @return Coordenada Y m?xima
1014
         */
1015
        public double getMaxY() {
1016
                double maxy = Double.NEGATIVE_INFINITY;
1017
                for(int i = 0; i < providers.size(); i++) {
1018
                        double aux = providers.get(i).getExtent().getMax().getY();
1019
                        if(aux > maxy)
1020
                                maxy = aux;
1021
                }
1022
                return maxy;
1023
        }
1024

    
1025
        /*
1026
         * (non-Javadoc)
1027
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getNoDataValue()
1028
         */
1029
        public double getNoDataValue() {
1030
                if (providers.isEmpty())
1031
                        return RasterLibrary.defaultNoDataValue;
1032

    
1033
                return providers.get(0).getNoDataValue();
1034
        }
1035

    
1036
        /*
1037
         * (non-Javadoc)
1038
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isNoDataEnabled()
1039
         */
1040
        public boolean isNoDataEnabled() {
1041
                if (providers.isEmpty())
1042
                        return false;
1043

    
1044
                return providers.get(0).isNoDataEnabled();
1045
        }
1046

    
1047
        /*
1048
         * (non-Javadoc)
1049
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#resetNoDataValue()
1050
         */
1051
        public void resetNoDataValue() {
1052
                for (int i = 0; i < providers.size(); i++)
1053
                        providers.get(i).resetNoDataValue();
1054
        }
1055

    
1056
        /*
1057
         * (non-Javadoc)
1058
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setNoDataValue(double)
1059
         */
1060
        public void setNoDataValue(double value) {
1061
                for (int i = 0; i < providers.size(); i++)
1062
                        providers.get(i).setNoDataValue(value);
1063
        }
1064

    
1065
        /*
1066
         * (non-Javadoc)
1067
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setNoDataEnabled(boolean)
1068
         */
1069
        public void setNoDataEnabled(boolean enabled) {
1070
                for (int i = 0; i < providers.size(); i++)
1071
                        providers.get(i).setNoDataEnabled(enabled);
1072
        }
1073

    
1074
        /*
1075
         * (non-Javadoc)
1076
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getExtent()
1077
         */
1078
        public Extent getExtent() {
1079
                if(providers.size() == 0)
1080
                        return null;
1081
                else
1082
                        return providers.get(0).getExtent();
1083
        }
1084

    
1085
        /**
1086
         * Este es el extent sobre el que se ajusta una petici?n para que esta no exceda el
1087
         * extent m?ximo del raster. Para un raster sin rotar ser? igual al extent
1088
         * pero para un raster rotado ser? igual al extent del raster como si no
1089
         * tuviera rotaci?n. Esto ha de ser as? ya que la rotaci?n solo se hace sobre la
1090
         * vista y las peticiones han de hacerse en coordenadas de la imagen sin shearing
1091
         * aplicado.
1092
         * @return Extent
1093
         */
1094
        public Extent getExtentForRequest() {
1095
                return providers.get(0).getExtentWithoutRot();
1096
        }
1097

    
1098
        /**
1099
         * 
1100
         * @return
1101
         */
1102
        public Extent getLastSelectedView(){
1103
                return providers.get(0).getView();
1104
        }
1105

    
1106
        /*
1107
         * (non-Javadoc)
1108
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getTransparencyFilesStatus()
1109
         */
1110
        public Transparency getTransparencyFilesStatus() {
1111
                if(providers.size() <= 0)
1112
                        return null;
1113
                Transparency t = providers.get(0).getTransparency();
1114
                for(int i = 1; i < providers.size(); i++) {
1115
                        Transparency t1 = providers.get(i).getTransparency();
1116
                        t.merge(t1);
1117
                }
1118
                return t;
1119
        }
1120

    
1121
        /*
1122
         * (non-Javadoc)
1123
         * @see org.gvsig.raster.impl.store.QueryableRaster#getColorTable(int)
1124
         */
1125
        public ColorTable getColorTable(int i){
1126
                if(i >= providers.size())
1127
                        return null;
1128
                return providers.get(i).getColorTable();
1129
        }
1130

    
1131
        /**
1132
         * Obtiene la lista de paletas correspondiente a todos los ficheros que forman el GeoMultiRasterFile
1133
         * @return Paleta asociada a este o null si no tiene. Una posici?n null en el array tambi?n indica que
1134
         * para ese fichero no hay paletas asociadas.
1135
         */
1136
        public ColorTable[] getColorTables(){
1137
                if(providers.size() <= 0)
1138
                        return null;
1139
                ColorTable[] list = new ColorTable[providers.size()];
1140
                for(int i = 0; i < providers.size(); i++)
1141
                        list[i] = providers.get(i).getColorTable();
1142
                return list;
1143
        }
1144

    
1145
        /*
1146
         * (non-Javadoc)
1147
         * @see org.gvsig.raster.impl.store.QueryableRaster#getColorTable(java.lang.String)
1148
         */
1149
        public ColorTable getColorTable(String fileName){
1150
                if(fileName == null)
1151
                        return null;
1152
                for(int i = 0; i < providers.size(); i++)
1153
                        if(providers.get(i).getFName().indexOf(fileName) == 0)
1154
                                return providers.get(i).getColorTable();
1155
                return null;
1156
        }
1157

    
1158
        /*
1159
         * (non-Javadoc)
1160
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#rasterToWorld(java.awt.geom.Point2D)
1161
         */
1162
        public Point2D rasterToWorld(Point2D pt) {
1163
                return providers.get(0).rasterToWorld(pt);
1164
        }
1165

    
1166
        /*
1167
         * (non-Javadoc)
1168
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#worldToRaster(java.awt.geom.Point2D)
1169
         */
1170
        public Point2D worldToRaster(Point2D pt) {
1171
                return providers.get(0).worldToRaster(pt);
1172
        }
1173

    
1174
        /*
1175
         * (non-Javadoc)
1176
         * @see org.gvsig.raster.impl.store.QueryableRaster#calcSteps(double, double, double, double, double, double, int, int)
1177
         */
1178
        public double[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY,
1179
                        double nWidth, double nHeight, int bufWidth, int bufHeight){
1180
                return providers.get(0).calcSteps(dWorldTLX, dWorldTLY, dWorldBRX, dWorldBRY, nWidth, nHeight, bufWidth, bufHeight);
1181
        }
1182

    
1183
        /*
1184
         * (non-Javadoc)
1185
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isGeoreferenced()
1186
         */
1187
        public boolean isGeoreferenced() {
1188
                for(int i = 0; i < providers.size(); i++)
1189
                        if(providers.get(i).isGeoreferenced())
1190
                                return true;
1191
                return false;
1192
        }
1193

    
1194
        /*
1195
         * (non-Javadoc)
1196
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getPixelSizeX()
1197
         */
1198
        public double getPixelSizeX() {
1199
                return providers.get(0).getPixelSizeX();
1200
        }
1201

    
1202
        /*
1203
         * (non-Javadoc)
1204
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getPixelSizeY()
1205
         */
1206
        public double getPixelSizeY() {
1207
                return providers.get(0).getPixelSizeY();
1208
        }
1209

    
1210
        /*
1211
         * (non-Javadoc)
1212
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getData(int, int, int)
1213
         */
1214
        public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
1215
                String file = bandList.getBand(band).getFileName();
1216
                int[] posList = bandList.getBandPositionList();
1217
                for(int i = 0; i < providers.size(); i++)
1218
                        if(providers.get(i).getFName().equals(file))
1219
                                return providers.get(i).getData(x, y, posList[band]);
1220
                return null;
1221
        }
1222

    
1223
        /*
1224
         * (non-Javadoc)
1225
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getWktProjection()
1226
         */
1227
        public String getWktProjection() throws RasterDriverException {
1228
                return providers.get(0).getWktProjection();
1229
        }
1230

    
1231
        /*
1232
         * (non-Javadoc)
1233
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isInside(java.awt.geom.Point2D)
1234
         */
1235
        public boolean isInside(Point2D p) {
1236
                if(getProvider(0) != null)
1237
                        return getProvider(0).isInside(p);
1238
                return false;
1239
        }
1240
        
1241
        /*
1242
         * (non-Javadoc)
1243
         * @see org.gvsig.raster.impl.store.QueryableRaster#getDataStore()
1244
         */
1245
        public RasterDataStore getDataStore() {
1246
                return this;
1247
        }
1248

    
1249
        /**
1250
         * 
1251
         * @param band
1252
         * @return
1253
         */
1254
        public AffineTransform getAffineTransform(int band){
1255
                if(band < 0 || band > (getBandCount() - 1))
1256
                        return null;
1257
                int[] providerBand = getProviderFromBandNumber(band);
1258
                if(providerBand != null)
1259
                        return providers.get(providerBand[0]).getAffineTransform();
1260
                return null;
1261
        }
1262

    
1263
        /**
1264
         * Obtiene el n?mero de dataset para un n?mero de banda y la posici?n de la banda dentro de
1265
         * ese dataset.
1266
         * @param bandNumber N?mero de banda
1267
         * @return Dataset que corresponde a la banda pedida y n?mero de banda dentro del dataset (dataset, banda)
1268
         */
1269
        public int[] getProviderFromBandNumber(int bandNumber) {
1270
                int cont = 0;
1271
                for (int i = 0; i < getDataStoreCount(); i++) {
1272
                        RasterProvider provider = providers.get(i);
1273
                        cont += provider.getBandCount();
1274
                        if(cont > bandNumber) {
1275
                                int lastBands = (cont - provider.getBandCount()); //Suma de las bandas de todos los datasets anteriores.
1276
                                return new int[]{i, (bandNumber - lastBands)};
1277
                        }
1278
                }
1279
                return null;
1280
        }
1281

    
1282
        /*
1283
         * (non-Javadoc)
1284
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setAffineTransform(java.awt.geom.AffineTransform)
1285
         */
1286
        public void setAffineTransform(AffineTransform transf){
1287
                for (int i = 0; i < getDataStoreCount(); i++)
1288
                        this.getProvider(i).setAffineTransform(transf);
1289
        }
1290

    
1291
        /**
1292
         * Obtiene la matriz de transformaci?n del propio raster. Esta matriz es la encargada
1293
         * de convertir las coordenadas de la petici?n en coordenadas a las que se pide a la libreria.
1294
         * En gdal, por ejemplo, se piden las coordenadas a la libreria en coordenadas pixel por lo que
1295
         * esta matriz tendr? la georreferenciaci?n asociada en el worldfile o cabecera. Otras librerias como
1296
         * ermapper la petici?n a la libreria se hace en coordenadas geograficas que son las mismas en las
1297
         * que pide el usuario de gvSIG por lo que esta matriz en este caso se inicializa con la identidad.
1298
         * @return
1299
         */
1300
        public AffineTransform getOwnTransformation() {
1301
                if(providers != null && providers.size() > 0)
1302
                        return providers.get(0).getOwnAffineTransform();
1303
                return new AffineTransform();
1304
        }
1305

    
1306
        /*
1307
         * (non-Javadoc)
1308
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isRotated()
1309
         */
1310
        public boolean isRotated() {
1311
                if(providers != null && providers.size() > 0)
1312
                        return providers.get(0).isRotated();
1313
                return false;
1314
        }
1315

    
1316
        /*
1317
         * (non-Javadoc)
1318
         * @see org.gvsig.raster.impl.store.QueryableRaster#setDrawableBands(int[])
1319
         */
1320
        public void setDrawableBands(int[] db) {
1321
                getBands().setDrawableBands(db);
1322
        }
1323
        
1324
        /*
1325
         * (non-Javadoc)
1326
         * @see org.gvsig.raster.impl.store.QueryableRaster#getDrawableBands()
1327
         */
1328
        public int[] getDrawableBands() {
1329
                return getBands().getDrawableBands();
1330
        }
1331

    
1332
        /*
1333
         * (non-Javadoc)
1334
         * @see org.gvsig.raster.impl.store.QueryableRaster#clearDrawableBands()
1335
         */
1336
        public void clearDrawableBands() {
1337
                getBands().clearDrawableBands();
1338
        }
1339

    
1340
        /*
1341
         * (non-Javadoc)
1342
         * @see org.gvsig.raster.impl.store.QueryableRaster#addDrawableBand(int, int)
1343
         */
1344
        public void addDrawableBand(int posRasterBuf, int imageBand) {
1345
                getBands().addDrawableBand(posRasterBuf, imageBand);
1346
        }
1347

    
1348
        /**
1349
         * 
1350
         * @return
1351
         */
1352
        public boolean isReadOnly() {
1353
                return readOnly;
1354
        }
1355

    
1356
        /**
1357
         * 
1358
         * @param readOnly
1359
         */
1360
        public void setReadOnly(boolean readOnly) {
1361
                this.readOnly = readOnly;
1362
                if(readOnly)
1363
                        this.forceToMemory = false;
1364
        }
1365

    
1366
        /*
1367
         * (non-Javadoc)
1368
         * @see org.gvsig.raster.impl.store.QueryableRaster#setMemoryBuffer(boolean)
1369
         */
1370
        public void setMemoryBuffer(boolean memory) {
1371
                this.forceToMemory = memory;
1372
                if(memory)
1373
                        this.readOnly = false;
1374
        }
1375

    
1376
        /**
1377
         * 
1378
         * @return
1379
         */
1380
        public boolean isMemoryBuffer() {
1381
                return forceToMemory;
1382
        }
1383
        
1384
        /*
1385
         * (non-Javadoc)
1386
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewWidth(int, int)
1387
         */
1388
        public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
1389
                int[] providerBand = getProviderFromBandNumber(band);
1390
                RasterProvider prov = getProvider(providerBand[0]);
1391
                return prov.getOverviewWidth(providerBand[1], overview);
1392
        }
1393

    
1394
        /*
1395
         * (non-Javadoc)
1396
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewHeight(int, int)
1397
         */
1398
        public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
1399
                int[] providerBand = getProviderFromBandNumber(band);
1400
                RasterProvider prov = getProvider(providerBand[0]);
1401
                return prov.getOverviewHeight(providerBand[1], overview);
1402
        }
1403

    
1404
        /*
1405
         * (non-Javadoc)
1406
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewCount(int)
1407
         */
1408
        public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
1409
                if(band >= getBandCount())
1410
                        throw new BandAccessException("Wrong band");
1411
                String fileName = getBands().getBand(band).getFileName();
1412
                RasterDataStore store = getDataStore(fileName);
1413
                RasterProvider prov = ((DefaultMultiRasterStore)store).getProvider(0);
1414
                return prov.getOverviewCount(0);
1415
        }
1416

    
1417
        /*
1418
         * (non-Javadoc)
1419
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#overviewsSupport()
1420
         */
1421
        public boolean overviewsSupport() {
1422
                if(getProviders().size() > 0)
1423
                        return getProvider(0).isOverviewsSupported();
1424
                return false;
1425
        }
1426
        
1427
        /*
1428
         * (non-Javadoc)
1429
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#saveGeoreferencingToRmf()
1430
         */
1431
        public void saveGeoreferencingToRmf() throws RmfSerializerException {
1432
                for (int i = 0; i < providers.size(); i++) {
1433
                        providers.get(i).saveObjectToRmf(DefaultRasterProvider.class, providers.get(i));
1434
                }
1435
        }
1436
        
1437
        /*
1438
         * (non-Javadoc)
1439
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#saveSerialInfoToRmf(org.gvsig.fmap.dal.coverage.store.props.SerialInfo)
1440
         */
1441
        public void saveSerialInfoToRmf(TimeSeries serialInfo) throws RmfSerializerException {
1442
                for (int i = 0; i < providers.size(); i++) {
1443
                        providers.get(i).saveObjectToRmf(TimeSeries.class, serialInfo);
1444
                }
1445
        }
1446
        
1447
        /*
1448
         * (non-Javadoc)
1449
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#saveColorTableToRmf(org.gvsig.fmap.dal.coverage.store.props.ColorTable)
1450
         */
1451
        public void saveColorTableToRmf(ColorTable table) throws RmfSerializerException {
1452
                for (int i = 0; i < providers.size(); i++) {
1453
                        providers.get(i).saveObjectToRmf(ColorTable.class, table);
1454
                }
1455
        }
1456
        
1457
        /*
1458
         * (non-Javadoc)
1459
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#loadSerialInfoFromRmf(org.gvsig.fmap.dal.coverage.store.props.SerialInfo)
1460
         */
1461
        public boolean loadSerialInfoFromRmf(TimeSeries serialInfo) {
1462
                for (int i = 0; i < providers.size(); i++) {
1463
                        try {
1464
                                providers.get(i).loadObjectFromRmf(TimeSeries.class, serialInfo);
1465
                                return true;
1466
                        } catch (RmfSerializerException e) {
1467
                                //Prueba hasta que alguno tiene la informaci?n
1468
                        }
1469
                }
1470
                return false;
1471
        }
1472

    
1473
        /*
1474
         * (non-Javadoc)
1475
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getView()
1476
         */
1477
        public Extent getView() {
1478
                if(providers.size() >= 1)
1479
                        return providers.get(0).getView();
1480
                return null;
1481
        }
1482
        
1483
        /*
1484
         * (non-Javadoc)
1485
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getExtentWithoutRot()
1486
         */
1487
        public Extent getExtentWithoutRot() {
1488
                if(providers.size() >= 1)
1489
                        return providers.get(0).getExtentWithoutRot();
1490
                return null;
1491
        }
1492
        
1493
        /*
1494
         * (non-Javadoc)
1495
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOwnAffineTransform()
1496
         */
1497
        public AffineTransform getOwnAffineTransform() {
1498
                if(providers.size() >= 1)
1499
                        return providers.get(0).getOwnAffineTransform();
1500
                return null;
1501
        }
1502
        
1503
        /*
1504
         * (non-Javadoc)
1505
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getAffineTransform()
1506
         */
1507
        public AffineTransform getAffineTransform() {
1508
                if(providers.size() >= 1)
1509
                        return providers.get(0).getAffineTransform();
1510
                return null;
1511
        }
1512
        
1513
        /*
1514
         * (non-Javadoc)
1515
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getProjection()
1516
         */
1517
        public IProjection getProjection() {
1518
                if(providers.size() >= 1)
1519
                        return providers.get(0).getProjection();
1520
                return null;
1521
        }
1522
        
1523
        /*
1524
         * (non-Javadoc)
1525
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getStatistics()
1526
         */
1527
        public Statistics getStatistics() {
1528
                if(stats == null)
1529
                        stats = new MultiDataStoreStatistics(providers);
1530
                return stats;
1531
        }
1532
        
1533
        /*
1534
         * (non-Javadoc)
1535
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getHistogram()
1536
         */
1537
        public HistogramComputer getHistogramComputer() {
1538
                if (histogram == null)
1539
                        histogram = new MultiDataStoreHistogramComputer(this);
1540
                return histogram;
1541
        }
1542
        
1543
        /*
1544
         * (non-Javadoc)
1545
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getMetadata()
1546
         */
1547
        public Metadata getMetadata() {
1548
                if(metadata == null) {
1549
                        int[] bands = new int[providers.size()];
1550
                        for (int i = 0; i < bands.length; i++) 
1551
                                bands[i] = providers.get(i).getBandCount();
1552
                        metadata = new MultiDataStoreMetadata(bands);
1553
                }
1554
                return metadata;
1555
        }
1556
        
1557
        /*
1558
         * (non-Javadoc)
1559
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getColorTable()
1560
         */
1561
        public ColorTable getColorTable() {
1562
                //Solo tiene sentido si tiene un fichero y ese fichero tiene una sola banda
1563
                if(providers.size() == 1)
1564
                        return providers.get(0).getColorTable();
1565
                return null;
1566
        }
1567
        
1568
        /*
1569
         * (non-Javadoc)
1570
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getTransparency()
1571
         */
1572
        public Transparency getTransparency() {
1573
                if(providers.size() >= 1)
1574
                        return providers.get(0).getTransparency();
1575
                return null;
1576
        }
1577
        
1578
        /*
1579
         * (non-Javadoc)
1580
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getColorInterpretation()
1581
         */
1582
        public ColorInterpretation getColorInterpretation() {
1583
                DataStoreColorInterpretation ci = new DataStoreColorInterpretation();
1584
                for (int i = 0; i < providers.size(); i++)
1585
                        ci.addColorInterpretation(providers.get(i).getColorInterpretation());
1586
                return ci;
1587
        }
1588
        
1589
        /*
1590
         * (non-Javadoc)
1591
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#getColorInterpretation(int)
1592
         */
1593
        public ColorInterpretation getColorInterpretation(int file) {
1594
                try {
1595
                        return providers.get(file).getColorInterpretation();
1596
                } catch (ArrayIndexOutOfBoundsException e) {
1597
                        return null;
1598
                }
1599
        }
1600

    
1601
        /*
1602
         * (non-Javadoc)
1603
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isReproyectable()
1604
         */
1605
        public boolean isReproyectable() {
1606
                boolean is = true; 
1607
                for (int i = 0; i < providers.size(); i++) {
1608
                        if(!providers.get(i).isReproyectable())
1609
                                is = false;
1610
                }
1611
                return is;
1612
        }
1613
        
1614
        /*
1615
         * (non-Javadoc)
1616
         * @see org.gvsig.metadata.Metadata#getMetadataName()
1617
         */
1618
        public String getMetadataName() {
1619
                if(providers.size() != 0)
1620
                        return providers.get(0).getName();
1621
                return null;
1622
        }
1623
        
1624
        /*
1625
         * (non-Javadoc)
1626
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#cloneDataStore()
1627
         */
1628
        public RasterDataStore cloneDataStore() throws CloneException {
1629
                DefaultMultiRasterStore ds = new DefaultMultiRasterStore();
1630
                ds.parameters = getParameters();
1631
                
1632
                int[] bands = new int[providers.size()];
1633
                for (int i = 0; i < bands.length; i++) 
1634
                        bands[i] = providers.get(i).getBandCount();
1635
                ds.metadata = new MultiDataStoreMetadata(bands);
1636
                
1637
                for (int i = 0; i < providers.size(); i++) {
1638
                        RasterProvider prov = providers.get(i).cloneProvider();
1639
                        ds.providers.add(prov);
1640
                        ds.metadata.add(providers.get(i).getMetadata());
1641
                }
1642
                ds.bandList = (BandListImpl)bandList.clone();
1643
                ds.stats = new MultiDataStoreStatistics(ds.providers);
1644
                ds.histogram = new MultiDataStoreHistogramComputer(ds);
1645
                return ds;
1646
        }
1647
        
1648
        /*
1649
         * (non-Javadoc)
1650
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isOpen()
1651
         */
1652
        public boolean isOpen() {
1653
                if(providers == null || providers.size() == 0)
1654
                        return false;
1655
                for (int i = 0; i < providers.size(); i++) {
1656
                        if(!providers.get(i).isOpen())
1657
                                return false;
1658
                }
1659
                return true;
1660
        }
1661

    
1662
        /*
1663
         * (non-Javadoc)
1664
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#getProvider()
1665
         */
1666
        public CoverageStoreProvider getProvider() {
1667
                if(providers != null && providers.size() > 0)
1668
                        return providers.get(0);
1669
                return null;
1670
        }
1671
        
1672
        /*
1673
         * (non-Javadoc)
1674
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getInfoByPoint(double, double)
1675
         */
1676
        public String getInfoByPoint(double x, double y, ICancellable cancellable) throws RemoteServiceException {
1677
                return null;
1678
        }
1679

    
1680
        /*
1681
         * (non-Javadoc)
1682
         * @see org.gvsig.fmap.dal.coverage.store.TRasterStore#goTo(int)
1683
         */
1684
        public void goTo(int position) throws OperationNotSupportedException {
1685
                if(!isTimeSupportedByTheProvider())
1686
                        throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1687
                if(getParameters() instanceof TimeStoreParameters) {
1688
                        ((TimeStoreParameters)getParameters()).goTo(position);
1689
                }
1690
        }
1691

    
1692
        /*
1693
         * (non-Javadoc)
1694
         * @see org.gvsig.fmap.dal.coverage.store.TRasterStore#selectNext()
1695
         */
1696
        public void selectNext() throws OperationNotSupportedException {
1697
                if(!isTimeSupportedByTheProvider())
1698
                        throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1699
                if(getParameters() instanceof TimeStoreParameters) {
1700
                        ((TimeStoreParameters)getParameters()).selectNextInstant();
1701
                }
1702
        }
1703

    
1704
        /*
1705
         * (non-Javadoc)
1706
         * @see org.gvsig.fmap.dal.coverage.store.TRasterStore#selectPrev()
1707
         */
1708
        public void selectPrev() throws OperationNotSupportedException {
1709
                if(!isTimeSupportedByTheProvider())
1710
                        throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1711
                if(getParameters() instanceof TimeStoreParameters) {
1712
                        ((TimeStoreParameters)getParameters()).selectPrevInstant();
1713
                }
1714
        }
1715
        
1716
        /*
1717
         * (non-Javadoc)
1718
         * @see org.gvsig.fmap.dal.coverage.store.TRasterStore#setTime(org.gvsig.timesupport.Time)
1719
         */
1720
        public void setTime(Time time) throws TimeException, OperationNotSupportedException {
1721
                if(!isTimeSupportedByTheProvider())
1722
                        throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1723
                
1724
        }
1725
        
1726
        /**
1727
         * Returns true whether all providers support time
1728
         * @return
1729
         */
1730
        private boolean isTimeSupportedByTheProvider() {
1731
                for (int i = 0; i < providers.size(); i++) {
1732
                        if(!providers.get(i).isTimeSupported())
1733
                                return false;
1734
                }
1735
                return true;
1736
        }
1737
        
1738
        /*
1739
         * (non-Javadoc)
1740
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isRasterEnclosed()
1741
         */
1742
        public boolean isRasterEnclosed() {
1743
                return getProvider(0).isRasterEnclosed();
1744
        }
1745

    
1746
        /*
1747
         * (non-Javadoc)
1748
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getCoordsInLevel(java.awt.geom.Point2D, int, int, int)
1749
         */
1750
        public Extent getCoordsInLevel(Point2D viewCenter, int level, int w, int h) {
1751
                try {
1752
                        return ((TiledRasterProvider)getProvider(0)).getCoordsInLevel(viewCenter, level, w, h);
1753
                } catch (ClassCastException e) {
1754
                        return null;
1755
                }
1756
        }
1757

    
1758
        /*
1759
         * (non-Javadoc)
1760
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getCoordsInTheNearestLevel(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int)
1761
         */
1762
        public Extent getCoordsInTheNearestLevel(Extent extent, int w, int h) {
1763
                try {
1764
                        return ((TiledRasterProvider)getProvider(0)).getCoordsInTheNearestLevel(extent, w, h);
1765
                } catch (ClassCastException e) {
1766
                        return null;
1767
                }
1768
        }
1769

    
1770
        /*
1771
         * (non-Javadoc)
1772
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getZoomLevels()
1773
         */
1774
        public int getZoomLevels() {
1775
                try {
1776
                        return ((TiledRasterProvider)getProvider(0)).getZoomLevels();
1777
                } catch (ClassCastException e) {
1778
                        return -1;
1779
                }
1780
        }
1781

    
1782
        /*
1783
         * (non-Javadoc)
1784
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getNearestLevel(double)
1785
         */
1786
        public int getNearestLevel(double pixelSize) {
1787
                try {
1788
                        return ((TiledRasterProvider)getProvider(0)).getNearestLevel(pixelSize);
1789
                } catch (ClassCastException e) {
1790
                        return -1;
1791
                }
1792
        }
1793
        
1794
        /*
1795
         * (non-Javadoc)
1796
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setTileServer(java.lang.Class)
1797
         */
1798
        public void setTileServer(Class<?> tileServer) {
1799
                try {
1800
                        ((TiledRasterProvider)getProvider(0)).setTileServer(tileServer);
1801
                } catch (ClassCastException e) {
1802
                }
1803
        }
1804

    
1805
}