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

History | View | Annotate | Download (54.8 KB)

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

    
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.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.fmap.dal.DataStoreParameters;
32
import org.gvsig.fmap.dal.coverage.RasterLibrary;
33
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
34
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
35
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand;
36
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
37
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
38
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
39
import org.gvsig.fmap.dal.coverage.exception.FileNotExistsException;
40
import org.gvsig.fmap.dal.coverage.exception.FileNotFoundInListException;
41
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
42
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
43
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
44
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
45
import org.gvsig.fmap.dal.coverage.exception.OperationNotSupportedException;
46
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
47
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
48
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
49
import org.gvsig.fmap.dal.coverage.grid.render.TileListener;
50
import org.gvsig.fmap.dal.coverage.store.MultiRasterStore;
51
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
52
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
53
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
54
import org.gvsig.fmap.dal.coverage.store.props.Histogram;
55
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
56
import org.gvsig.fmap.dal.coverage.store.props.SerialInfo;
57
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
58
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
59
import org.gvsig.fmap.dal.exception.InitializeException;
60
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider;
61
import org.gvsig.raster.impl.DefaultRasterManager;
62
import org.gvsig.raster.impl.buffer.cache.RasterReadOnlyBuffer;
63
import org.gvsig.raster.impl.datastruct.BandListImpl;
64
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
65
import org.gvsig.raster.impl.datastruct.ExtentImpl;
66
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
67
import org.gvsig.raster.impl.provider.RasterProvider;
68
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
69
import org.gvsig.raster.impl.store.properties.MultiDataStoreHistogram;
70
import org.gvsig.raster.impl.store.properties.MultiDataStoreMetadata;
71
import org.gvsig.raster.impl.store.properties.MultiDataStoreStatistics;
72

    
73
/**
74
 * Clase que representa una imagen de raster georreferenciada formada por varias
75
 * imagenes de disco que tienen la misma extensi?n. Contiene funcionalidades
76
 * para abrir ficheros, gestionar el extent, pintar el raster sobre un DataImage
77
 * con su gesti?n de bandas correspondiente.
78
 *
79
 * @author Nacho Brodin (nachobrodin@gmail.com)
80
 */
