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

History | View | Annotate | Download (47 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.Image;
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.NoninvertibleTransformException;
27
import java.awt.geom.Point2D;
28
import java.io.File;
29
import java.util.ArrayList;
30
import java.util.Collection;
31
import java.util.Date;
32
import java.util.Iterator;
33

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
514
                if (!new File(manager.getPath()).exists())
515
                        return;
516
                
517
                GeoInfoRmfSerializer geoInfoSerializer = new GeoInfoRmfSerializer(this);
518
                ColorTableRmfSerializer colorTableSerializer = new ColorTableRmfSerializer();
519
                GeoPointListRmfSerializer gcpSerializer = new GeoPointListRmfSerializer();
520
                NoDataRmfSerializer noDataSerializer = null;
521
                if(noData == null)
522
                        noData = new DefaultNoData(null, null, manager.getPath(), getBandCount());
523
                noDataSerializer = new NoDataRmfSerializer((DefaultNoData)noData);                        
524
                ColorInterpretationRmfSerializer colorInterpSerializer = new ColorInterpretationRmfSerializer();
525
                ProjectionRmfSerializer projectionRmfSerializer = new ProjectionRmfSerializer();
526
                StatisticsRmfSerializer statsRmfSerializer = new StatisticsRmfSerializer(getStatistics());
527

    
528
                manager.addClient(geoInfoSerializer);
529
                manager.addClient(colorTableSerializer);
530
                manager.addClient(gcpSerializer);
531
                manager.addClient(noDataSerializer);
532
                manager.addClient(colorInterpSerializer);
533
                manager.addClient(projectionRmfSerializer);
534
                manager.addClient(statsRmfSerializer);
535

    
536
                manager.read(null);
537

    
538
                manager.removeAllClients();
539

    
540
                if (colorTableSerializer.getResult() != null)
541
                        setColorTable((ColorTable) colorTableSerializer.getResult());
542

    
543
                if (colorInterpSerializer.getResult() != null) {
544
                        DataStoreColorInterpretation ci = (DataStoreColorInterpretation) colorInterpSerializer.getResult();
545
                        setColorInterpretation(ci);
546
                        getTransparency().setTransparencyBand(ci.getBand(DataStoreColorInterpretation.ALPHA_BAND));
547
                }
548

    
549
                if (projectionRmfSerializer.getResult() != null)
550
                        wktProjection = RasterLocator.getManager().getCRSUtils().convertIProjectionToWkt((IProjection) projectionRmfSerializer.getResult());
551
                
552
                if( gcpSerializer.getResult() != null && 
553
                        gcpSerializer.getResult() instanceof GeoPointList && 
554
                        ((GeoPointList)gcpSerializer.getResult()).size() > 0) {
555
                        setGeoPointList((GeoPointList)gcpSerializer.getResult());
556
                }
557
        }
558

    
559
        /**
560
         * Obtiene el n?nero de bandas del fichero
561
         * @return Entero que representa el n?mero de bandas
562
         */
563
        public int getBandCount() {
564
                return bandCount;
565
        }
566

    
567
        /**
568
         * @return Returns the dataType.
569
         */
570
        public int[] getDataType() {
571
                return dataType;
572
        }
573

    
574
        /**
575
         * @param dataType The dataType to set.
576
         */
577
        public void setDataType(int[] dataType) {
578
                this.dataType = dataType;
579
        }
580

    
581
        /*
582
         * (non-Javadoc)
583
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeX()
584
         */
585
        public double getPixelSizeX() {
586
                return externalTransformation.getScaleX();
587
        }
588

    
589
        /*
590
         * (non-Javadoc)
591
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getPixelSizeY()
592
         */
593
        public double getPixelSizeY() {
594
                return externalTransformation.getScaleY();
595
        }
596

    
597
        /*
598
         * (non-Javadoc)
599
         * @see org.gvsig.raster.impl.provider.RasterProvider#getNoDataValue()
600
         */
601
        public NoData getNoDataValue() {
602
                if(noData == null) {
603
                        noData = RasterLocator.getManager().getDataStructFactory().createNoData(null, null, getRMFFile(), getBandCount());
604
                        noData.setDataType(getDataType()[0]);
605
                }
606
                return noData;
607
        }
608
        
609
        /*
610
         * (non-Javadoc)
611
         * @see org.gvsig.raster.impl.provider.RasterProvider#setNoDataValue(org.gvsig.fmap.dal.coverage.datastruct.NoData)
612
         */
613
        public void setNoDataValue(NoData value) {
614
                this.noData = value;
615
        }
