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 @ 464

History | View | Annotate | Download (57.6 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.datastruct.TimeInfo;
41
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
42
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
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.props.ColorInterpretation;
57
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
58
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
59
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
60
import org.gvsig.fmap.dal.coverage.store.props.SerialInfo;
61
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
62
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
63
import org.gvsig.fmap.dal.exception.InitializeException;
64
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider;
65
import org.gvsig.raster.cache.tile.TileCacheLocator;
66
import org.gvsig.raster.cache.tile.TileCacheManager;
67
import org.gvsig.raster.cache.tile.exception.TileGettingException;
68
import org.gvsig.raster.cache.tile.provider.TileListener;
69
import org.gvsig.raster.impl.DefaultRasterManager;
70
import org.gvsig.raster.impl.buffer.cache.RasterReadOnlyBuffer;
71
import org.gvsig.raster.impl.datastruct.BandListImpl;
72
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
73
import org.gvsig.raster.impl.datastruct.ExtentImpl;
74
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
75
import org.gvsig.raster.impl.provider.RasterProvider;
76
import org.gvsig.raster.impl.provider.TiledRasterProvider;
77
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
78
import org.gvsig.raster.impl.store.properties.MultiDataStoreHistogramComputer;
79
import org.gvsig.raster.impl.store.properties.MultiDataStoreMetadata;
80
import org.gvsig.raster.impl.store.properties.MultiDataStoreStatistics;
81

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
475
                //Buffer ReadOnly
476

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

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

    
510
                return raster;
511
        }
512

    
513
        /*
514
         * (non-Javadoc)
515
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double, boolean)
516
         */
517
        public Buffer getWindow(double ulx, double uly, double w, double h, boolean adjustToExtent)
518
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
519
                //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
520
                //tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h
521
                Extent ext = getExtent();
522
                Point2D pInit = providers.get(0).rasterToWorld(new Point2D.Double(0, 0));
523
                Point2D pEnd = providers.get(0).rasterToWorld(new Point2D.Double((int)getWidth(), (int)getHeight()));
524
                double wRaster = Math.abs(pEnd.getX() - pInit.getX());
525
                double hRaster = Math.abs(pEnd.getY() - pInit.getY());
526
                double lrx = (((int)(ext.getULX() - wRaster)) == ((int)ext.getLRX())) ? (ulx - w) : (ulx + w);
527
                double lry = (((int)(ext.getULY() - hRaster)) == ((int)ext.getLRY())) ? (uly - h) : (uly + h);
528

    
529
                //Extent selectedExtent = new Extent(ulx, uly, lrx, lry);
530

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

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

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

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

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

    
560
                //Buffer ReadOnly
561

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

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

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

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

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

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

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

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

    
694
                //Buffer ReadOnly
695

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

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

    
724
                return raster;
725
        }
726

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

    
736
                //Buffer ReadOnly
737

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

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

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

    
777
                //Buffer ReadOnly
778

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

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

    
806
                return raster;
807
        }
808

    
809
        //******************************
810
        //Setters and Getters
811
        //******************************
812

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

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

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

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

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

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

    
880
                if (dt.length == 0)
881
                        return null;
882

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

    
892
                return dt;
893
        }
894

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

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

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

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

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

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

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

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

    
1031
                return providers.get(0).getNoDataValue();
1032
        }
1033

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

    
1042
                return providers.get(0).isNoDataEnabled();
1043
        }
1044

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1678
        public String getSerialDescription() throws OperationNotSupportedException {
1679
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1680
        }
1681

    
1682
        public String getSerialName() throws OperationNotSupportedException {
1683
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1684
        }
1685

    
1686
        public void goTo(int position) throws OperationNotSupportedException {
1687
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1688
        }
1689

    
1690
        public void selectNext() throws OperationNotSupportedException {
1691
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1692
        }
1693

    
1694
        public void selectPrev() throws OperationNotSupportedException {
1695
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1696
        }
1697

    
1698
        public void selectSerial(String serialName) throws OperationNotSupportedException {
1699
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1700
        }
1701

    
1702
        public void setSerialDescription(String serialDescription) throws OperationNotSupportedException {
1703
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1704
        }
1705

    
1706
        public void setSerialName(String serialName) throws OperationNotSupportedException {
1707
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1708
        }
1709

    
1710
        public void setTime(TimeInfo time) throws TimeException, OperationNotSupportedException {
1711
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1712
        }
1713

    
1714
        public void addTemporalDataStore(RasterDataStore store) throws OperationNotSupportedException {
1715
                throw new OperationNotSupportedException("Not supported for a MultiRasterDataset");
1716
        }
1717
        
1718
        /*
1719
         * (non-Javadoc)
1720
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isRasterEnclosed()
1721
         */
1722
        public boolean isRasterEnclosed() {
1723
                return getProvider(0).isRasterEnclosed();
1724
        }
1725

    
1726
        /*
1727
         * (non-Javadoc)
1728
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getCoordsInLevel(java.awt.geom.Point2D, int, int, int)
1729
         */
1730
        public Extent getCoordsInLevel(Point2D viewCenter, int level, int w, int h) {
1731
                try {
1732
                        return ((TiledRasterProvider)getProvider(0)).getCoordsInLevel(viewCenter, level, w, h);
1733
                } catch (ClassCastException e) {
1734
                        return null;
1735
                }
1736
        }
1737

    
1738
        /*
1739
         * (non-Javadoc)
1740
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getCoordsInTheNearestLevel(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int)
1741
         */
1742
        public Extent getCoordsInTheNearestLevel(Extent extent, int w, int h) {
1743
                try {
1744
                        return ((TiledRasterProvider)getProvider(0)).getCoordsInTheNearestLevel(extent, w, h);
1745
                } catch (ClassCastException e) {
1746
                        return null;
1747
                }
1748
        }
1749

    
1750
        /*
1751
         * (non-Javadoc)
1752
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getZoomLevels()
1753
         */
1754
        public int getZoomLevels() {
1755
                try {
1756
                        return ((TiledRasterProvider)getProvider(0)).getZoomLevels();
1757
                } catch (ClassCastException e) {
1758
                        return -1;
1759
                }
1760
        }
1761

    
1762
        /*
1763
         * (non-Javadoc)
1764
         * @see org.gvsig.fmap.dal.coverage.store.RemoteRasterStore#getNearestLevel(double)
1765
         */
1766
        public int getNearestLevel(double pixelSize) {
1767
                try {
1768
                        return ((TiledRasterProvider)getProvider(0)).getNearestLevel(pixelSize);
1769
                } catch (ClassCastException e) {
1770
                        return -1;
1771
                }
1772
        }
1773
        
1774
        /*
1775
         * (non-Javadoc)
1776
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setTileServer(java.lang.Class)
1777
         */
1778
        public void setTileServer(Class<?> tileServer) {
1779
                try {
1780
                        ((TiledRasterProvider)getProvider(0)).setTileServer(tileServer);
1781
                } catch (ClassCastException e) {
1782
                }
1783
        }
1784
}