81
public class DefaultMultiRasterStore extends AbstractRasterDataStore implements MultiRasterStore {
82
        protected ArrayList<RasterProvider>     providers     = new ArrayList<RasterProvider>();
83
        protected BandListImpl                  bandList      = new BandListImpl();
84
        protected MultiDataStoreStatistics      stats         = null;
85
        protected MultiDataStoreHistogram       histogram     = null;
86
        protected MultiDataStoreMetadata        metadata      = null;
87
        /**
88
         * Flag que fuerza al buffer de solo lectura
89
         */
90
        protected boolean                       readOnly      = false;
91
        /**
92
         * Flag que fuerza al buffer en memoria
93
         */
94
        protected boolean                       forceToMemory = false;
95
        protected int                           percent       = 0;
96
        
97

    
98
        //TODO: FUNCIONALIDAD: Contructores igual a RasterDataset + String[] nameFiles
99
        public DefaultMultiRasterStore() {
100
                super();
101
        }
102

    
103
        /**
104
         * Crea un objeto MultiRasterDataset nuevo con los mismos ficheros
105
         * que el actual.
106
         * @return MultiRasterDataset
107
         */
108
        public RasterDataStore newDataStore() {
109
                try {
110
                        String[] fileList = getNameDatasetStringList();
111
                        DefaultMultiRasterStore multiRasterDataset = (DefaultMultiRasterStore)DefaultRasterManager.getInstance().open(fileList[0]);
112
                        for (int j = 1; j < fileList.length; j++)
113
                                multiRasterDataset.addDataStore(new String[] { fileList[j] });
114
                        return multiRasterDataset;
115
                } catch (FileNotFoundInListException e) {
116
                        return null;
117
                } catch (NotSupportedExtensionException e) {
118
                        return null;
119
                } catch (RasterDriverException e) {
120
                        return null;
121
                } catch (OperationNotSupportedException e) {
122
                        //No puede darse. El metodo es @override 
123
                }
124
                return null;
125
        }
126
        
127
        /*
128
         * (non-Javadoc)
129
         * @see org.gvsig.raster.impl.dataset.QueryableRaster#getProviders()
130
         */
131
        public ArrayList<RasterProvider> getProviders() {
132
                return providers;
133
        }
134
        
135
        /*
136
         * (non-Javadoc)
137
         * @see org.gvsig.raster.impl.store.QueryableRaster#getProvider(int)
138
         */
139
        public RasterProvider getProvider(int i) {
140
                if(providers == null || 
141
                        providers.size() == 0 || 
142
                        i < 0 || 
143
                        i >= providers.size())
144
                        return null;
145
                return providers.get(i);
146
        }
147
        
148
        /*
149
         * (non-Javadoc)
150
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getName()
151
         */
152
        public String getName() {
153
                if(providers != null && providers.size() >= 1)
154
                        return providers.get(0).getFName();
155
                return null;
156
        }
157
        
158
        /*
159
         * (non-Javadoc)
160
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#getFName(int)
161
         */
162
        public String getFName(int i) {
163
                if(providers != null && providers.size() >= (i + 1))
164
                        return providers.get(i).getFName();
165
                return null;
166
        }
167

    
168
        /*
169
         * (non-Javadoc)
170
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#addDataStore(org.gvsig.fmap.dal.coverage.store.RasterDataStore)
171
         */
172
        public void addDataStore(RasterDataStore f)throws FileNotFoundInListException, InvalidSourceException, OperationNotSupportedException {
173
                if(f instanceof DefaultMultiRasterStore) {
174
                        for (int i = 0; i < ((DefaultMultiRasterStore)f).providers.size(); i++) {
175
                                RasterProvider prov = providers.get(i);
176
                                providers.add(prov);
177
                                addBands(prov);
178
                                if(stats == null)
179
                                        stats = new MultiDataStoreStatistics(((QueryableRaster)f).getProviders());
180
                                else
181
                                        stats.addProvider(prov);
182
                        }
183
                }
184
        }
185

    
186
        /*
187
         * 
188
         */
189
        public void addDataStore(RasterProvider provider) throws OperationNotSupportedException {
190
                providers.add(provider);
191
                addBands(provider);
192
                if(stats == null) 
193
                        stats = new MultiDataStoreStatistics(providers);
194
                else
195
                        stats.addProvider(provider);
196
        }
197
        
198
        /*
199
         * (non-Javadoc)
200
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#addDataStore(java.lang.String[])
201
         */
202
        public void addDataStore(String[] fileName)throws FileNotFoundInListException, NotSupportedExtensionException, RasterDriverException, OperationNotSupportedException {
203
                if(fileName == null || fileName.length < 1)
204
                        throw new FileNotFoundInListException("Error in list.");
205
                if(findDataset(fileName[0]))
206
                        throw new FileNotFoundInListException("The file already is in list.");
207
                for (int i = 0; i < fileName.length; i++) {
208
                        DefaultRasterProvider ds = DefaultRasterProvider.singleDatasetInstance(fileName[i]);
209
                        addDataStore(ds);
210
                }
211
        }
212
        
213
        /*
214
         * (non-Javadoc)
215
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#addDataStore(java.lang.String)
216
         */
217
        public void addDataStore(String fileName)throws FileNotFoundInListException, NotSupportedExtensionException, RasterDriverException, OperationNotSupportedException {
218
                addDataStore(new String[]{fileName});
219
        }
220
        
221
        /**
222
         * A?ade el fichero a lista de georrasterfiles y sus bandas a la lista de bandas
223
         * @param grf
224
         */
225
        public void addBands(RasterProvider prov) {
226
                if(prov == null)
227
                        return;
228

    
229
                for(int i = 0; i < prov.getBandCount(); i++)
230
                        try {
231
                                int dataType = prov.getDataType()[i];
232
                                DatasetBand band = new DatasetBandImpl(prov.getFName(), i, dataType);
233
                                bandList.addBand(band, i);
234
                        } catch(BandNotFoundInListException ex) {
235
                                //No a?adimos la banda
236
                        }
237
        }
238

    
239
        /*
240
         * (non-Javadoc)
241
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#removeDataStore(java.lang.String)
242
         */
243
        public void removeDataStore(String fileName) throws OperationNotSupportedException {
244
                for(int i = 0; i < providers.size(); i++)
245
                        if(providers.get(i).getFName().equals(fileName)) {
246
                                providers.remove(i);
247
                                bandList.removeBands(fileName);
248
                                return;
249
                        }
250
        }
251

    
252
        /*
253
         * (non-Javadoc)
254
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#removeDataStore(org.gvsig.fmap.dal.coverage.store.RasterDataStore)
255
         */
256
        public void removeDataStore(RasterDataStore file) throws OperationNotSupportedException {
257
                for(int i = 0; i < providers.size(); i++)
258
                        if(providers.get(i).getFName().equals(file.getName())) {
259
                                providers.remove(i);
260
                                bandList.removeBands(file.getName());
261
                                return;
262
                        }
263
        }
264

    
265
        /*
266
         * (non-Javadoc)
267
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getDataStoreCount()
268
         */
269
        public int getDataStoreCount() {
270
                return providers.size();
271
        }
272

    
273
        /**
274
         * Encuentra un fichero en la lista.
275
         * @param file Fichero b?scado.
276
         * @return true si se ha hallado el fichero y false si no se
277
         * ha encontrado
278
         */
279
        public boolean findDataset(RasterDataStore file) {
280
                for(int i = 0; i < providers.size(); i++) {
281
                        RasterProvider prov = providers.get(i);
282
                        if(        prov.getFName().equals(file.getName()))
283
                                return true;
284
                }
285
                return false;
286
        }
287

    
288
        /**
289
         * Encuentra un fichero en la lista.
290
         * @param file Fichero b?scado.
291
         * @return true si se ha hallado el fichero y false si no se
292
         * ha encontrado
293
         */
294
        public boolean findDataset(String fileName) {
295
                for(int i = 0; i < providers.size(); i++)
296
                        if(providers.get(i).getFName().equals(fileName))
297
                                return true;
298
                return false;
299
        }
300

    
301
        /*
302
         * (non-Javadoc)
303
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#close()
304
         */
305
        public void close() {
306
                for(int i = 0; i < providers.size(); i++)
307
                        providers.get(i).close();
308
                providers.clear();
309
                bandList.clear();
310
        }
311

    
312
        /*
313
         * (non-Javadoc)
314
         * @see org.gvsig.fmap.dal.coverage.store.MultiRasterStore#getNameDatasetStringList()
315
         */
316
        public String[] getNameDatasetStringList() {
317
                String[] list = new String[providers.size()];
318
                for(int k = 0; k < providers.size(); k++)
319
                        list[k] = providers.get(k).getFName();
320
                return list;
321
        }
322

    
323
        /**
324
         * Inicializa el buffer a valores NoData
325
         * @param raster Buffer a inicializar
326
         * @param bandList Lista de bandas
327
         */
328
        private void initBufferToNoData(Buffer raster, BandList bandList) {
329
                for(int i = 0; i < bandList.getDrawableBandsCount(); i++)
330
                        switch(getDataType()[0]) {
331
                        case Buffer.TYPE_BYTE:raster.assign(i, raster.getByteNoDataValue());break;
332
                        case Buffer.TYPE_SHORT:raster.assign(i, raster.getShortNoDataValue());break;
333
                        case Buffer.TYPE_INT:raster.assign(i, raster.getIntNoDataValue());break;
334
                        case Buffer.TYPE_FLOAT:raster.assign(i, raster.getFloatNoDataValue());break;
335
                        case Buffer.TYPE_DOUBLE:raster.assign(i, raster.getNoDataValue());break;
336
                        }
337
        }
338

    
339
        /**
340
         * A partir de la lista de bandas que dice como cargar el buffer se crean tantos Buffer como ficheros intervienen
341
         * . Cada Buffer corresponde a un dataset del RasterMultiDataset y en ellos se reserva memoria solo para las
342
         * bandas que vayan a ser cargadas. Las otras se asignaran a la banda NotValid.
343
         * @param bl Lista de bandas
344
         * @param width Ancho
345
         * @param height Alto
346
         * @return Lista de buffers en el que cada uno corresponde a un dataset.
347
         */
348
        private Buffer[] mallocBuffersDatasets(BandList bl, int width, int height) {
349
                Buffer[] buffers = new Buffer[getDataStoreCount()];
350
                for(int i = 0; i < getDataStoreCount(); i++) {
351
                        if(forceToMemory)
352
                                buffers[i] =  DefaultRasterManager.getInstance().createMemoryBuffer(getProvider(i).getDataType()[0], width, height, getProvider(i).getBandCount(), false);
353
                        else
354
                                buffers[i] =  DefaultRasterManager.getInstance().createBuffer(getProvider(i).getDataType()[0], width, height, getProvider(i).getBandCount(), false);
355

    
356
                        //Asignamos las bandas de cada fichero que no se pintan a null y las que se pintan se reserva memoria
357
                        String name = getProvider(i).getName();
358
                        for(int j = 0; j < getProvider(i).getBandCount(); j ++)
359
                                if(bl.getBufferBandToDraw(name, j) == null)
360
                                        buffers[i].assignBandToNotValid(j);
361
                                else
362
                                        buffers[i].mallocOneBand(getProvider(i).getDataType()[0], width, height, j);
363
                }
364
                return buffers;
365
        }
366

    
367
        /**
368
         * Mezcla los buffers de los dataset que forman el RasterMultiDataset sobre un solo buffer
369
         * con las directrices que marca la lista de bandas. Esta funci?n es la que realiza el switch
370
         * de las bandas.
371
         * @param b Buffer sobre el que se mezcla
372
         * @param bDataset Buffers que corresponden a los datasets
373
         * @param bandList Objeto que contiene la informaci?n de que bandas de los dataset se escriben sobre
374
         * que banda del buffer.
375
         */
376
        private void mergeBuffers(Buffer b, Buffer[] bDataset, BandList bandList) {
377
                for(int iDataset = 0; iDataset < getDataStoreCount(); iDataset++){ //Ojo! Los datasets est?n en la misma posici?n que se han metido en mallocBuffersDatasets
378
                        String name = getProvider(iDataset).getFName();
379

    
380
                        for(int iBand = 0; iBand < getProvider(iDataset).getBandCount(); iBand ++) {
381
                                int[] posToDraw = bandList.getBufferBandToDraw(name, iBand);
382
                                if(posToDraw != null)
383
                                        for(int i = 0; i < posToDraw.length; i ++)
384
                                                switch(getDataType()[iDataset]) {
385
                                                case Buffer.TYPE_BYTE: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
386
                                                case Buffer.TYPE_SHORT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
387
                                                case Buffer.TYPE_INT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
388
                                                case Buffer.TYPE_FLOAT: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
389
                                                case Buffer.TYPE_DOUBLE: b.assignBand(posToDraw[i], bDataset[iDataset].getBand(iBand)); break;
390
                                                }
391
                        }
392
                }
393
        }
394

    
395
        /*
396
         * (non-Javadoc)
397
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double)
398
         */
399
        public Buffer getWindowRaster(double ulx, double uly, double lrx, double lry)
400
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
401
                //Extent selectedExtent = new Extent(ulx, uly, lrx, lry);
402

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

    
406
                Point2D p1 = providers.get(0).worldToRaster(new Point2D.Double(ulx, uly));
407
                Point2D p2 = providers.get(0).worldToRaster(new Point2D.Double(lrx, lry));
408

    
409
                //Para el valor mayor redondeamos por arriba. Para el valor menor redondeamos por abajo.
410
                double p1X = (p1.getX() > p2.getX()) ? Math.ceil(p1.getX()) : Math.floor(p1.getX());
411
                double p1Y = (p1.getY() > p2.getY()) ? Math.ceil(p1.getY()) : Math.floor(p1.getY());
412
                double p2X = (p2.getX() > p1.getX()) ? Math.ceil(p2.getX()) : Math.floor(p2.getX());
413
                double p2Y = (p2.getY() > p1.getY()) ? Math.ceil(p2.getY()) : Math.floor(p2.getY());
414

    
415
                int width = (int)Math.abs(p1X - p2X);
416
                int height = (int)Math.abs(p1Y - p2Y);
417

    
418
                //Ajustamos por si nos hemos salido del raster
419
                if(((int)(Math.min(p1X, p2X) + width)) > getWidth())
420
                        width = (int)(getWidth() - Math.min(p1X, p2X));
421
                if(((int)(Math.min(p1Y, p2Y) + height)) > getHeight())
422
                        height = (int)(getHeight() - Math.min(p1Y, p2Y));
423

    
424
                if (p1X < 0)
425
                        p1X = 0;
426
                if (p1Y < 0)
427
                        p1Y = 0;
428
                if (p2X > getWidth())
429
                        p2X = getWidth();
430
                if (p2Y > getHeight())
431
                        p2Y = getHeight();
432

    
433
                int mallocNBands = 0;
434
                if(bandList.getDrawableBands() != null)
435
                        mallocNBands = bandList.getDrawableBands().length;
436
                else
437
                        mallocNBands = bandList.getDrawableBandsCount();
438

    
439
                //Buffer ReadOnly
440

    
441
                if(isReadOnly()) {
442
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], width, height, getBandCount());
443
                        if(rb instanceof RasterReadOnlyBuffer) {
444
                                try {
445
                                        ((RasterReadOnlyBuffer)rb).setBufferParams(this, (int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), bandList);
446
                                } catch (FileNotExistsException e) {
447
                                        //Esto no debe darse ya que se comprueba al hacer el open.
448
                                        return null;
449
                                } catch (NotSupportedExtensionException e) {
450
                                        //Esto no debe darse ya que se comprueba al hacer el open
451
                                        return null;
452
                                }
453
                                return rb;
454
                        }