616

    
617
        /**
618
         * Dice si el fichero tiene georreferenciaci?n o no.
619
         * @return true si tiene georreferenciaci?n y false si no la tiene
620
         */
621
        public boolean isGeoreferenced() {
622
                return true;
623
        }
624

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

    
647
                Point2D p1 = new Point2D.Double(dWorldTLX, dWorldTLY);
648
                Point2D p2 = new Point2D.Double(dWorldBRX, dWorldBRY);
649

    
650
                Point2D tl = worldToRaster(new Point2D.Double(p1.getX(), p1.getY()));
651
                Point2D br = worldToRaster(new Point2D.Double(p2.getX(), p2.getY()));
652

    
653
                double wPx = (bufWidth / Math.abs(br.getX() - tl.getX()));
654
                double hPx = (bufHeight / Math.abs(br.getY() - tl.getY()));
655

    
656
                int x = (int)((tl.getX() > br.getX()) ? Math.floor(br.getX()) : Math.floor(tl.getX()));
657
                int y = (int)((tl.getY() > br.getY()) ? Math.floor(br.getY()) : Math.floor(tl.getY()));
658

    
659
                double a = (tl.getX() > br.getX()) ? (Math.abs(br.getX() - x)) : (Math.abs(tl.getX() - x));
660
                double b = (tl.getY() > br.getY()) ? (Math.abs(br.getY() - y)) : (Math.abs(tl.getY() - y));
661

    
662
                                double stpX = (int)((a * bufWidth) / Math.abs(br.getX() - tl.getX()));
663
                double stpY = (int)((b * bufHeight) / Math.abs(br.getY() - tl.getY()));
664

    
665
                return new double[]{stpX, stpY, wPx, hPx};
666
        }
667

    
668
        /**
669
         * Convierte un punto desde coordenadas pixel a coordenadas del mundo.
670
         * @param pt Punto a transformar
671
         * @return punto transformado en coordenadas del mundo
672
         */
673
        public Point2D rasterToWorld(Point2D pt) {
674
                Point2D p = new Point2D.Double();
675
                externalTransformation.transform(pt, p);
676
                return p;
677
        }
678

    
679
        /**
680
         * Convierte un punto desde del mundo a coordenadas pixel.
681
         * @param pt Punto a transformar
682
         * @return punto transformado en coordenadas pixel
683
         */
684
        public Point2D worldToRaster(Point2D pt) {
685
                Point2D p = new Point2D.Double();
686
                try {
687
                        externalTransformation.inverseTransform(pt, p);
688
                } catch (NoninvertibleTransformException e) {
689
                        return pt;
690
                }
691
                return p;
692
        }
693

    
694
        /**
695
         * Calcula el extent en coordenadas del mundo real
696
         * @return Extent
697
         */
698
        public Extent getExtent() {
699
                return new ExtentImpl(        rasterToWorld(new Point2D.Double(0, 0)),
700
                                                        rasterToWorld(new Point2D.Double(getWidth(), getHeight())),
701
                                                        rasterToWorld(new Point2D.Double(getWidth(), 0)),
702
                                                        rasterToWorld(new Point2D.Double(0, getHeight())));
703
        }
704

    
705
        /**
706
         * Calcula el extent en coordenadas del mundo real sin rotaci?n. Solo coordenadas y tama?o de pixel
707
         * @return Extent
708
         */
709
        public Extent getExtentWithoutRot() {
710
                AffineTransform at = new AffineTransform(        externalTransformation.getScaleX(), 0,
711
                                                                                                        0, externalTransformation.getScaleY(),
712
                                                                                                        externalTransformation.getTranslateX(), externalTransformation.getTranslateY());
713
                Point2D p1 = new Point2D.Double(0, 0);
714
                Point2D p2 = new Point2D.Double(getWidth(), getHeight());
715
                at.transform(p1, p1);
716
                at.transform(p2, p2);
717
                return new ExtentImpl(p1, p2);
718
        }
719

    
720
        /**
721
         * ASigna el par?metro de inicializaci?n del driver.
722
         */
723
        public void setParam(DataStoreProviderServices provServices, DataStoreParameters param) {
724
                if(param instanceof RasterDataParameters)
725
                        this.uri = ((RasterDataParameters)param).getURI();
726
                this.param = param;
727
                this.storeServices = provServices;
728
        }
729

    
730
        /*
731
         * (non-Javadoc)
732
         * @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewWidth(int, int)
733
         */
734
        abstract public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException;
735
        
