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 / provider / DefaultRasterProvider.java @ 1057

History | View | Annotate | Download (45.7 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.provider;
23

    
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.NoninvertibleTransformException;
26
import java.awt.geom.Point2D;
27
import java.io.File;
28
import java.util.ArrayList;
29
import java.util.Collection;
30
import java.util.Date;
31
import java.util.Iterator;
32

    
33
import org.cresques.cts.IProjection;
34
import org.gvsig.compat.net.ICancellable;
35
import org.gvsig.fmap.dal.DALLocator;
36
import org.gvsig.fmap.dal.DataServerExplorer;
37
import org.gvsig.fmap.dal.DataStoreParameters;
38
import org.gvsig.fmap.dal.coverage.RasterLocator;
39
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
40
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
41
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
42
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
43
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
44
import org.gvsig.fmap.dal.coverage.exception.CloneException;
45
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
46
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
47
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
48
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
49
import org.gvsig.fmap.dal.coverage.exception.ParsingException;
50
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
51
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
52
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
53
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
54
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
55
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
56
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
57
import org.gvsig.fmap.dal.coverage.store.parameter.RasterFileStoreParameters;
58
import org.gvsig.fmap.dal.coverage.store.parameter.RemoteStoreParameters;
59
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
60
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
61
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
62
import org.gvsig.fmap.dal.coverage.store.props.Metadata;
63
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
64
import org.gvsig.fmap.dal.coverage.store.props.TimeSeries;
65
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
66
import org.gvsig.fmap.dal.coverage.util.FileUtils;
67
import org.gvsig.fmap.dal.coverage.util.RasterUtils;
68
import org.gvsig.fmap.dal.exception.InitializeException;
69
import org.gvsig.fmap.dal.exception.OpenException;
70
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
71
import org.gvsig.fmap.dal.exception.ReadException;
72
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
73
import org.gvsig.fmap.dal.raster.spi.AbstractCoverageStoreProvider;
74
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
75
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
76
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
77
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
78
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
79
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
80
import org.gvsig.raster.cache.tile.provider.TileListener;
81
import org.gvsig.raster.cache.tile.provider.TileServer;
82
import org.gvsig.raster.impl.buffer.DefaultRasterQuery;
83
import org.gvsig.raster.impl.datastruct.DefaultNoData;
84
import org.gvsig.raster.impl.datastruct.ExtentImpl;
85
import org.gvsig.raster.impl.datastruct.serializer.ColorTableRmfSerializer;
86
import org.gvsig.raster.impl.datastruct.serializer.NoDataRmfSerializer;
87
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
88
import org.gvsig.raster.impl.store.DefaultRasterStore;
89
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
90
import org.gvsig.raster.impl.store.properties.SimpleProviderHistogramComputer;
91
import org.gvsig.raster.impl.store.properties.SimpleProviderStatistics;
92
import org.gvsig.raster.impl.store.rmf.ClassSerializer;
93
import org.gvsig.raster.impl.store.rmf.RmfBlocksManager;
94
import org.gvsig.raster.impl.store.serializer.ColorInterpretationRmfSerializer;
95
import org.gvsig.raster.impl.store.serializer.GeoInfoRmfSerializer;
96
import org.gvsig.raster.impl.store.serializer.ProjectionRmfSerializer;
97
import org.gvsig.raster.impl.store.serializer.StatisticsRmfSerializer;
98
import org.gvsig.raster.util.DefaultProviderServices;
99
import org.gvsig.timesupport.Interval;
100
import org.gvsig.timesupport.Time;
101
import org.gvsig.tools.dynobject.DynObject;
102
import org.gvsig.tools.task.Cancellable;
103
import org.gvsig.tools.task.TaskStatus;
104

    
105
/**
106
 * Base class for all raster providers. 
107
 * @author Nacho Brodin (nachobrodin@gmail.com)
108
 */
109
public abstract class DefaultRasterProvider extends AbstractCoverageStoreProvider implements RasterProvider {
110
        /**
111
         * Flags que representan a las bandas visualizables
112
         */
113
        public static final int                   RED_BAND               = 0x01;
114
        public static final int                   GREEN_BAND             = 0x02;
115
        public static final int                   BLUE_BAND              = 0x04;
116
        public static final int                   ALPHA_BAND             = 0x08;
117
        
118
        protected int                             bandCount              = 1;
119
        private int[]                             dataType               = null;
120
        protected NoData                          noData                 = null;
121
        protected String                          wktProjection          = "";
122

    
123
        protected Statistics                      stats                  = null;
124
        protected HistogramComputer               histogram              = null;
125
        protected DataStoreParameters             param                  = null;
126
        protected DataStoreProviderServices       storeServices          = null;
127
        protected RmfBlocksManager                rmfBlocksManager       = null;
128
        protected ColorTable                      colorTable             = null;
129
        private ColorInterpretation               colorInterpretation    = null;
130
        protected TimeSeries                      serialInfo             = null;
131
        protected Transparency                    transparency           = null;
132
        protected TileServer                      tileServer             = null;
133
        
134
        protected FileUtils                       fileUtil               = RasterLocator.getManager().getFileUtils();
135
        protected RasterUtils                     rasterUtil             = RasterLocator.getManager().getRasterUtils();
136
        
137
        protected IProjection                     proj                   = null;
138
        protected long                            fileSize               = 0;
139
        protected long                            bytesReaded            = 0;
140
        protected long                            lineCnt                = 0;
141
        protected String                          uri;
142
        protected String                          selectedSubdatasetID   = null;
143
        
144
        /**
145
         * Transformaci?n creada a partir de la informaci?n de georreferencia de la
146
         * propia imagen. Esta informaci?n est? en la cabecera o en ficheros
147
         * worldfile.
148
         */
149
        protected AffineTransform                 ownTransformation      = null;
150
        /**
151
         * Transformaci?n asignada de forma externa, bien desde el fichero rmf o
152
         * asignada directamente por el usuario.
153
         */
154
        protected AffineTransform                 externalTransformation = null;
155
        
156
        public DefaultRasterProvider(AbstractRasterDataParameters params,
157
                        DataStoreProviderServices storeServices, DynObject metadata) {
158
                super(params, storeServices, metadata);
159
                if(params.getURI() != null) {
160
                        File f = new File(params.getURI());
161
                        if(f.exists())
162
                                setFileSize(f.length());
163
                }
164
                
165
                if(params.getURI() != null)
166
                        uri = translateFileName(params.getURI());
167
                
168
                ownTransformation = new AffineTransform();
169
                externalTransformation = new AffineTransform();
170
        }
171
        
172
        public DefaultRasterProvider(DataStoreParameters params,
173
                        DataStoreProviderServices storeServices, DynObject metadata) {
174
                super(params, storeServices, metadata);
175
                if(((RasterDataParameters)params).getURI() != null) {
176
                        File f = new File(((RasterDataParameters)params).getURI());
177
                        if(f.exists())
178
                                setFileSize(f.length());
179
                        if(params instanceof RemoteStoreParameters)
180
                                uri = translateFileName(((RasterDataParameters)params).getURI());
181
                }
182
                
183
                ownTransformation = new AffineTransform();
184
                externalTransformation = new AffineTransform();
185
        }
186
        
187
        public DefaultRasterProvider(String params) {
188
                super();
189
        }
190
        
191
        public DefaultRasterProvider() {
192
                super(null, null, null);
193
        }
194
        
195
        public String getFullName() {
196
                return getName();
197
        }
198
        
199
        public String getProviderName() {
200
                return getName();
201
        }
202
        
203
        /*
204
         * (non-Javadoc)
205
         * @see org.gvsig.raster.impl.provider.RasterProvider#getFormatList()
206
         */
207
        public String[] getFormatList() {
208
                return null;
209
        }
210
        
211
        /**
212
         * Acciones de inicilizaci?n comunes a todos los drivers.
213
         * Este m?todo debe ser llamado explicitamente por el constructor de cada driver.
214
         * Estas son acciones de inicializaci?n que se ejecutan despu?s del constructor de cada driver.
215
         * Las acciones que hayan de ser realizadas antes se definen en el constructor de RasterDataset.
216
         */
217
        protected void init() {
218
        }
219
        
220
        /*
221
         * (non-Javadoc)
222
         * @see org.gvsig.raster.impl.provider.RasterProvider#isTiled()
223
         */
224
        public boolean isTiled() {
225
                return false;
226
        }
227
        
228
        /*
229
         * (non-Javadoc)
230
         * @see org.gvsig.raster.impl.provider.RasterProvider#isTimeSupported()
231
         */
232
        public boolean isTimeSupported() {
233
                return false;
234
        }
235
        
236
        /*
237
         * (non-Javadoc)
238
         * @see java.lang.Object#clone()
239
         */
240
        public RasterProvider cloneProvider() throws CloneException {
241
                try {
242
                        DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager();
243
                        DefaultRasterProvider provider = (DefaultRasterProvider)dataManager.createProvider(storeServices, param);
244
                        //DefaultRasterProvider provider = singleDatasetInstance(storeServices, param);
245
                        // Estas van por referencia
246
                        provider.histogram = histogram;
247
                        provider.stats = stats;
248
                        return provider;
249
                } catch (ProviderNotRegisteredException e) {
250
                        e.printStackTrace();
251
                } catch (InitializeException e) {
252
                        e.printStackTrace();
253
                }
254
                return null;
255
        }
256
        
257
        /**
258
         * Factoria para abrir distintos tipos de raster.
259
         * @param fName Nombre del fichero.
260
         *
261
         * @return SingleDataset, o null si hay problemas.
262
         */
263
        /*public static DefaultRasterProvider singleDatasetInstance(DataStoreProviderServices storeServices, DataStoreParameters param) throws RasterDriverException {
264
                DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager();
265
                try {
266
                        return (DefaultRasterProvider)dataManager.createProvider(storeServices, param);
267
                } catch (InitializeException e) {
268
                        throw new RasterDriverException("Error initializing provider", e);
269
                } catch (ProviderNotRegisteredException e) {
270
                        throw new RasterDriverException("Provider not register error", e);
271
                }
272
        }*/
273
        
274
        /**
275
         * Factoria para abrir distintos tipos de raster.
276
         * @param fName Nombre del fichero.
277
         *
278
         * @return SingleDataset, o null si hay problemas.
279
         */
280
        public static DefaultRasterProvider singleDatasetInstance(DataStoreProviderServices storeServices, String param) throws RasterDriverException {
281
                DataManagerProviderServices dataManager = (DataManagerProviderServices)DALLocator.getDataManager();
282
                //We have to locate a provider's name which manages the selected file
283
                //A FilesystemServerExplorer will give a getProviderNames service
284
                
285
                FilesystemServerExplorer serverExplorer = null;
286
                try {
287
                        FilesystemServerExplorerParameters paramsExplorer = (FilesystemServerExplorerParameters)dataManager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
288
                        paramsExplorer.setRoot(File.separator);
289
                        serverExplorer = (FilesystemServerExplorer)dataManager.openServerExplorer(FilesystemServerExplorer.NAME, paramsExplorer);
290
                } catch (ValidateDataParametersException e) {
291
                        throw new RasterDriverException("Error validating parameters", e);
292
                } catch (InitializeException e) {
293
                        throw new RasterDriverException("Error creating a server explorer ", e);
294
                } catch (ProviderNotRegisteredException e) {
295
                        throw new RasterDriverException("Provider not registered", e);
296
                }
297
                
298
                //Gets the list of provider's name to manage the file
299
                File file = new File(param);
300
                ArrayList<String> provName = serverExplorer.getProviderNameList(file);
301
                if(provName.size() > 0) {
302
                        for (int i = 0; i < provName.size(); i++) {
303
                                //Gets the first provider what is not a TileProvider
304
                                if(provName.get(i).compareTo("Tile Store") != 0) {
305
                                        DataStoreParameters newparams;
306
                                        try {
307
                                                newparams = dataManager.createStoreParameters(provName.get(i));
308
                                                ((FilesystemStoreParameters)newparams).setFile(file); 
309
                                                if(storeServices == null)
310
                                                        storeServices = new DefaultRasterStore();
311
                                                return (DefaultRasterProvider)dataManager.createProvider(storeServices, newparams);
312
                                        } catch (InitializeException e) {
313
                                                throw new RasterDriverException("Error creating a server explorer ", e);
314
                                        } catch (ProviderNotRegisteredException e) {
315
                                                throw new RasterDriverException("Provider not registered", e);
316
                                        }
317
                                }
318
                        }
319
                }
320
                return null;
321
        }
322

    
323
        /**
324
         * Carga un fichero raster. Puede usarse para calcular el extent e instanciar
325
         * un objeto de este tipo.
326
         */
327
        abstract public RasterProvider load();
328

    
329
        /**
330
         * Obtiene el ancho de la imagen
331
         * @return Ancho de la imagen
332
         */
333
        abstract public double getWidth();
334

    
335
        /**
336
         * Obtiene el ancho de la imagen
337
         * @return Ancho de la imagen
338
         */
339
        abstract public double getHeight();
340

    
341
        /**
342
         * Asigna un nuevo Extent
343
         * @param e        Extent
344
         */
345
        public abstract void setView(Extent e);
346

    
347
        /**
348
         * Obtiene el extent asignado
349
         * @return        Extent
350
         */
351
        public abstract Extent getView();
352

    
353
        /**
354
         * Obtiene el valor del raster en la coordenada que se le pasa.
355
         * El valor ser? Double, Int, Byte, etc. dependiendo del tipo de
356
         * raster.
357
         * @param x        coordenada X
358
         * @param y coordenada Y
359
         * @return
360
         */
361
        abstract public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException;
362

    
363
        /**
364
         * Gets the set of data selected in the {@link RasterQuery}
365
         * @param q
366
         * @return
367
         * @throws RasterDriverException 
368
         * @throws ProcessInterruptedException 
369
         */
370
        public Buffer getDataSet(RasterQuery query) throws ProcessInterruptedException, RasterDriverException {
371
                DefaultRasterQuery q = (DefaultRasterQuery)query;
372
                if( q.getType() == DefaultRasterQuery.TYPE_ENTIRE || 
373
                        q.getType() == DefaultRasterQuery.TYPE_PX_SIZE || 
374
                        q.getType() == DefaultRasterQuery.TYPE_PX) {
375
                        return getWindow(q.getPixelX(), q.getPixelY(), q.getPixelW(), q.getPixelH(), 
376
                                        q.getBandList(), q.getBuffer(), q.getTaskStatus());
377
                }
378
                
379
                if(q.getType() == DefaultRasterQuery.TYPE_COORDS_SIZE) {
380
                        return getWindow(q.getBBox(), q.getBufWidth(), q.getBufHeight(), 
381
                                        q.getBandList(), q.getBuffer(), q.isAdjustToExtent(), q.getTaskStatus());
382
                }
383
                
384
                if(q.getType() == DefaultRasterQuery.TYPE_COORDS) {
385
                        if(q.getBBox() == null)
386
                                return getWindow(q.getX(), q.getY(), q.getW(), q.getH(), 
387
                                                q.getBandList(), q.getBuffer(), q.isAdjustToExtent(), q.getTaskStatus());
388
                        else
389
                                return getWindow(q.getBBox(), q.getBandList(), q.getBuffer(), q.getTaskStatus());
390
                }
391
                
392
                if(q.getType() == DefaultRasterQuery.TYPE_COORDS_SIZE_TILED) {
393
                        getWindow(q.getBBox(), q.getBufWidth(), q.getBufHeight(), 
394
                                        q.getBandList(), q.getTileListener(), q.getCancel());
395
                }
396
                return null;
397
        }
398
        
399
        /**
400
         * Gets a window of data from the source. The result of this operation could be a list of tiles
401
         * that are sent through the listener.
402
         * @param ex
403
         * @param bufWidth
404
         * @param bufHeight
405
         * @param bandList
406
         * @param listener
407
         * @throws ProcessInterruptedException
408
         * @throws RasterDriverException
409
         */
410
         abstract protected void getWindow(Extent ex, int bufWidth, int bufHeight, 
411
                         BandList bandList, TileListener listener, Cancellable status) throws ProcessInterruptedException, RasterDriverException;
412
        
413
        /**
414
         * Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
415
         * No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
416
         * pixeles de disco.
417
         * @param ulx Posici?n X superior izquierda
418
         * @param uly Posici?n Y superior izquierda
419
         * @param lrx Posici?n X inferior derecha
420
         * @param lry Posici?n Y inferior derecha
421
         * @param rasterBuf        Buffer de datos
422
         * @param bandList
423
         * @return Buffer de datos
424
         */
425
        abstract protected Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf, TaskStatus status) 
426
                throws ProcessInterruptedException, RasterDriverException;
427

    
428
        /**
429
         * Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
430
         * No aplica supersampleo ni subsampleo sino que devuelve una matriz de igual tama?o a los
431
         * pixeles de disco.
432
         * @param x Posici?n X superior izquierda
433
         * @param y Posici?n Y superior izquierda
434
         * @param w Ancho en coordenadas reales
435
         * @param h Alto en coordenadas reales
436
         * @param rasterBuf        Buffer de datos
437
         * @param bandList
438
         * @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
439
         * @return Buffer de datos
440
         */
441
        abstract protected Buffer getWindow(double x, double y, double w, double h, 
442
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException;
443

    
444
        /**
445
         * Obtiene una ventana de datos de la imagen a partir de coordenadas reales.
446
         * Se aplica supersampleo o subsampleo dependiendo del tama?o del buffer especificado.
447
         *
448
         * @param minX Posici?n m?nima X superior izquierda
449
         * @param minY Posici?n m?nima Y superior izquierda
450
         * @param maxX Posici?n m?xima X inferior derecha
451
         * @param maxY Posici?n m?xima Y inferior derecha
452
         * @param bufWidth Ancho del buffer de datos
453
         * @param bufHeight Alto del buffer de datos
454
         * @param rasterBuf        Buffer de datos
455
         * @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
456
         * @param bandList
457
         * @return Buffer de datos
458
         */
459
        abstract protected Buffer getWindow(Extent extent, 
460
                        int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, 
461
                        boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException;
462

    
463
        /**
464
         * Obtiene una ventana de datos de la imagen a partir de coordenadas pixel.
465
         * Se aplica supersampleo o subsampleo dependiendo del tama?o del buffer especificado.
466
         *
467
         * @param x Posici?n X superior izquierda
468
         * @param y Posici?n Y superior izquierda
469
         * @param w Ancho en coordenadas reales
470
         * @param h Alto en coordenadas reales
471
         * @param bufWidth Ancho del buffer de datos
472
         * @param bufHeight Alto del buffer de datos
473
         * @param rasterBuf        Buffer de datos
474
         * @param bandList
475
         * @return Buffer de datos
476
         */
477
        abstract protected Buffer getWindow(int x, int y, int w, int h, 
478
                        BandList bandList, Buffer rasterBuf, TaskStatus status)throws ProcessInterruptedException, RasterDriverException;
479

    
480
        abstract public int getBlockSize();
481
        
482
        /*
483
         * (non-Javadoc)
484
         * @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewHeight(int, int)
485
         */
486
        abstract public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException;
487

    
488
        /**
489
         * Informa de si el dataset soporta overviews o no.
490
         * @return true si soporta overviews y false si no las soporta.
491
         */
492
        abstract public boolean isOverviewsSupported();
493
        
494
        /**
495
         * Returns true if supersampling operation is supported by this provider, i.e if 
496
         * a request greater than 1:1 will have a response.
497
         * @return
498
         */
499
        public boolean isSupersamplingSupported() {
500
                return true;
501
        }
502
        
503
        /**
504
         * Carga metadatos desde el fichero Rmf si estos existen
505
         * @param fName Nombre del fichero
506
         * @throws ParsingException
507
         */
508
        protected void loadFromRmf(RmfBlocksManager manager) throws ParsingException {
509
                if (!manager.checkRmf())
510
                        return;
511

    
512
                if (!new File(manager.getPath()).exists())
513
                        return;
514

    
515
                GeoInfoRmfSerializer geoInfoSerializer = new GeoInfoRmfSerializer(this);
516
                ColorTableRmfSerializer colorTableSerializer = new ColorTableRmfSerializer();
517
                NoDataRmfSerializer noDataSerializer = null;
518
                if(noData == null)
519
                        noData = new DefaultNoData(null, null, manager.getPath(), getBandCount());
520
                noDataSerializer = new NoDataRmfSerializer((DefaultNoData)noData);                        
521
                ColorInterpretationRmfSerializer colorInterpSerializer = new ColorInterpretationRmfSerializer();
522
                ProjectionRmfSerializer projectionRmfSerializer = new ProjectionRmfSerializer();
523
                StatisticsRmfSerializer statsRmfSerializer = new StatisticsRmfSerializer(getStatistics());
524

    
525
                manager.addClient(geoInfoSerializer);
526
                manager.addClient(colorTableSerializer);
527
                manager.addClient(noDataSerializer);
528
                manager.addClient(colorInterpSerializer);
529
                manager.addClient(projectionRmfSerializer);
530
                manager.addClient(statsRmfSerializer);
531

    
532
                manager.read(null);
533

    
534
                manager.removeAllClients();
535

    
536
                if (colorTableSerializer.getResult() != null)
537
                        setColorTable((ColorTable) colorTableSerializer.getResult());
538

    
539
                if (colorInterpSerializer.getResult() != null) {
540
                        DataStoreColorInterpretation ci = (DataStoreColorInterpretation) colorInterpSerializer.getResult();
541
                        setColorInterpretation(ci);
542
                        getTransparency().setTransparencyBand(ci.getBand(DataStoreColorInterpretation.ALPHA_BAND));
543
                }
544

    
545
                if (projectionRmfSerializer.getResult() != null)
546
                        wktProjection = RasterLocator.getManager().getCRSUtils().convertIProjectionToWkt((IProjection) projectionRmfSerializer.getResult());
547
        }
548

    
549
        /**
550
         * Obtiene el n?nero de bandas del fichero
551
         * @return Entero que representa el n?mero de bandas
552
         */
553
        public int getBandCount() {
554
                return bandCount;
555
        }
556

    
557
        /**
558
         * @return Returns the dataType.
559
         */
560
        public int[] getDataType() {
561
                return dataType;
562
        }
563

    
564
        /**
565
         * @param dataType The dataType to set.
566
         */
567
        public void setDataType(int[] dataType) {
568
                this.dataType = dataType;
569
        }
570

    
571
        /*
572
         * (non-Javadoc)
573
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeX()
574
         */
575
        public double getPixelSizeX() {
576
                return externalTransformation.getScaleX();
577
        }
578

    
579
        /*
580
         * (non-Javadoc)
581
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeY()
582
         */
583
        public double getPixelSizeY() {
584
                return externalTransformation.getScaleY();
585
        }
586

    
587
        /*
588
         * (non-Javadoc)
589
         * @see org.gvsig.raster.impl.provider.RasterProvider#getNoDataValue()
590
         */
591
        public NoData getNoDataValue() {
592
                if(noData == null) {
593
                        noData = RasterLocator.getManager().getDataStructFactory().createNoData(null, null, getRMFFile(), getBandCount());
594
                        noData.setDataType(getDataType()[0]);
595
                }
596
                return noData;
597
        }
598
        
599
        /*
600
         * (non-Javadoc)
601
         * @see org.gvsig.raster.impl.provider.RasterProvider#setNoDataValue(org.gvsig.fmap.dal.coverage.datastruct.NoData)
602
         */
603
        public void setNoDataValue(NoData value) {
604
                this.noData = value;
605
        }
606

    
607
        /**
608
         * Dice si el fichero tiene georreferenciaci?n o no.
609
         * @return true si tiene georreferenciaci?n y false si no la tiene
610
         */
611
        public boolean isGeoreferenced() {
612
                return true;
613
        }
614

    
615
        /**
616
         * Dado unas coordenadas reales, un tama?o de buffer y un tama?o de raster.
617
         * Si el buffer es de mayor tama?o que el raster (supersampleo) quiere decir que
618
         * por cada pixel de buffer se repiten varios del raster. Esta funci?n calcula el
619
         * n?mero de pixels de desplazamiento en X e Y que corresponden al primer pixel del
620
         * buffer en la esquina superior izquierda. Esto es necesario porque la coordenada
621
         * solicitada es real y puede no caer sobre un pixel completo. Este calculo es
622
         * util cuando un cliente quiere supersamplear sobre un buffer y que no se lo haga
623
         * el driver autom?ticamente.
624
         * @param dWorldTLX Coordenada real X superior izquierda
625
         * @param dWorldTLY Coordenada real Y superior izquierda
626
         * @param dWorldBRX Coordenada real X inferior derecha
627
         * @param dWorldBRY Coordenada real Y inferior derecha
628
         * @param nWidth Ancho del raster
629
         * @param nHeight Alto del raster
630
         * @param bufWidth Ancho del buffer
631
         * @param bufHeight Alto del buffer
632
         * @return Array de dos elementos con el desplazamiento en X e Y.
633
         */
634
        public double[] calcSteps(double dWorldTLX, double dWorldTLY, double dWorldBRX, double dWorldBRY,
635
                        double nWidth, double nHeight, int bufWidth, int bufHeight) {
636

    
637
                Point2D p1 = new Point2D.Double(dWorldTLX, dWorldTLY);
638
                Point2D p2 = new Point2D.Double(dWorldBRX, dWorldBRY);
639

    
640
                Point2D tl = worldToRaster(new Point2D.Double(p1.getX(), p1.getY()));
641
                Point2D br = worldToRaster(new Point2D.Double(p2.getX(), p2.getY()));
642

    
643
                double wPx = (bufWidth / Math.abs(br.getX() - tl.getX()));
644
                double hPx = (bufHeight / Math.abs(br.getY() - tl.getY()));
645

    
646
                int x = (int)((tl.getX() > br.getX()) ? Math.floor(br.getX()) : Math.floor(tl.getX()));
647
                int y = (int)((tl.getY() > br.getY()) ? Math.floor(br.getY()) : Math.floor(tl.getY()));
648

    
649
                double a = (tl.getX() > br.getX()) ? (Math.abs(br.getX() - x)) : (Math.abs(tl.getX() - x));
650
                double b = (tl.getY() > br.getY()) ? (Math.abs(br.getY() - y)) : (Math.abs(tl.getY() - y));
651

    
652
                                double stpX = (int)((a * bufWidth) / Math.abs(br.getX() - tl.getX()));
653
                double stpY = (int)((b * bufHeight) / Math.abs(br.getY() - tl.getY()));
654

    
655
                return new double[]{stpX, stpY, wPx, hPx};
656
        }
657

    
658
        /**
659
         * Convierte un punto desde coordenadas pixel a coordenadas del mundo.
660
         * @param pt Punto a transformar
661
         * @return punto transformado en coordenadas del mundo
662
         */
663
        public Point2D rasterToWorld(Point2D pt) {
664
                Point2D p = new Point2D.Double();
665
                externalTransformation.transform(pt, p);
666
                return p;
667
        }
668

    
669
        /**
670
         * Convierte un punto desde del mundo a coordenadas pixel.
671
         * @param pt Punto a transformar
672
         * @return punto transformado en coordenadas pixel
673
         */
674
        public Point2D worldToRaster(Point2D pt) {
675
                Point2D p = new Point2D.Double();
676
                try {
677
                        externalTransformation.inverseTransform(pt, p);
678
                } catch (NoninvertibleTransformException e) {
679
                        return pt;
680
                }
681
                return p;
682
        }
683

    
684
        /**
685
         * Calcula el extent en coordenadas del mundo real
686
         * @return Extent
687
         */
688
        public Extent getExtent() {
689
                return new ExtentImpl(        rasterToWorld(new Point2D.Double(0, 0)),
690
                                                        rasterToWorld(new Point2D.Double(getWidth(), getHeight())),
691
                                                        rasterToWorld(new Point2D.Double(getWidth(), 0)),
692
                                                        rasterToWorld(new Point2D.Double(0, getHeight())));
693
        }
694

    
695
        /**
696
         * Calcula el extent en coordenadas del mundo real sin rotaci?n. Solo coordenadas y tama?o de pixel
697
         * @return Extent
698
         */
699
        public Extent getExtentWithoutRot() {
700
                AffineTransform at = new AffineTransform(        externalTransformation.getScaleX(), 0,
701
                                                                                                        0, externalTransformation.getScaleY(),
702
                                                                                                        externalTransformation.getTranslateX(), externalTransformation.getTranslateY());
703
                Point2D p1 = new Point2D.Double(0, 0);
704
                Point2D p2 = new Point2D.Double(getWidth(), getHeight());
705
                at.transform(p1, p1);
706
                at.transform(p2, p2);
707
                return new ExtentImpl(p1, p2);
708
        }
709

    
710
        /**
711
         * ASigna el par?metro de inicializaci?n del driver.
712
         */
713
        public void setParam(DataStoreProviderServices provServices, DataStoreParameters param) {
714
                if(param instanceof RasterDataParameters)
715
                        this.uri = ((RasterDataParameters)param).getURI();
716
                this.param = param;
717
                this.storeServices = provServices;
718
        }
719

    
720
        /*
721
         * (non-Javadoc)
722
         * @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewWidth(int, int)
723
         */
724
        abstract public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException;
725
        
726
        /*
727
         * (non-Javadoc)
728
         * @see org.gvsig.raster.impl.provider.RasterProvider#selectSubdataset()
729
         */
730
        public void selectSubdataset() {}
731
        
732
        /**
733
         * Selects the subdataset. This method will select
734
         * the rmf file. 
735
         */
736
        protected void selectSubdataset(String subdataset) {
737
                selectedSubdatasetID = subdataset;
738
                getRmfBlocksManager().setPath(getRMFFile());
739
        }
740

    
741
        /**
742
         * Obtiene el gestor de ficheros RMF
743
         * @return RmfBloksManager
744
         */
745
        public RmfBlocksManager getRmfBlocksManager() {
746
                String fileRMF = getRMFFile();
747
                if(fileRMF != null) {
748
                        if (rmfBlocksManager == null || fileRMF.compareTo(rmfBlocksManager.getPath()) != 0) {
749
                                rmfBlocksManager = new RmfBlocksManager(fileRMF);
750
                        }
751
                }
752
                return rmfBlocksManager;
753
        }
754
        
755
        /*
756
         * (non-Javadoc)
757
         * @see org.gvsig.raster.impl.provider.RasterProvider#getRMFFile()
758
         */
759
        public String getRMFFile() {
760
                String tail = selectedSubdatasetID == null ? ".rmf" : "-sd" + selectedSubdatasetID + ".rmf";
761
                return fileUtil.getNameWithoutExtension(getURI()) + tail;
762
        }
763

    
764
        /*
765
         * (non-Javadoc)
766
         * @see org.gvsig.raster.impl.provider.RasterProvider#isInside(java.awt.geom.Point2D)
767
         */
768
        public boolean isInside(Point2D p){
769
                //Realizamos los calculos solo si el punto est? dentro del extent de la imagen rotada, as? nos ahorramos los calculos
770
                //cuando el puntero est? fuera
771

    
772
                Point2D pt = new Point2D.Double();
773
                try {
774

    
775
                        getAffineTransform().inverseTransform(p, pt);
776
                        if(        pt.getX() >= 0 && pt.getX() < getWidth() &&
777
                                        pt.getY() >= 0 && pt.getY() < getHeight())
778
                                return true;
779
                } catch (NoninvertibleTransformException e) {
780
                        return false;
781
                }
782

    
783
                return false;
784
        }
785

    
786
        /**
787
         * Consulta de si un raster tiene rotaci?n o no.
788
         * @return true si tiene rotaci?n y false si no la tiene.
789
         */
790
        public boolean isRotated() {
791
                if(externalTransformation.getShearX() != 0 || externalTransformation.getShearY() != 0)
792
                        return true;
793
                return false;
794
        }
795
        
796
        /*
797
         * (non-Javadoc)
798
         * @see org.gvsig.raster.impl.provider.RasterProvider#isMultiFile()
799
         */
800
        public boolean isMultiFile() {
801
                return false;
802
        }
803
        
804
        /*
805
         * (non-Javadoc)
806
         * @see org.gvsig.raster.impl.provider.RasterProvider#isMosaic()
807
         */
808
        public boolean isMosaic() {
809
                return false;
810
        }
811

    
812
        /**
813
         * Devuelve si el Dataset es reproyectable
814
         * @return
815
         */
816
        public boolean isReproyectable() {
817
                return false;
818
        }
819

    
820
        public String getWktProjection() {
821
                return wktProjection;
822
        }
823

    
824
        /*
825
         * (non-Javadoc)
826
         * @see org.gvsig.raster.impl.dataset.RasterProvider#saveObjectToRmf(java.lang.Class, java.lang.Object)
827
         */
828
        @SuppressWarnings("unchecked")
829
        public void saveObjectToRmf(Class class1, Object value) throws RmfSerializerException {
830
                ((DefaultProviderServices)RasterLocator.getManager().getProviderServices()).saveObjectToRmfFile(getRmfBlocksManager(), class1, value);
831
        }
832

    
833
        /**
834
         * Carga un objecto desde un serializador del tipo class1. Usa value para iniciar dicho
835
         * serializador
836
         *
837
         * @param class1
838
         * @param value
839
         * @return
840
         * @throws RmfSerializerException
841
         */
842
        @SuppressWarnings("unchecked")
843
        private static Object loadObjectFromRmfFile(RmfBlocksManager blocksManager, Class class1, Object value) throws RmfSerializerException {
844
                ClassSerializer serializerObject = ((DefaultProviderServices)RasterLocator.getManager().getProviderServices()).getSerializerObject(class1, value);
845

    
846
                if (serializerObject == null)
847
                        throw new RmfSerializerException("No se ha podido encontrar el serializador para el Rmf");
848

    
849
                if (!blocksManager.checkRmf())
850
                        throw new RmfSerializerException("Error al comprobar el fichero Rmf");
851

    
852
                blocksManager.addClient(serializerObject);
853
                try {
854
                        blocksManager.read(null);
855
                } catch (ParsingException e) {
856
                        throw new RmfSerializerException("Error al leer el fichero Rmf", e);
857
                }
858
                blocksManager.removeAllClients();
859

    
860
                return serializerObject.getResult();
861
        }
862

    
863
        /*
864
         * (non-Javadoc)
865
         * @see org.gvsig.raster.impl.dataset.RasterProvider#loadObjectFromRmf(java.lang.Class, java.lang.Object)
866
         */
867
        @SuppressWarnings("unchecked")
868
        public Object loadObjectFromRmf(Class class1, Object value) throws RmfSerializerException {
869
                return loadObjectFromRmfFile(getRmfBlocksManager(), class1, value);
870
        }
871

    
872
        /**
873
         * Carga un objeto del fichero RMF especificado por parametro
874
         * @param file
875
         * @param class1
876
         * @param value
877
         * @return
878
         * @throws RmfSerializerException
879
         */
880
        @SuppressWarnings("unchecked")
881
        public static Object loadObjectFromRmfFile(String file, Class class1, Object value) throws RmfSerializerException {
882
                String fileRMF = RasterLocator.getManager().getFileUtils().getNameWithoutExtension(file) + ".rmf";
883
                RmfBlocksManager blocksManager = new RmfBlocksManager(fileRMF);
884
                return loadObjectFromRmfFile(blocksManager, class1, value);
885
        }
886

    
887
        /**
888
         * Guarda en el RMF el objecto actual en caso de que exista un serializador para el
889
         * @param value
890
         * @throws RmfSerializerException
891
         */
892
        public void saveObjectToRmf(Object value) throws RmfSerializerException {
893
                saveObjectToRmf(value.getClass(), value);
894
        }
895

    
896
        /**
897
         * Carga un objecto desde un serializador usando el tipo del mismo objeto pasado por parametro.
898
         * Usa value para iniciar dicho serializador
899
         * @param value
900
         * @return
901
         * @throws RmfSerializerException
902
         */
903
        public Object loadObjectFromRmf(Object value) throws RmfSerializerException {
904
                return loadObjectFromRmf(value.getClass(), value);
905
        }
906
        
907

    
908
        public double getCellSize() {
909
                try {
910
                        Extent e = getExtent();
911
                        double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / getWidth();
912
                        return dCellsize;
913
                } catch (NullPointerException e) {
914
                        return 1;
915
                }
916
        }
917
        
918
        
919
        public RasterProvider newProvider() {
920
                return null;
921
        }
922
        
923
        /*
924
         * (non-Javadoc)
925
         * @see org.gvsig.raster.impl.dataset.RasterProvider#getColorTable()
926
         */
927
        public ColorTable getColorTable() {
928
                return colorTable;
929
        }
930
        
931
        /*
932
         * (non-Javadoc)
933
         * @see org.gvsig.raster.impl.provider.RasterProvider#setColorTable(org.gvsig.fmap.dal.coverage.store.props.ColorTable)
934
         */
935
        public void setColorTable(ColorTable value) {
936
                colorTable = value;
937
        }
938

    
939
        /*
940
         * (non-Javadoc)
941
         * @see org.gvsig.raster.impl.dataset.RasterProvider#getTransparency()
942
         */
943
        public Transparency getTransparency() {
944
                return transparency;
945
        }
946
        
947
        /*
948
         * (non-Javadoc)
949
         * @see org.gvsig.raster.impl.provider.RasterProvider#getMetadata()
950
         */
951
        public Metadata getMetadata() {
952
                return null;
953
        }
954
        
955
        /*
956
         * (non-Javadoc)
957
         * @see org.gvsig.raster.impl.dataset.RasterProvider#getColorInterpretation()
958
         */
959
        public ColorInterpretation getColorInterpretation() {
960
                return this.colorInterpretation;
961
        }
962

    
963
        /**
964
         * Asigna el objeto que contiene que contiene la interpretaci?n de
965
         * color por banda
966
         * @param DataStoreColorInterpretation
967
         */
968
        public void setColorInterpretation(ColorInterpretation colorInterpretation) {
969
                this.colorInterpretation = colorInterpretation;
970
        }
971
        
972
        /*
973
         * (non-Javadoc)
974
         * @see org.gvsig.raster.impl.dataset.RasterProvider#getStatistics()
975
         */
976
        public Statistics getStatistics() {
977
                if(stats == null) {
978
                        stats = new SimpleProviderStatistics(this);
979
                }
980
                return stats;
981
        }
982
        
983
        /*
984
         * (non-Javadoc)
985
         * @see org.gvsig.raster.impl.provider.RasterProvider#setStatistics(org.gvsig.fmap.dal.coverage.store.props.Statistics)
986
         */
987
        public void setStatistics(Statistics stats) {
988
                this.stats = stats;
989
        }
990
        
991
        /*
992
         * (non-Javadoc)
993
         * @see org.gvsig.fmap.dal.coverage.store.props.Histogramable#getHistogramComputer()
994
         */
995
        public HistogramComputer getHistogramComputer() throws HistogramException, InterruptedException {
996
                if (histogram == null)
997
                        histogram = new SimpleProviderHistogramComputer(this);
998
                return histogram;
999
        }
1000
        
1001
    //****************************************************
1002
        //*********Implementing Disposable methods************
1003
        //****************************************************
1004
    
1005
    /*
1006
     * (non-Javadoc)
1007
     * @see org.gvsig.tools.dispose.impl.AbstractDisposable#doDispose()
1008
     */
1009
    public void doDispose() {
1010
            
1011
    }
1012
    
1013
    //****************************************************
1014
        //*****Implementing DataStoreProvider methods*********
1015
        //****************************************************
1016
    
1017
    /**
1018
     * Gets the specific parameter. All of them inherit from RasterStoreParameters
1019
     */
1020
    //public abstract RasterStoreParameters getRasterParameters();
1021
    
1022
        @Override
1023
        public DataServerExplorer getExplorer() throws ReadException,
1024
                        ValidateDataParametersException {
1025
            /*DataManager manager = DALLocator.getDataManager();
1026
                FilesystemServerExplorerParameters params;
1027
                try {
1028
                        params = (FilesystemServerExplorerParameters) manager
1029
                                        .createServerExplorerParameters(FilesystemServerExplorer.NAME);
1030
                        params.setRoot(((AbstractRasterStoreParameters)this.getDataParameters()).getFile().getParent());
1031
                        return manager.createServerExplorer(params);
1032
                } catch (DataException e) {
1033
                        throw new ReadException(this.getName(), e);
1034
                }*/
1035
            return null;
1036
        }
1037
  
1038
        
1039
        /**
1040
         * Returs the DataParameters
1041
         * @return
1042
         */
1043
        public RasterDataParameters getDataParameters() {
1044
                if(getDataStoreParameters() instanceof RasterDataParameters)
1045
                        return (RasterDataParameters)getDataStoreParameters();
1046
                return null;
1047
        }
1048

    
1049
        /*
1050
         * (non-Javadoc)
1051
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getChilds()
1052
         */
1053
        @SuppressWarnings("unchecked")
1054
        public Iterator getChilds() {
1055
                return null;
1056
        }
1057

    
1058
        /*
1059
         * (non-Javadoc)
1060
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getResource()
1061
         */
1062
        public ResourceProvider getResource() {
1063
                return null;
1064
        }
1065

    
1066
        /*
1067
         * (non-Javadoc)
1068
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getSourceId()
1069
         */
1070
        public Object getSourceId() {
1071
                if( this.getDataParameters() instanceof RasterFileStoreParameters)
1072
                        return ((RasterFileStoreParameters)this.getDataParameters()).getFile();
1073
                else
1074
                        return this.getDataParameters().getURI();
1075
        }
1076

    
1077
        /*
1078
         * (non-Javadoc)
1079
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#open()
1080
         */
1081
        public void open() throws OpenException {
1082
        }
1083
        
1084
        /**
1085
         * Traduce el nombre del fichero por un alias asignado por el propio driver.
1086
         * Cuando es traducido por un alias el driver intentar? abrir el alias y no el
1087
         * fichero. Esto es util porque algunos formatos tienen la extensi?n en el
1088
         * fichero de cabecera pero lo que se abre realmente es el fichero de datos.
1089
         * @param fileName
1090
         * @return
1091
         */
1092
        public String translateFileName(String fileName) {
1093
                return fileName;
1094
        }
1095
        
1096
        /*
1097
         * (non-Javadoc)
1098
         * @see org.gvsig.raster.impl.provider.RasterProvider#getFileSuffix()
1099
         */
1100
        public String getFileSuffix() {
1101
                return getURIOfFirstProvider().substring(getURIOfFirstProvider().lastIndexOf(".") + 1, getURIOfFirstProvider().length());
1102
        }
1103

    
1104
        /*
1105
         * (non-Javadoc)
1106
         * @see org.gvsig.raster.impl.provider.RasterProvider#getURIOfFirstProvider()
1107
         */
1108
        public String getURIOfFirstProvider() {
1109
                return RasterLocator.getManager().getFileUtils().getFormatedRasterFileName(uri);
1110
        }
1111

    
1112
        /*
1113
         * (non-Javadoc)
1114
         * @see org.gvsig.raster.impl.provider.RasterProvider#getURI()
1115
         */
1116
        public String getURI() {
1117
                return uri;
1118
        }
1119
        
1120
        public void setFName(String n) {
1121
                uri = n;
1122
        }
1123

    
1124
        public long getFileSize() {
1125
                return fileSize;
1126
        }
1127

    
1128
        public void setFileSize(long sz) {
1129
                fileSize = sz;
1130
        }
1131

    
1132
        /*
1133
         * (non-Javadoc)
1134
         * @see org.gvsig.raster.impl.provider.RasterProvider#getProjection()
1135
         */
1136
        public IProjection getProjection() {
1137
                return proj;
1138
        }
1139

    
1140
        public void setProjection(IProjection p) {
1141
                proj = p;
1142
        }
1143

    
1144
        protected long getTime() {
1145
                return (new Date()).getTime();
1146
        }
1147

    
1148
        /*
1149
         * (non-Javadoc)
1150
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#setAffineTransform(java.awt.geom.AffineTransform)
1151
         */
1152
        public void setAffineTransform(AffineTransform t) {
1153
                externalTransformation = (AffineTransform) t.clone();
1154
        }
1155

    
1156
        /*
1157
         * (non-Javadoc)
1158
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getAffineTransform()
1159
         */
1160
        public AffineTransform getAffineTransform() {
1161
                return externalTransformation;
1162
        }
1163

    
1164
        /**
1165
         * Elimina la matriz de transformaci?n asociada al raster y que se tiene en
1166
         * cuenta para el setView. Este reseteo tendr? en cuenta que si el raster
1167
         * tiene asociado un rmf esta transformaci?n no ser? eliminada sino que se
1168
         * asignar? la correspondiente al rmf existente.
1169
         * @return devuelve true si tiene fichero rmf asociado y false si no lo tiene.
1170
         */
1171
        public void resetAffineTransform() {
1172
                externalTransformation.setToIdentity();
1173
        }
1174

    
1175
        /*
1176
         * (non-Javadoc)
1177
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getOwnAffineTransform()
1178
         */
1179
        public AffineTransform getOwnAffineTransform() {
1180
                return ownTransformation;
1181
        }
1182
        
1183
        /*
1184
         * (non-Javadoc)
1185
         * @see org.gvsig.raster.impl.provider.RasterProvider#getInfoByPoint(double, double)
1186
         */
1187
        public String getInfoByPoint(double x, double y, ICancellable cancellable) throws RemoteServiceException {
1188
                return null;
1189
        }
1190
        
1191
        /*
1192
         * (non-Javadoc)
1193
         * @see org.gvsig.raster.impl.provider.RasterProvider#setTileServer(java.lang.Class)
1194
         */
1195
        public void setTileServer(Class<?> tileServer) {
1196
                
1197
        }
1198
        
1199
        /*
1200
         * (non-Javadoc)
1201
         * @see org.gvsig.raster.impl.provider.RasterProvider#getTileSize()
1202
         */
1203
        public int[] getTileSize(int level) {
1204
                return new int[]{0, 0};
1205
        }
1206
        
1207
        /*
1208
         * (non-Javadoc)
1209
         * @see org.gvsig.raster.impl.provider.RasterProvider#isRasterEnclosed()
1210
         */
1211
        public boolean isRasterEnclosed() {
1212
                return false;
1213
        }
1214
        
1215
        /*
1216
         * (non-Javadoc)
1217
         * @see org.gvsig.raster.impl.provider.RasterProvider#getSourceType()
1218
         */
1219
        public int getSourceType() {
1220
                if(getURI().startsWith("PG:host"))
1221
                        return RasterDataStore.POSTGIS;
1222
                if(getURI().startsWith("http:") || getURI().startsWith("https:"))
1223
                        return RasterDataStore.REMOTE;
1224
                return RasterDataStore.FILE;
1225
        }
1226
        
1227
        /**
1228
         * Most of providers don't need tiles. It those cases this method
1229
         * won't execute anything. Only providers that use tile cache will need
1230
         * implement this function, for instance TileProvider and MosaicProvider.
1231
         */
1232
        public void deleteLayerFromCache() {
1233
                
1234
        }
1235
        
1236
        /*
1237
         * (non-Javadoc)
1238
         * @see org.gvsig.raster.impl.provider.RasterProvider#getTimeSerials()
1239
         */
1240
        public TimeSeries getTimeSerials() throws RmfSerializerException {
1241
                if(serialInfo == null) {
1242
                        serialInfo =  new DefaultTimeSerials();
1243
                        loadObjectFromRmf(TimeSeries.class, serialInfo);
1244
                        //Seleccionamos la primera serie por defecto. El usuario seleccionar? otra si la necesita
1245
                        serialInfo.selectSerial(0);
1246
                }
1247
                return serialInfo;
1248
        }
1249
        
1250
        /*
1251
         * (non-Javadoc)
1252
         * @see org.gvsig.raster.impl.provider.RasterProvider#setTimeSerials(org.gvsig.fmap.dal.coverage.store.props.TimeSerials)
1253
         */
1254
        public void setTimeSerials(TimeSeries serialInfo) throws RmfSerializerException {
1255
                this.serialInfo = serialInfo;
1256
                saveObjectToRmf(TimeSeries.class, serialInfo);
1257
        }
1258
        
1259
        /*
1260
         * (non-Javadoc)
1261
         * @see org.gvsig.raster.impl.provider.RasterProvider#getFileSizeByProvider()
1262
         */
1263
        public long[] getFileSizeByProvider() {
1264
                return new long[]{getFileSize()};
1265
        }
1266
        
1267
        /*
1268
         * (non-Javadoc)
1269
         * @see org.gvsig.raster.impl.provider.RasterProvider#getFileNameByProvider()
1270
         */
1271
        public String[] getURIByProvider() {
1272
                //For providers with one file
1273
                return new String[]{getURIOfFirstProvider()};
1274
        }
1275
        
1276
        /*
1277
         * (non-Javadoc)
1278
         * @see org.gvsig.raster.impl.provider.RasterProvider#getBandCountByProvider()
1279
         */
1280
        public int[] getBandCountByProvider() {
1281
                return new int[]{getBandCount()};
1282
        }
1283
        
1284
        /*
1285
         * (non-Javadoc)
1286
         * @see org.gvsig.raster.impl.provider.RasterProvider#getInternalProviderCount()
1287
         */
1288
        public int getInternalProviderCount() {
1289
                return 1;
1290
        }
1291
        
1292
        /*
1293
         * (non-Javadoc)
1294
         * @see org.gvsig.raster.impl.provider.RasterProvider#getInternalProvider(int)
1295
         */
1296
        public RasterProvider getInternalProvider(int i) {
1297
                return this;
1298
        }
1299
        
1300
        /*
1301
         * (non-Javadoc)
1302
         * @see org.gvsig.raster.impl.provider.RasterProvider#getURIByBand(int)
1303
         */
1304
        public String getURIByBand(int band) {
1305
                //No matter which band be selected. In providers with one file is always the first URI
1306
                return getURIOfFirstProvider();
1307
        }
1308
        
1309
        /*
1310
         * (non-Javadoc)
1311
         * @see org.gvsig.raster.impl.provider.RasterProvider#getBandPositionByProvider(int)
1312
         */
1313
        public int getBandPositionByProvider(int band) {
1314
                return band;
1315
        }
1316
        
1317
        /*
1318
         * (non-Javadoc)
1319
         * @see org.gvsig.raster.impl.provider.RasterProvider#getSubdatasetCount()
1320
         */
1321
        public int getSubdatasetCount() {
1322
                return 0;
1323
        }
1324
        
1325
        /*
1326
         * (non-Javadoc)
1327
         * @see org.gvsig.raster.impl.provider.RasterProvider#addFile(java.lang.String)
1328
         */
1329
        public void addFile(String file) throws InvalidSourceException {
1330
                //Do nothing
1331
        }
1332
        
1333
        /*
1334
         * (non-Javadoc)
1335
         * @see org.gvsig.raster.impl.provider.RasterProvider#removeFile(java.lang.String)
1336
         */
1337
        public void removeFile(String file) {
1338
                //Do nothing                
1339
        }
1340
        
1341
        /*
1342
         * (non-Javadoc)
1343
         * @see org.gvsig.raster.impl.provider.RasterProvider#needEnhanced()
1344
         */
1345
        public boolean needEnhanced() {
1346
                return false;
1347
        }
1348
        
1349
        /**
1350
         * Gets the {@link Interval} of the store, that means the temporal
1351
         * interval where the store has valid data.
1352
         * In raster this method has sense in a mosaic. Therefore this has to be implemented 
1353
         * by the provider.
1354
         * @return
1355
         *         a time interval or null if there is not time support
1356
         */
1357
        public Interval getInterval() {
1358
                return null;
1359
        }
1360
        
1361
        /**
1362
         * Gets all the possible values of time for which the store has data.  
1363
         * In raster this method has sense in a mosaic. Therefore this has to be implemented 
1364
         * by the provider.
1365
         * @return
1366
         *         a collection of {@link Time} objects.
1367
         */
1368
        @SuppressWarnings("unchecked")
1369
        public Collection getTimes() {
1370
                return null;
1371
        }
1372
        
1373
        /**
1374
         * Gets all the possible values of time for which the store has data
1375
         * and intersects with an interval.
1376
         * In raster this method has sense in a mosaic. Therefore this has to be implemented 
1377
         * by the provider.
1378
         * @param interval
1379
         *         the interval of time
1380
         * @return
1381
         *         a collection of {@link Time} objects.
1382
         */
1383
        @SuppressWarnings("unchecked")
1384
        public Collection getTimes(Interval interval) {
1385
                return null;
1386
        }
1387
        
1388
        public void close() {
1389
                if(transparency != null)
1390
                        transparency.dispose();
1391
                try {
1392
                        finalize();
1393
                } catch (Throwable e) {
1394
                }
1395
        }
1396
        
1397
        /*
1398
         * (non-Javadoc)
1399
         * @see java.lang.Object#finalize()
1400
         */
1401
        protected void finalize() throws Throwable {
1402
                dataType               = null;
1403
                noData                 = null;
1404
                wktProjection          = null;
1405
                stats                  = null;
1406
                histogram              = null;
1407
                param                  = null;
1408
                storeServices          = null;
1409
                rmfBlocksManager       = null;
1410
                colorTable             = null;
1411
                colorInterpretation    = null;
1412
                serialInfo             = null;
1413
                transparency           = null;
1414
                tileServer             = null;
1415
                fileUtil               = null;
1416
                rasterUtil             = null;
1417
                proj                   = null;
1418
                uri                    = null;
1419
                selectedSubdatasetID   = null;
1420
                ownTransformation      = null;
1421
                externalTransformation = null;
1422
        }
1423
}