455
                }
456

    
457
                //Buffer RW
458

    
459
                Buffer raster = null;
460
                if(forceToMemory) //Fuerza siempre buffer en memoria
461
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], width, height, mallocNBands, false);
462
                else
463
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], width, height, mallocNBands, false);
464

    
465
                for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
466
                        raster.assignBandToNotValid(iBand);
467

    
468
                //Reservamos memoria para los buffers por dataset
469
                Buffer[] bufferDatasets = mallocBuffersDatasets(bandList, width, height);
470

    
471
                //Si hemos redondeado los pixeles de la petici?n (p1 y p2) por arriba y por abajo deberemos calcular un extent mayor
472
                //equivalente a los pixeles redondeados.
473
                Point2D wc1 = providers.get(0).rasterToWorld(new Point2D.Double(p1X, p1Y));
474
                Point2D wc2 = providers.get(0).rasterToWorld(new Point2D.Double(p2X, p2Y));
475
                for(int i = 0; i < getDataStoreCount(); i++)
476
                        bufferDatasets[i] = ((DefaultRasterProvider)providers.get(i)).getWindowRaster(wc1.getX(), wc1.getY(), wc2.getX(), wc2.getY(), bandList, bufferDatasets[i]);
477

    
478
                //Mezclamos los buffers de cada dataset en un solo buffer