736
        /*
737
         * (non-Javadoc)
738
         * @see org.gvsig.raster.impl.provider.RasterProvider#selectSubdataset()
739
         */
740
        public void selectSubdataset() {}
741
        
742
        /**
743
         * Selects the subdataset. This method will select
744
         * the rmf file. 
745
         */
746
        protected void selectSubdataset(String subdataset) {
747
                selectedSubdatasetID = subdataset;
748
                getRmfBlocksManager().setPath(getRMFFile());
749
        }
750

    
751
        /**
752
         * Obtiene el gestor de ficheros RMF
753
         * @return RmfBloksManager
754
         */
755
        public RmfBlocksManager getRmfBlocksManager() {
756
                String fileRMF = getRMFFile();
757
                if(fileRMF != null) {
758
                        if (rmfBlocksManager == null || fileRMF.compareTo(rmfBlocksManager.getPath()) != 0) {
759
                                rmfBlocksManager = new RmfBlocksManager(fileRMF);
760
                        }
761
                }
762
                return rmfBlocksManager;
763
        }
764
        
765
        /*
766
         * (non-Javadoc)
767
         * @see org.gvsig.raster.impl.provider.RasterProvider#getRMFFile()
768
         */
769
        public String getRMFFile() {
770
                String tail = selectedSubdatasetID == null ? ".rmf" : "-sd" + selectedSubdatasetID + ".rmf";
771
                return fileUtil.getNameWithoutExtension(getURI()) + tail;
772
        }
773

    
774
        /*
775
         * (non-Javadoc)
776
         * @see org.gvsig.raster.impl.provider.RasterProvider#isInside(java.awt.geom.Point2D)
777
         */
778
        public boolean isInside(Point2D p){
779
                //Realizamos los calculos solo si el punto est? dentro del extent de la imagen rotada, as? nos ahorramos los calculos
780
                //cuando el puntero est? fuera
781

    
782
                Point2D pt = new Point2D.Double();
783
                try {
784

    
785
                        getAffineTransform().inverseTransform(p, pt);
786
                        if(        pt.getX() >= 0 && pt.getX() < getWidth() &&
787
                                        pt.getY() >= 0 && pt.getY() < getHeight())
788
                                return true;
789
                } catch (NoninvertibleTransformException e) {
790
                        return false;
791
                }
792

    
793
                return false;
794
        }
795

    
796
        /**
797
         * Consulta de si un raster tiene rotaci?n o no.
798
         * @return true si tiene rotaci?n y false si no la tiene.
799
         */
800
        public boolean isRotated() {
801
                if(externalTransformation.getShearX() != 0 || externalTransformation.getShearY() != 0)
802
                        return true;
803
                return false;
804
        }
805
        
806
        /*
807
         * (non-Javadoc)
808
         * @see org.gvsig.raster.impl.provider.RasterProvider#isMultiFile()
809
         */
810
        public boolean isMultiFile() {
811
                return false;
812
        }
813
        
814
        /*
815
         * (non-Javadoc)
816
         * @see org.gvsig.raster.impl.provider.RasterProvider#isMosaic()
817
         */
818
        public boolean isMosaic() {
819
                return false;
820
        }
821

    
822
        /**
823
         * Devuelve si el Dataset es reproyectable
824
         * @return
825
         */
826
        public boolean isReproyectable() {
827
                return true;
828
        }
829

    
830
        public String getWktProjection() {
831
                return wktProjection;
832
        }
833

    
834
        /*
835
         * (non-Javadoc)
836
         * @see org.gvsig.raster.impl.dataset.RasterProvider#saveObjectToRmf(java.lang.Class, java.lang.Object)
837
         */
838
        @SuppressWarnings("unchecked")
839
        public void saveObjectToRmf(Class class1, Object value) throws RmfSerializerException {
840
                ((DefaultProviderServices)RasterLocator.getManager().getProviderServices()).saveObjectToRmfFile(getRmfBlocksManager(), class1, value);
841
        }
842

    
843
        /**
844
         * Carga un objecto desde un serializador del tipo class1. Usa value para iniciar dicho
845
         * serializador
846
         *
847
         * @param class1
848
         * @param value
849
         * @return
850
         * @throws RmfSerializerException
851
         */
852
        @SuppressWarnings("unchecked")