479
                mergeBuffers(raster, bufferDatasets, bandList);
480

    
481
                for (int i = 0; i < bufferDatasets.length; i++)
482
                        bufferDatasets[i].free();
483

    
484
                return raster;
485
        }
486

    
487
        /*
488
         * (non-Javadoc)
489
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double, boolean)
490
         */
491
        public Buffer getWindowRaster(double ulx, double uly, double w, double h, boolean adjustToExtent)
492
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
493
                //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
494
                //tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h
495
                Extent ext = getExtent();
496
                Point2D pInit = providers.get(0).rasterToWorld(new Point2D.Double(0, 0));
497
                Point2D pEnd = providers.get(0).rasterToWorld(new Point2D.Double((int)getWidth(), (int)getHeight()));
498
                double wRaster = Math.abs(pEnd.getX() - pInit.getX());
499
                double hRaster = Math.abs(pEnd.getY() - pInit.getY());
500
                double lrx = (((int)(ext.getULX() - wRaster)) == ((int)ext.getLRX())) ? (ulx - w) : (ulx + w);
501
                double lry = (((int)(ext.getULY() - hRaster)) == ((int)ext.getLRY())) ? (uly - h) : (uly + h);
502

    
503
                //Extent selectedExtent = new Extent(ulx, uly, lrx, lry);
504

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

    
508
                Point2D p1 = providers.get(0).worldToRaster(new Point2D.Double(ulx, uly));
509
                Point2D p2 = providers.get(0).worldToRaster(new Point2D.Double(lrx, lry));
510
                int width = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX()));
511
                int height = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY()));
512

    
513
                //Ajustamos por si nos hemos salido del raster
514
                if(((int)(p1.getX() + width)) > getWidth())
515
                        width = (int)(getWidth() - p1.getX());
516
                if(((int)(p1.getY() + height)) > getHeight())
517
                        height = (int)(getHeight() - p1.getY());
518

    
519
                if (p1.getX() < 0)
520
                        p1.setLocation(0, p1.getY());
521
                if (p1.getY() < 0)
522
                        p1.setLocation(p1.getX(), 0);
523
                if (p2.getX() > getWidth())
524
                        p2.setLocation(getWidth(), p2.getY());
525
                if (p2.getY() > getHeight())
526
                        p2.setLocation(p2.getX(), getHeight());
527

    
528
                int mallocNBands = 0;
529
                if(bandList.getDrawableBands() != null)
530
                        mallocNBands = bandList.getDrawableBands().length;
531
                else
532
                        mallocNBands = bandList.getDrawableBandsCount();
533

    
534
                //Buffer ReadOnly
535

    
536
                if(isReadOnly()) {
537
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], width, height, getBandCount());
538
                        if(rb instanceof RasterReadOnlyBuffer) {
539
                                try {
540
                                        ((RasterReadOnlyBuffer)rb).setBufferParams(this, (int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), bandList);
541
                                } catch (FileNotExistsException e) {
542
                                        //Esto no debe darse ya que se comprueba al hacer el open.
543
                                        return null;
544
                                } catch (NotSupportedExtensionException e) {
545
                                        //Esto no debe darse ya que se comprueba al hacer el open
546
                                        return null;
547
                                }
548
                                return rb;
549
                        }
550
                }
551

    
552
                //Buffer RW
553

    
554
                Buffer raster = null;
555
                if(forceToMemory) //Fuerza siempre buffer en memoria
556
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], width, height, mallocNBands, false);
557
                else
558
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], width, height, mallocNBands, false);
559

    
560
                for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
561
                        raster.assignBandToNotValid(iBand);
562

    
563
                //Si no vamos a ajustar el extent al raster inicializamos el buffer a noData ya que este puede ser
564
                //m?s grande y salirse de los l?mites.
565
                if(!adjustToExtent)
566
                         initBufferToNoData(raster, bandList);
567

    
568
                //Reservamos memoria para los buffers por dataset
569
                Buffer[] bufferDatasets = mallocBuffersDatasets(bandList, width, height);
570

    
571
                //Si hemos redondeado los pixeles de la petici?n (p1 y p2) por arriba y por abajo deberemos calcular un extent mayor
572
                //equivalente a los pixeles redondeados.
573
                Point2D wc1 = providers.get(0).rasterToWorld(new Point2D.Double(Math.floor(p1.getX()), Math.floor(p1.getY())));
574
                Point2D wc2 = providers.get(0).rasterToWorld(new Point2D.Double(Math.ceil(p2.getX()), Math.ceil(p2.getY())));
575
                for(int i = 0; i < getDataStoreCount(); i++)