853
        private static Object loadObjectFromRmfFile(RmfBlocksManager blocksManager, Class class1, Object value) throws RmfSerializerException {
854
                ClassSerializer serializerObject = ((DefaultProviderServices)RasterLocator.getManager().getProviderServices()).getSerializerObject(class1, value);
855

    
856
                if (serializerObject == null)
857
                        throw new RmfSerializerException("No se ha podido encontrar el serializador para el Rmf");
858

    
859
                if (!blocksManager.checkRmf())
860
                        throw new RmfSerializerException("Error al comprobar el fichero Rmf");
861

    
862
                blocksManager.addClient(serializerObject);
863
                try {
864
                        blocksManager.read(null);
865
                } catch (ParsingException e) {
866
                        throw new RmfSerializerException("Error al leer el fichero Rmf", e);
867
                }
868
                blocksManager.removeAllClients();
869

    
870
                return serializerObject.getResult();
871
        }
872

    
873
        /*
874
         * (non-Javadoc)
875
         * @see org.gvsig.raster.impl.dataset.RasterProvider#loadObjectFromRmf(java.lang.Class, java.lang.Object)
876
         */
877
        @SuppressWarnings("unchecked")
878
        public Object loadObjectFromRmf(Class class1, Object value) throws RmfSerializerException {
879
                return loadObjectFromRmfFile(getRmfBlocksManager(), class1, value);
880
        }
881

    
882
        /**
883
         * Carga un objeto del fichero RMF especificado por parametro
884
         * @param file
885
         * @param class1
886
         * @param value
887
         * @return
888
         * @throws RmfSerializerException
889
         */
890
        @SuppressWarnings("unchecked")
891
        public static Object loadObjectFromRmfFile(String file, Class class1, Object value) throws RmfSerializerException {
892
                String fileRMF = RasterLocator.getManager().getFileUtils().getNameWithoutExtension(file) + ".rmf";
893
                RmfBlocksManager blocksManager = new RmfBlocksManager(fileRMF);
894
                return loadObjectFromRmfFile(blocksManager, class1, value);
895
        }
896

    
897
        /**
898
         * Guarda en el RMF el objecto actual en caso de que exista un serializador para el
899
         * @param value
900
         * @throws RmfSerializerException
901
         */
902
        public void saveObjectToRmf(Object value) throws RmfSerializerException {
903
                saveObjectToRmf(value.getClass(), value);
904
        }
905

    
906
        /**
907
         * Carga un objecto desde un serializador usando el tipo del mismo objeto pasado por parametro.
908
         * Usa value para iniciar dicho serializador
909
         * @param value
910
         * @return
911
         * @throws RmfSerializerException
912
         */
913
        public Object loadObjectFromRmf(Object value) throws RmfSerializerException {
914
                return loadObjectFromRmf(value.getClass(), value);
915
        }
916
        
917

    
918
        public double getCellSize() {
919
                try {
920
                        Extent e = getExtent();
921
                        double dCellsize = (e.getMax().getX() - e.getMin().getX() ) / getWidth();
922
                        return dCellsize;
923
                } catch (NullPointerException e) {
924
                        return 1;
925
                }
926
        }
927
        
928
        
929
        public RasterProvider newProvider() {
930
                return null;
931
        }
932
        
933
        /*
934
         * (non-Javadoc)
935
         * @see org.gvsig.raster.impl.dataset.RasterProvider#getColorTable()
936
         */
937
        public ColorTable getColorTable() {
938
                return colorTable;
939
        }
940
        
941
        /*
942
         * (non-Javadoc)
943
         * @see org.gvsig.raster.impl.provider.RasterProvider#getImageLegend()
944
         */
945
        public Image getImageLegend() {
946
                return null;
947
        }
948
        
949
        /*
950
         * (non-Javadoc)
951
         * @see org.gvsig.raster.impl.provider.RasterProvider#setColorTable(org.gvsig.fmap.dal.coverage.store.props.ColorTable)
952
         */
953
        public void setColorTable(ColorTable value) {
954
                colorTable = value;
955
        }
956

    
957
        /*
958
         * (non-Javadoc)
959
         * @see org.gvsig.raster.impl.dataset.RasterProvider#getTransparency()
960
         */
961
        public Transparency getTransparency() {
962
                return transparency;
963
        }
964
        
965
        /*
966
         * (non-Javadoc)
967
         * @see org.gvsig.raster.impl.provider.RasterProvider#getMetadata()
968
         */
969
        public Metadata getMetadata() {
970
                return null;
971
        }
972
        
973
        /*
974
         * (non-Javadoc)
975
         * @see org.gvsig.raster.impl.dataset.RasterProvider#getColorInterpretation()
976
         */
977
        public ColorInterpretation getColorInterpretation() {
978
                return this.colorInterpretation;
979
        }