576
                        bufferDatasets[i] = ((DefaultRasterProvider)providers.get(i)).getWindowRaster(wc1.getX(), wc1.getY(), Math.abs(wc2.getX() - wc1.getX()), Math.abs(wc2.getY() - wc1.getY()), bandList, bufferDatasets[i], adjustToExtent);
577
                        //bufferDatasets[i] = ((RasterDataStore)files.get(i)).getWindowRaster(x, y, w, h, bandList, bufferDatasets[i], adjustToExtent);
578

    
579
                //Mezclamos los buffers de cada dataset en un solo buffer
580
                mergeBuffers(raster, bufferDatasets, bandList);
581

    
582
                for (int i = 0; i < bufferDatasets.length; i++)
583
                        bufferDatasets[i].free();
584

    
585
                return raster;
586
        }
587
        
588
        /*
589
         * (non-Javadoc)
590
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.grid.render.TileListener, int)
591
         */
592
        public void getWindowRaster(double ulx, double uly, double lrx, double lry, 
593
                int bufWidth, int bufHeight, TileListener listener)
594
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
595
                double[] step = null;
596
                Buffer buf = null;
597
                
598
                //Esta secci?n es para que no supersamplee el driver y pueda hacerse en el cliente
599
                if(!currentQuery.isSupersamplingLoadingBuffer()) {
600
                        //nWidth = ((adjustedDataExtent.width() * mDataset.getDataset(0).getWidth()) / mDataset.getExtentForRequest().width());
601
                        //nHeight = ((adjustedDataExtent.height() * mDataset.getDataset(0).getHeight()) / mDataset.getExtentForRequest().height());
602
                        Point2D p1 = worldToRaster(new Point2D.Double(ulx, uly));
603
                        Point2D p2 = worldToRaster(new Point2D.Double(lrx, lry));
604
                        nWidth = Math.abs(p1.getX() - p2.getX());
605
                        nHeight = Math.abs(p1.getY() - p2.getY());
606

    
607
                        if(bufWidth > Math.ceil(nWidth) && bufHeight > Math.ceil(nHeight)) {
608
                                step = calcSteps(ulx, uly, lrx, lry, nWidth, nHeight, bufWidth, bufHeight);
609
                                buf = getWindowRaster(ulx, uly, lrx, lry);
610
                        }
611
                } 
612
                
613
                if(buf == null)
614
                        buf = getWindowRaster(ulx, uly, lrx, lry, bufWidth, bufHeight, true);
615
                
616
                buf.setDataExtent(new Rectangle2D.Double(ulx, uly, Math.abs(ulx - lrx), Math.abs(uly - lry)));
617
                
618
                Buffer alphaBand = null;
619
                if(currentQuery.getAlphaBandNumber() != -1) {
620
                        int[] drawableBands = bandList.getDrawableBands();
621
                        bandList.setDrawableBands(new int[]{currentQuery.getAlphaBandNumber(), -1, -1});
622
                        for(int i = 0; i < getDataStoreCount(); i++)
623
                                ((AbstractRasterDataParameters)((DefaultRasterProvider)providers.get(i)).getDataParameters()).setAlphaBand(currentQuery.getAlphaBandNumber());
624
                        alphaBand = getWindowRaster(ulx, uly, lrx, lry, bufWidth, bufHeight, true);
625
                        bandList.setDrawableBands(drawableBands);
626
                }
627
                
628
                listener.nextBuffer(buf, alphaBand, new ExtentImpl(ulx, uly, lrx, lry), this.getAffineTransform(), step, false);
629
                listener.endReading();
630
        }
631

    
632
        /*
633
         * (non-Javadoc)
634
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(double, double, double, double, int, int, boolean)
635
         */
636
        public Buffer getWindowRaster(double ulx, double uly, double lrx, double lry, int bufWidth, int bufHeight, boolean adjustToExtent)
637
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
638

    
639
                Point2D p1 = worldToRaster(new Point2D.Double(ulx, uly));
640
                Point2D p2 = worldToRaster(new Point2D.Double(lrx, lry));
641
                
642
                if(p1.getX() > p2.getX())
643
                        p1.setLocation(p1.getX() - 1, p1.getY());
644
                else
645
                        p2.setLocation(p2.getX() - 1, p2.getY());
646
                
647
                if(p1.getY() > p2.getY())
648
                        p1.setLocation(p1.getX(), p1.getY() - 1);
649
                else
650
                        p2.setLocation(p2.getX(), p2.getY() - 1);
651
                
652
                if(        ((int)p1.getX()) < 0 || ((int)p2.getX()) > getWidth() ||
653
                                ((int)p2.getY()) > getHeight() || ((int)p2.getY()) < 0)
654
                                throw new InvalidSetViewException("");
655

    
656
                int mallocNBands = 0;
657
                if(bandList.getDrawableBands() != null)
658
                        mallocNBands = bandList.getDrawableBands().length;
659
                else
660
                        mallocNBands = bandList.getDrawableBandsCount();
661

    
662
                //Buffer ReadOnly
663

    
664
                if(isReadOnly()) {
665
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], bufWidth, bufHeight, getBandCount());
666
                        if(rb instanceof RasterReadOnlyBuffer) {
667
                                try {
668
                                        ((RasterReadOnlyBuffer)rb).setBufferParams(this, (int)p1.getX(), (int)p1.getY(), (int)p2.getX(), (int)p2.getY(), bandList);
669
                                } catch (FileNotExistsException e) {
670
                                        //Esto no debe darse ya que se comprueba al hacer el open.
671
                                        return null;
672
                                } catch (NotSupportedExtensionException e) {
673
                                        //Esto no debe darse ya que se comprueba al hacer el open
674
                                        return null;
675
                                }
676
                                return rb;
677
                        }
678
                }
679

    
680
                //Buffer RW
681

    
682
                Buffer raster = null;
683
                if(forceToMemory) //Fuerza siempre buffer en memoria
684
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], bufWidth, bufHeight, mallocNBands, false);
685
                else
686
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, mallocNBands, false);
687

    
688
                for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
689
                        raster.assignBandToNotValid(iBand);
690

    
691
                //Si no vamos a ajustar el extent al raster inicializamos el buffer a noData ya que este puede ser
692
                //m?s grande y salirse de los l?mites.
693
                if(!adjustToExtent)
694
                         initBufferToNoData(raster, bandList);
695

    
696
                //Reservamos memoria para los buffers por dataset
697
                Buffer[] bufferDatasets = mallocBuffersDatasets(bandList, bufWidth, bufHeight);
698
                for(int i = 0; i < getDataStoreCount(); i++)
699
                        bufferDatasets[i] = ((DefaultRasterProvider)providers.get(i)).getWindowRaster(ulx, uly, lrx, lry, bufWidth, bufHeight, bandList, bufferDatasets[i], adjustToExtent);
700

    
701
                //Mezclamos los buffers de cada dataset en un solo buffer
702
                mergeBuffers(raster, bufferDatasets, bandList);
703

    
704
                for (int i = 0; i < bufferDatasets.length; i++)
705
                        bufferDatasets[i].free();
706

    
707
                return raster;
708
        }
709

    
710
        /*
711
         * (non-Javadoc)
712
         * @see org.gvsig.raster.impl.store.QueryableRaster#getWindowRaster(int, int, int, int)
713
         */
714
        public Buffer getWindowRaster(int x, int y, int w, int h)
715
                throws InvalidSetViewException, ProcessInterruptedException, RasterDriverException {
716
                if(x < 0 || y < 0 || w > providers.get(0).getWidth() || h > providers.get(0).getHeight())
717
                        throw new InvalidSetViewException("Out of image");
718

    
719
                //Buffer ReadOnly
720

    
721
                if(isReadOnly()) {
722
                        Buffer rb = DefaultRasterManager.getInstance().createReadOnlyBuffer(getDataType()[0], w, h, getBandCount());
723
                        if(rb instanceof RasterReadOnlyBuffer) {
724
                                try {
725
                                        ((RasterReadOnlyBuffer)rb).setBufferParams(this, x, y, x + w, y + h, bandList);
726
                                } catch (FileNotExistsException e) {
727
                                        //Esto no debe darse ya que se comprueba al hacer el open.
728
                                        return null;
729
                                } catch (NotSupportedExtensionException e) {
730
                                        //Esto no debe darse ya que se comprueba al hacer el open
731
                                        return null;
732
                                }
733
                                return rb;
734
                        }
735
                }
736

    
737
                //Buffer RW
738

    
739
                Buffer raster = null;
740
                if(forceToMemory) //Fuerza siempre buffer en memoria
741
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], w, h, bandList.getDrawableBandsCount(), false);
742
                else
743
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], w, h, bandList.getDrawableBandsCount(), false);
744

    
745
                for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
746
                        raster.assignBandToNotValid(iBand);
747

    
748
                //Reservamos memoria para los buffers por dataset
749
                Buffer[] bufferDatasets = mallocBuffersDatasets(bandList, w, h);
750
                for(int i = 0; i < getDataStoreCount(); i++)
751
                        bufferDatasets[i] = ((DefaultRasterProvider)providers.get(i)).getWindowRaster(x, y, w, h, bandList, bufferDatasets[i]);
752

    
753
                //Mezclamos los buffers de cada dataset en un solo buffer
754
                mergeBuffers(raster, bufferDatasets, bandList);
755

    
756
                for (int i = 0; i < bufferDatasets.length; i++)
757
                        bufferDatasets[i].free();
758

    
759
                return raster;
760
        }
761

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

    
771
                //Buffer ReadOnly
772

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

    
789
                Buffer raster = null;
790
                if(forceToMemory) //Fuerza siempre buffer en memoria
791
                        raster = DefaultRasterManager.getInstance().createMemoryBuffer(getDataType()[0], bufWidth, bufHeight, bandList.getDrawableBandsCount(), false);
792
                else
793
                        raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, bandList.getDrawableBandsCount(), false);
794

    
795
                for(int iBand = 0; iBand < raster.getBandCount(); iBand ++)
796
                        raster.assignBandToNotValid(iBand);
797

    
798
                //Reservamos memoria para los buffers por dataset
799
                Buffer[] bufferDatasets = mallocBuffersDatasets(bandList, bufWidth, bufHeight);
800

    
801
                for(int i = 0; i < getDataStoreCount(); i++)
802
                        bufferDatasets[i] = ((DefaultRasterProvider)providers.get(i)).getWindowRaster(x, y, w, h, bufWidth, bufHeight, bandList, bufferDatasets[i]);
803

    
804
                //Mezclamos los buffers de cada dataset en un solo buffer
805
                mergeBuffers(raster, bufferDatasets, bandList);
806

    
807
                for (int i = 0; i < bufferDatasets.length; i++)
808
                        bufferDatasets[i].free();
809

    
810
                return raster;
811
        }
812

    
813
        //******************************
814
        //Setters and Getters
815
        //******************************
816

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

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

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

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

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

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

    
884
                if (dt.length == 0)
885
                        return null;
886

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

    
896
                return dt;
897
        }
898

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

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

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

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

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

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

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

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

    
1035
                return providers.get(0).getNoDataValue();
1036
        }
1037

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

    
1046
                return providers.get(0).isNoDataEnabled();
1047
        }
1048

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

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

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

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

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

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

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

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

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

    
1147
        /*
1148
         * (non-Javadoc)
1149
         * @see org.gvsig.raster.impl.store.QueryableRaster#getColorTable(java.lang.String)
1150
         */