980

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

    
1068
        /*
1069
         * (non-Javadoc)
1070
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getChilds()
1071
         */
1072
        @SuppressWarnings("unchecked")
1073
        public Iterator getChilds() {
1074
                return null;
1075
        }
1076

    
1077
        /*
1078
         * (non-Javadoc)
1079
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getResource()
1080
         */
1081
        public ResourceProvider getResource() {
1082
                return null;
1083
        }
1084

    
1085
        /*
1086
         * (non-Javadoc)
1087
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getSourceId()
1088
         */
1089
        public Object getSourceId() {
1090
                if( this.getDataParameters() instanceof RasterFileStoreParameters)
1091
                        return ((RasterFileStoreParameters)this.getDataParameters()).getFile();
1092
                else
1093
                        return this.getDataParameters().getURI();
1094
        }
1095

    
1096
        /*
1097
         * (non-Javadoc)
1098
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#open()
1099
         */
1100
        public void open() throws OpenException {
1101
        }
1102
        
1103
        /**
1104
         * Traduce el nombre del fichero por un alias asignado por el propio driver.
1105
         * Cuando es traducido por un alias el driver intentar? abrir el alias y no el
1106
         * fichero. Esto es util porque algunos formatos tienen la extensi?n en el
1107
         * fichero de cabecera pero lo que se abre realmente es el fichero de datos.
1108
         * @param fileName
1109
         * @return
1110
         */
1111
        public String translateFileName(String fileName) {
1112
                return fileName;
1113
        }
1114
        
1115
        /*
1116
         * (non-Javadoc)
1117
         * @see org.gvsig.raster.impl.provider.RasterProvider#getFileSuffix()
1118
         */
1119
        public String getFileSuffix() {
1120
                return getURIOfFirstProvider().substring(getURIOfFirstProvider().lastIndexOf(".") + 1, getURIOfFirstProvider().length());
1121
        }
1122

    
1123
        /*
1124
         * (non-Javadoc)
1125
         * @see org.gvsig.raster.impl.provider.RasterProvider#getURIOfFirstProvider()
1126
         */
1127
        public String getURIOfFirstProvider() {
1128
                return RasterLocator.getManager().getFileUtils().getFormatedRasterFileName(uri);
1129
        }
1130

    
1131
        /*
1132
         * (non-Javadoc)
1133
         * @see org.gvsig.raster.impl.provider.RasterProvider#getURI()
1134
         */
1135
        public String getURI() {
1136
                return uri;
1137
        }
1138
        
1139
        public void setFName(String n) {
1140
                uri = n;
1141
        }
1142

    
1143
        /**
1144
         * Gets the size of the file if exists in Bytes
1145
         * @return
1146
         */
1147
        public long getFileSize() {
1148
                return fileSize;
1149
        }
1150

    
1151
        public void setFileSize(long sz) {
1152
                fileSize = sz;
1153
        }
1154

    
1155
        /*
1156
         * (non-Javadoc)
1157
         * @see org.gvsig.raster.impl.provider.RasterProvider#getProjection()
1158
         */
1159
        public IProjection getProjection() {
1160
                return proj;
1161
        }
1162

    
1163
        public void setProjection(IProjection proj) throws RmfSerializerException {
1164
                this.proj = proj;
1165
                saveObjectToRmf(IProjection.class, proj);
1166
        }
1167

    
1168
        protected long getTime() {
1169
                return (new Date()).getTime();
1170
        }
1171

    
1172
        /*
1173
         * (non-Javadoc)
1174
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#setAffineTransform(java.awt.geom.AffineTransform)
1175
         */
1176
        public void setAffineTransform(AffineTransform t) {
1177
                externalTransformation = (AffineTransform) t.clone();
1178
        }
1179

    
1180
        /*
1181
         * (non-Javadoc)
1182
         * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getAffineTransform()
1183
         */
1184
        public AffineTransform getAffineTransform() {
1185
                return externalTransformation;
1186
        }
1187

    
1188
        /**
1189
         * Elimina la matriz de transformaci?n asociada al raster y que se tiene en
1190
         * cuenta para el setView. Este reseteo tendr? en cuenta que si el raster
1191
         * tiene asociado un rmf esta transformaci?n no ser? eliminada sino que se
1192
         * asignar? la correspondiente al rmf existente.
1193
         * @return devuelve true si tiene fichero rmf asociado y false si no lo tiene.
1194
         */
1195
        public void resetAffineTransform() {
1196
                externalTransformation.setToIdentity();
1197
        }
1198

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