1151
        public ColorTable getColorTable(String fileName){
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.MultiRasterStore#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.props.Histogramable#getPercent()
1234
         */
1235
        public int getPercent() {
1236
                if (histogram != null)
1237
                        return histogram.getPercent();
1238
                return 0;
1239
        }
1240

    
1241
        /*
1242
         * (non-Javadoc)
1243
         * @see org.gvsig.fmap.dal.coverage.store.props.Histogramable#resetPercent()
1244
         */
1245
        public void resetPercent() {
1246
                if (histogram != null) histogram.resetPercent();
1247
        }
1248

    
1249
        /*
1250
         * (non-Javadoc)
1251
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isInside(java.awt.geom.Point2D)
1252
         */
1253
        public boolean isInside(Point2D p) {
1254
                if(getProvider(0) != null)
1255
                        return getProvider(0).isInside(p);
1256
                return false;
1257
        }
1258
        
1259
        /*
1260
         * (non-Javadoc)
1261
         * @see org.gvsig.raster.impl.store.QueryableRaster#getDataStore()
1262
         */
1263
        public RasterDataStore getDataStore() {
1264
                return this;
1265
        }
1266

    
1267
        /**
1268
         * 
1269
         * @param band
1270
         * @return
1271
         */
1272
        public AffineTransform getAffineTransform(int band){
1273
                if(band < 0 || band > (getBandCount() - 1))
1274
                        return null;
1275
                int[] providerBand = getProviderFromBandNumber(band);
1276
                if(providerBand != null)
1277
                        return providers.get(providerBand[0]).getAffineTransform();
1278
                return null;
1279
        }
1280

    
1281
        /**
1282
         * Obtiene el n?mero de dataset para un n?mero de banda y la posici?n de la banda dentro de
1283
         * ese dataset.
1284
         * @param bandNumber N?mero de banda
1285
         * @return Dataset que corresponde a la banda pedida y n?mero de banda dentro del dataset (dataset, banda)
1286
         */
1287
        public int[] getProviderFromBandNumber(int bandNumber) {
1288
                int cont = 0;
1289
                for (int i = 0; i < getDataStoreCount(); i++) {
1290
                        RasterProvider provider = providers.get(i);
1291
                        cont += provider.getBandCount();
1292
                        if(cont > bandNumber) {
1293
                                int lastBands = (cont - provider.getBandCount()); //Suma de las bandas de todos los datasets anteriores.
1294
                                return new int[]{i, (bandNumber - lastBands)};
1295
                        }
1296
                }
1297
                return null;
1298
        }
1299

    
1300
        /*
1301
         * (non-Javadoc)
1302
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#setAffineTransform(java.awt.geom.AffineTransform)
1303
         */
1304
        public void setAffineTransform(AffineTransform transf){
1305
                for (int i = 0; i < getDataStoreCount(); i++)
1306
                        this.getProvider(i).setAffineTransform(transf);
1307
        }
1308

    
1309
        /**
1310
         * Obtiene la matriz de transformaci?n del propio raster. Esta matriz es la encargada
1311
         * de convertir las coordenadas de la petici?n en coordenadas a las que se pide a la libreria.
1312
         * En gdal, por ejemplo, se piden las coordenadas a la libreria en coordenadas pixel por lo que
1313
         * esta matriz tendr? la georreferenciaci?n asociada en el worldfile o cabecera. Otras librerias como
1314
         * ermapper la petici?n a la libreria se hace en coordenadas geograficas que son las mismas en las
1315
         * que pide el usuario de gvSIG por lo que esta matriz en este caso se inicializa con la identidad.
1316
         * @return
1317
         */
1318
        public AffineTransform getOwnTransformation() {
1319
                if(providers != null && providers.size() > 0)
1320
                        return providers.get(0).getOwnAffineTransform();
1321
                return new AffineTransform();
1322
        }
1323

    
1324
        /*
1325
         * (non-Javadoc)
1326
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isRotated()
1327
         */
1328
        public boolean isRotated() {
1329
                if(providers != null && providers.size() > 0)
1330
                        return providers.get(0).isRotated();
1331
                return false;
1332
        }
1333

    
1334
        /*
1335
         * (non-Javadoc)
1336
         * @see org.gvsig.raster.impl.store.QueryableRaster#setDrawableBands(int[])
1337
         */
1338
        public void setDrawableBands(int[] db) {
1339
                getBands().setDrawableBands(db);
1340
        }
1341
        
1342
        /*
1343
         * (non-Javadoc)
1344
         * @see org.gvsig.raster.impl.store.QueryableRaster#getDrawableBands()
1345
         */
1346
        public int[] getDrawableBands() {
1347
                return getBands().getDrawableBands();
1348
        }
1349

    
1350
        /*
1351
         * (non-Javadoc)
1352
         * @see org.gvsig.raster.impl.store.QueryableRaster#clearDrawableBands()
1353
         */
1354
        public void clearDrawableBands() {
1355
                getBands().clearDrawableBands();
1356
        }
1357

    
1358
        /*
1359
         * (non-Javadoc)
1360
         * @see org.gvsig.raster.impl.store.QueryableRaster#addDrawableBand(int, int)
1361
         */
1362
        public void addDrawableBand(int posRasterBuf, int imageBand) {
1363
                getBands().addDrawableBand(posRasterBuf, imageBand);
1364
        }
1365

    
1366
        /**
1367
         * 
1368
         * @return
1369
         */
1370
        public boolean isReadOnly() {
1371
                return readOnly;
1372
        }
1373

    
1374
        /**
1375
         * 
1376
         * @param readOnly
1377
         */
1378
        public void setReadOnly(boolean readOnly) {
1379
                this.readOnly = readOnly;
1380
                if(readOnly)
1381
                        this.forceToMemory = false;
1382
        }
1383

    
1384
        /*
1385
         * (non-Javadoc)
1386
         * @see org.gvsig.raster.impl.store.QueryableRaster#setMemoryBuffer(boolean)
1387
         */
1388
        public void setMemoryBuffer(boolean memory) {
1389
                this.forceToMemory = memory;
1390
                if(memory)
1391
                        this.readOnly = false;
1392
        }
1393

    
1394
        /**
1395
         * 
1396
         * @return
1397
         */
1398
        public boolean isMemoryBuffer() {
1399
                return forceToMemory;
1400
        }
1401
        
1402
        /*
1403
         * (non-Javadoc)
1404
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewWidth(int, int)
1405
         */
1406
        public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
1407
                int[] providerBand = getProviderFromBandNumber(band);
1408
                RasterProvider prov = getProvider(providerBand[0]);
1409
                return prov.getOverviewWidth(providerBand[1], overview);
1410
        }
1411

    
1412
        /*
1413
         * (non-Javadoc)
1414
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewHeight(int, int)
1415
         */
1416
        public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
1417
                int[] providerBand = getProviderFromBandNumber(band);
1418
                RasterProvider prov = getProvider(providerBand[0]);
1419
                return prov.getOverviewHeight(providerBand[1], overview);
1420
        }
1421

    
1422
        /*
1423
         * (non-Javadoc)
1424
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#getOverviewCount(int)
1425
         */
1426
        public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
1427
                if(band >= getBandCount())
1428
                        throw new BandAccessException("Wrong band");
1429
                String fileName = getBands().getBand(band).getFileName();
1430
                RasterDataStore store = getDataStore(fileName);
1431
                RasterProvider prov = ((DefaultMultiRasterStore)store).getProvider(0);
1432
                return prov.getOverviewCount(0);
1433
        }
1434

    
1435
        /*
1436
         * (non-Javadoc)
1437
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#overviewsSupport()
1438
         */
1439
        public boolean overviewsSupport() {
1440
                if(getProviders().size() > 0)
1441
                        return getProvider(0).overviewsSupport();
1442
                return false;
1443
        }
1444
        
1445
        /*
1446
         * (non-Javadoc)
1447
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#saveGeoreferencingToRmf()
1448
         */
1449
        public void saveGeoreferencingToRmf() throws RmfSerializerException {
1450
                for (int i = 0; i < providers.size(); i++) {
1451
                        providers.get(i).saveObjectToRmf(DefaultRasterProvider.class, providers.get(i));
1452
                }
1453
        }
1454
        
1455
        /*
1456
         * (non-Javadoc)
1457
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#saveSerialInfoToRmf(org.gvsig.fmap.dal.coverage.store.props.SerialInfo)
1458
         */
1459
        public void saveSerialInfoToRmf(SerialInfo serialInfo) throws RmfSerializerException {
1460
                for (int i = 0; i < providers.size(); i++) {
1461
                        providers.get(i).saveObjectToRmf(SerialInfo.class, serialInfo);
1462
                }
1463
        }
1464
        
1465
        /*
1466
         * (non-Javadoc)
1467
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#saveColorTableToRmf(org.gvsig.fmap.dal.coverage.store.props.ColorTable)
1468
         */
1469
        public void saveColorTableToRmf(ColorTable table) throws RmfSerializerException {
1470
                for (int i = 0; i < providers.size(); i++) {
1471
                        providers.get(i).saveObjectToRmf(ColorTable.class, table);
1472
                }
1473
        }
1474
        
1475
        /*
1476
         * (non-Javadoc)
1477
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#loadSerialInfoFromRmf(org.gvsig.fmap.dal.coverage.store.props.SerialInfo)
1478
         */
1479
        public boolean loadSerialInfoFromRmf(SerialInfo serialInfo) {
1480
                for (int i = 0; i < providers.size(); i++) {
1481
                        try {
1482
                                providers.get(i).loadObjectFromRmf(SerialInfo.class, serialInfo);
1483
                                return true;
1484
                        } catch (RmfSerializerException e) {
1485
                                //Prueba hasta que alguno tiene la informaci?n
1486
                        }
1487
                }
1488
                return false;
1489
        }
1490

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

    
1619
        /*
1620
         * (non-Javadoc)
1621
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isReproyectable()
1622
         */
1623
        public boolean isReproyectable() {
1624
                boolean is = true; 
1625
                for (int i = 0; i < providers.size(); i++) {
1626
                        if(!providers.get(i).isReproyectable())
1627
                                is = false;
1628
                }
1629
                return is;
1630
        }
1631
        
1632
        /*
1633
         * (non-Javadoc)
1634
         * @see org.gvsig.metadata.Metadata#getMetadataName()
1635
         */
1636
        public String getMetadataName() {
1637
                if(providers.size() != 0)
1638
                        return providers.get(0).getName();
1639
                return null;
1640
        }
1641
        
1642
        /*
1643
         * (non-Javadoc)
1644
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#cloneDataStore()
1645
         */
1646
        public RasterDataStore cloneDataStore() {
1647
                DefaultMultiRasterStore ds = new DefaultMultiRasterStore();
1648
                
1649
                int[] bands = new int[providers.size()];
1650
                for (int i = 0; i < bands.length; i++) 
1651
                        bands[i] = providers.get(i).getBandCount();
1652
                ds.metadata = new MultiDataStoreMetadata(bands);
1653
                
1654
                for (int i = 0; i < providers.size(); i++) {
1655
                        RasterProvider prov = providers.get(i).cloneProvider();
1656
                        ds.providers.add(prov);
1657
                        ds.metadata.add(providers.get(i).getMetadata());
1658
                }
1659
                ds.bandList = (BandListImpl)bandList.clone();
1660
                ds.stats = new MultiDataStoreStatistics(ds.providers);
1661
                ds.histogram = new MultiDataStoreHistogram(ds);
1662
                return ds;
1663
        }
1664
        
1665
        /*
1666
         * (non-Javadoc)
1667
         * @see org.gvsig.fmap.dal.coverage.store.RasterDataStore#isOpen()
1668
         */
1669
        public boolean isOpen() {
1670
                if(providers == null || providers.size() == 0)
1671
                        return false;
1672
                for (int i = 0; i < providers.size(); i++) {
1673
                        if(!providers.get(i).isOpen())
1674
                                return false;
1675
                }
1676
                return true;
1677
        }
1678

    
1679
        /*
1680
         * (non-Javadoc)
1681
         * @see org.gvsig.raster.impl.store.AbstractRasterDataStore#getProvider()
1682
         */
1683
        public CoverageStoreProvider getProvider() {
1684
                if(providers == null || providers.size() == 0)
1685
                        return providers.get(0);
1686
                return null;
1687
        }
1688
}