Statistics
| Revision:

gvsig-raster / org.gvsig.raster.gdal / trunk / org.gvsig.raster.gdal / org.gvsig.raster.gdal.io / src / main / java / org / gvsig / raster / gdal / io / GdalProvider.java @ 1794

History | View | Annotate | Download (24.2 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.gdal.io;
23

    
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.Point2D;
26
import java.awt.geom.Rectangle2D;
27
import java.io.BufferedReader;
28
import java.io.File;
29
import java.io.FileNotFoundException;
30
import java.io.FileReader;
31
import java.io.IOException;
32

    
33
import org.gvsig.fmap.dal.DALFileLocator;
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataStore;
36
import org.gvsig.fmap.dal.coverage.RasterLocator;
37
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
38
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
39
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
40
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
41
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
42
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
43
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
44
import org.gvsig.fmap.dal.coverage.exception.ParsingException;
45
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
46
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
47
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
48
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
49
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
50
import org.gvsig.jgdal.GdalException;
51
import org.gvsig.metadata.MetadataLocator;
52
import org.gvsig.raster.cache.tile.provider.TileListener;
53
import org.gvsig.raster.cache.tile.provider.TileServer;
54
import org.gvsig.raster.impl.datastruct.ExtentImpl;
55
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
56
import org.gvsig.raster.impl.provider.RasterProvider;
57
import org.gvsig.raster.impl.provider.tile.FileTileServer;
58
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
59
import org.gvsig.raster.impl.store.DefaultStoreFactory;
60
import org.gvsig.raster.impl.store.properties.DataStoreMetadata;
61
import org.gvsig.tools.ToolsLocator;
62
import org.gvsig.tools.dynobject.DynObject;
63
import org.gvsig.tools.extensionpoint.ExtensionPoint;
64
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
65
import org.gvsig.tools.task.TaskStatus;
66
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
68
/**
69
 * This class represents the data access for gdal formats.
70
 *
71
 * @author Luis W. Sevilla
72
 * @author Nacho Brodin (nachobrodin@gmail.com)
73
 */
74
public class GdalProvider extends DefaultRasterProvider {
75
        public static String        NAME                     = "Gdal Store";
76
        public static String        DESCRIPTION              = "Gdal Raster file";
77
        public static final String  METADATA_DEFINITION_NAME = "GdalStore";
78
        private static final Logger logger                   = LoggerFactory.getLogger(GdalProvider.class);
79
        
80
        public static final String  FORMAT_GTiff    = "GTiff";
81
        public static final String  FORMAT_VRT      = "VRT";
82
        public static final String  FORMAT_NITF     = "NITF";
83
        public static final String  FORMAT_HFA      = "HFA";
84
        public static final String  FORMAT_ELAS     = "ELAS";
85
        public static final String  FORMAT_MEM      = "MEM";
86
        public static final String  FORMAT_BMP      = "BMP";
87
        public static final String  FORMAT_PCIDSK   = "PCIDSK";
88
        public static final String  FORMAT_ILWIS    = "ILWIS";
89
        public static final String  FORMAT_HDF4     = "HDF4Image";
90
        public static final String  FORMAT_PNM      = "PNM";
91
        public static final String  FORMAT_ENVI     = "ENVI";
92
        public static final String  FORMAT_EHDR     = "EHdr";
93
        public static final String  FORMAT_PAUX     = "PAux";
94
        public static final String  FORMAT_MFF      = "MFF";
95
        public static final String  FORMAT_MFF2     = "MFF2";
96
        public static final String  FORMAT_BT       = "BT";
97
        public static final String  FORMAT_IDA      = "IDA";
98
        public static final String  FORMAT_RMF      = "RMF";
99
        public static final String  FORMAT_RST      = "RST";
100
        public static final String  FORMAT_LEVELLER = "Leveller";
101
        public static final String  FORMAT_TERRAGEN = "Terragen";
102
        public static final String  FORMAT_ERS      = "ERS";
103
        public static final String  FORMAT_INGR     = "INGR";
104
        public static final String  FORMAT_GSAG     = "GSAG";
105
        public static final String  FORMAT_GSBG     = "GSBG";
106
        public static final String  FORMAT_ADRG     = "ADRG";
107
        public static final int     BAND_HEIGHT     = 64;
108
        protected GdalNative        file            = null;
109
        private Extent              viewRequest     = null;
110
        protected static String[]   formatList      = null;
111
        
112
        public static void register() {
113
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
114
                registerFormats();
115
                
116
                ExtensionPoint point = extensionPoints.get("DefaultRasterProvider");
117
                point.append("reader", GdalProvider.NAME, GdalProvider.class);
118
                
119
                RasterLocator.getManager().registerFileProvidersTiled(GdalProvider.class);
120
                
121
                DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
122
                if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
123
                        dataman.registerStoreProvider(NAME,
124
                                        GdalProvider.class, GdalDataParameters.class);
125
                }
126
                
127
                if(DALFileLocator.getFilesystemServerExplorerManager() != null)
128
                        DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
129
                                        NAME, DESCRIPTION,
130
                                        GdalFilesystemServerExplorer.class);
131
                
132
                dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
133
        }
134
        
135
        private static void registerFormats() {
136
                formatList      = new String[] {
137
                                "bmp", 
138
                                "gif",
139
                                "tif",
140
                                "tiff",
141
                                "jpg",
142
                                "jpeg",
143
                                "png",
144
                                "vrt",
145
                                "dat", // Envi
146
                                "lan", // Erdas
147
                                "gis", // Erdas
148
                                "img", // Erdas
149
                                "pix", // PCI Geomatics
150
                                "aux", // PCI Geomatics
151
                                "adf", // ESRI Grids
152
                                "mpr", // Ilwis
153
                                "mpl", // Ilwis
154
                                "map", // PC Raster
155
                                "asc",
156
                                "pgm", //Ficheros PNM en escala de grises
157
                                "ppm", //Ficheros PNM en RGB
158
                                "rst", //IDRISIS
159
                                "rmf", //Raster Matrix Format
160
                                "nos",
161
                                "kap",
162
                                "hdr",
163
                                "raw",
164
                                "ers",
165
                                "xml"};
166
                for (int i = 0; i < formatList.length; i++) 
167
                        RasterLocator.getManager().addFormat(formatList[i], GdalProvider.class);
168
        }
169
        
170
        /*
171
         * (non-Javadoc)
172
         * @see org.gvsig.raster.impl.provider.RasterProvider#getFormatList()
173
         */
174
        public String[] getFormatList() {
175
                return formatList;
176
        }
177
        
178
        /**
179
         * Returns true if the extension is supported and false if doesn't
180
         * @param ext
181
         * @return
182
         */
183
        public boolean isExtensionSupported(String ext) {
184
                if(ext.indexOf(".") != -1)
185
                        ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length());
186
                for (int i = 0; i < formatList.length; i++) {
187
                        if(formatList[i].compareTo(ext) == 0)
188
                                return true;
189
                }
190
                return false;
191
        }
192
        
193
        /**
194
         * Mandatory constructor to instantiate an empty provider
195
         */
196
        public GdalProvider() {
197
        }
198
        
199
        /**
200
         * Constructor. Abre el dataset.
201
         * @param proj Proyecci?n
202
         * @param fName Nombre del fichero
203
         * @throws NotSupportedExtensionException
204
         */
205
        public GdalProvider(String params) throws NotSupportedExtensionException {
206
                super(params);
207
                if(params instanceof String) {
208
                        GdalDataParameters p = new GdalDataParameters();
209
                        p.setURI((String)params);
210
                        super.init(p, null, ToolsLocator.getDynObjectManager()
211
                                        .createDynObject(
212
                                                        MetadataLocator.getMetadataManager().getDefinition(
213
                                                                        DataStore.METADATA_DEFINITION_NAME)));
214
                        init(p, null);
215
                }
216
        }
217
        
218
        public GdalProvider (GdalDataParameters params,
219
                        DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
220
                super(params, storeServices, ToolsLocator.getDynObjectManager()
221
                                .createDynObject(
222
                                                MetadataLocator.getMetadataManager().getDefinition(
223
                                                                DataStore.METADATA_DEFINITION_NAME)));
224
                init(params, storeServices);
225
        }
226
        
227
        public GdalProvider(AbstractRasterDataParameters params,
228
                        DataStoreProviderServices storeServices, DynObject metadata) {
229
                super(params, storeServices, metadata);
230
        }
231
        
232
        /**
233
         * Creates file references and loads structures with the information and metadata
234
         * @param params load parameters
235
         * @throws NotSupportedExtensionException
236
         */
237
        public void init (AbstractRasterDataParameters params,
238
                        DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
239
                try {
240
                        setParam(storeServices, params);
241
                        validRmf(params.getURI());
242
                        file = new GdalNative(translateFileName(params.getURI()));
243
                        setColorInterpretation(file.colorInterpr);
244
                        setColorTable(file.palette);
245
                        noData = file.getNoDataValue();
246
                        wktProjection = file.getProjectionRef();
247
                        if(wktProjection != null && wktProjection != "") {
248
                                try {
249
                                        proj = RasterLocator.getManager().getCRSUtils().convertWktToIProjection(wktProjection);
250
                                } catch (Exception e) {
251
                                        logger.info("Error reading WKT from the raster provider", e);
252
                                }
253
                        }
254
                        //CrsWkt crs = new CrsWkt(wktProjection);
255
                        //IProjection proj = CRSFactory.getCRS("EPSG:23030");
256
                        ownTransformation = file.getOwnTransformation();
257
                        externalTransformation = (AffineTransform)ownTransformation.clone();
258
                        load();
259

    
260
                        if(file != null)
261
                                bandCount = file.getRasterCount();
262
                } catch (GdalException e) {
263
                        throw new NotSupportedExtensionException("Extension not supported", e);
264
                } catch(Exception e) {
265
                        System.out.println("Error en GdalOpen");
266
                        e.printStackTrace();
267
                        file = null;
268
                }
269

    
270
                //Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
271
                int[] dt = new int[file.getDataType().length];
272
                for (int i = 0; i < dt.length; i++)
273
                        dt[i] = GdalNative.getRasterBufTypeFromGdalType(file.getDataType()[i]);
274
                setDataType(dt);
275

    
276
                super.init();
277

    
278
                try {
279
                        loadFromRmf(getRmfBlocksManager());
280
                } catch (ParsingException e) {
281
                        //No lee desde rmf
282
                        logger.debug("Problems reading from the RMF file", e);
283
                }
284
        }
285

    
286
        /**
287
         * Comprueba si el fichero abierto es un RasterMetaFile o una imagen
288
         * raster.
289
         * @throws GdalException
290
         */
291
        private void validRmf(String file) throws GdalException {
292
                if(file.endsWith(".rmf")) {
293
                        File f = new File(file);
294
                        FileReader fr;
295
                        try {
296
                                fr = new FileReader(f);
297
                                BufferedReader br = new BufferedReader(fr);
298
                                char[] buffer = new char[5];
299
                                        br.read(buffer);
300
                                        StringBuffer st = new StringBuffer(new String(buffer));
301
                                        if(st.toString().equals("<?xml"))
302
                                                throw new GdalException("RasterMetaFile");
303
                        } catch (FileNotFoundException e) {
304
                                throw new GdalException("File Not Found");
305
                        } catch (IOException e) {
306
                                throw new GdalException("");
307
                        }
308
                }
309
        }
310
        
311
        /*
312
         * (non-Javadoc)
313
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load()
314
         */
315
        public RasterProvider load() {
316
                return this;
317
        }
318
        
319
        /*
320
         * (non-Javadoc)
321
         * @see org.gvsig.raster.impl.provider.RasterProvider#isOpen()
322
         */
323
        public boolean isOpen() {
324
                if(file != null && file.isOpen())
325
                        return true;
326
                return false;
327
        }
328

    
329
        /*
330
         * (non-Javadoc)
331
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String)
332
         */
333
        public String translateFileName(String fileName) {
334
                if(fileName.endsWith("hdr"))
335
                        return fileName.substring(0, fileName.lastIndexOf("."));
336
                return fileName;
337
        }
338

    
339
        /**
340
         * Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n
341
         * de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v)
342
         * ha de estar en coordenadas del fichero.
343
         */
344
        public void setView(Extent e) {
345
                viewRequest = new ExtentImpl(e);
346
        }
347

    
348
        /*
349
         * (non-Javadoc)
350
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
351
         */
352
        public Extent getView() {
353
                return viewRequest;
354
        }
355

    
356
        /*
357
         * (non-Javadoc)
358
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
359
         */
360
        public double getWidth() {
361
                return file.width;
362
        }
363

    
364
        /*
365
         * (non-Javadoc)
366
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight()
367
         */
368
        public double getHeight() {
369
                return file.height;
370
        }
371

    
372
        /**
373
         * Read a line from the file
374
         * @param line
375
         * @param band
376
         * @return
377
         * @throws InvalidSetViewException
378
         * @throws FileNotOpenException
379
         * @throws RasterDriverException
380
         * @Deprecated This operation is deprecated because is not useful and in the future
381
         * it will not be maintained. The abstract operation has dissapear
382
         */
383
        public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
384
                if(line > this.getHeight() || band > this.getBandCount())
385
                        throw new InvalidSetViewException("Request out of grid");
386

    
387
                try{
388
                        return file.readCompleteLine(line, band);
389
                }catch(GdalException e){
390
                        throw new RasterDriverException("Error reading data from Gdal library");
391
                }
392
        }
393

    
394
        /*
395
         *  (non-Javadoc)
396
         * @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int)
397
         */
398
        public Object readBlock(int pos, int blockHeight, double scale)
399
                throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
400
                if(pos < 0)
401
                        throw new InvalidSetViewException("Request out of grid");
402

    
403
                if((pos + blockHeight) > getHeight())
404
                        blockHeight = Math.abs(((int)getHeight()) - pos);
405
                try{
406
                        return file.readBlock(pos, blockHeight, scale);
407
                }catch(GdalException e){
408
                        throw new RasterDriverException("Error reading data from Gdal library");
409
                }
410
        }
411

    
412
        /*
413
         * (non-Javadoc)
414
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
415
         */
416
        public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
417
                if(file != null){
418
                        if(x < 0 || y < 0 || x >= file.width || y >= file.height)
419
                                throw new InvalidSetViewException("Request out of grid");
420
                        Object[] data = file.getData(x, y);
421
                        return data[band];
422
                }
423
                throw new FileNotOpenException("GdalNative not exist");
424
        }
425
        
426
        /*
427
         * (non-Javadoc)
428
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener)
429
         */
430
        public void getWindow(Extent ex, int bufWidth, int bufHeight, 
431
                        BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
432
                 
433
        }
434

    
435
        /*
436
         * (non-Javadoc)
437
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
438
         */
439
        public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) 
440
                throws ProcessInterruptedException, RasterDriverException {
441
                setView(ex);
442

    
443
                try {
444
                        file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), 
445
                                        rasterBuf.getWidth(), rasterBuf.getHeight(), true, status);
446
                } catch (GdalException e) {
447
                        throw new RasterDriverException("Error reading data", e);
448
                }
449

    
450
                return rasterBuf;
451
        }
452

    
453
        /*
454
         * (non-Javadoc)
455
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
456
         */
457
        public Buffer getWindow(double ulx, double uly, double w, double h, 
458
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
459
                //El incremento o decremento de las X e Y depende de los signos de rotaci?n y escala en la matriz de transformaci?n. Por esto
460
                //tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h
461
                Extent ext = getExtent();
462
                Point2D pInit = rasterToWorld(new Point2D.Double(0, 0));
463
                Point2D pEnd = rasterToWorld(new Point2D.Double(getWidth(), getHeight()));
464
                double wRaster = Math.abs(pEnd.getX() - pInit.getX());
465
                double hRaster = Math.abs(pEnd.getY() - pInit.getY());
466
                double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w);
467
                double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h);
468

    
469
                Extent selectedExtent = new ExtentImpl(ulx, uly, lrx, lry);
470
                setView(selectedExtent);
471

    
472
                try {
473
                        file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), 
474
                                        rasterBuf.getWidth(), rasterBuf.getHeight(), adjustToExtent, status);
475
                } catch (GdalException e) {
476
                        throw new RasterDriverException("Error reading data");
477
                }
478

    
479
                return rasterBuf;
480
        }
481

    
482
        /*
483
         * (non-Javadoc)
484
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
485
         */
486
        public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, 
487
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
488
                //draw method
489
                setView(extent);
490

    
491
                double width = 0;
492
                double height = 0;
493

    
494
                Point2D ul = new Point2D.Double(viewRequest.getULX(), viewRequest.getULY());
495
                Point2D lr = new Point2D.Double(viewRequest.getLRX(), viewRequest.getLRY());
496
                ul = worldToRaster(ul);
497
                lr = worldToRaster(lr);
498
                ul.setLocation(ul.getX() < 0 ? 1 : ul.getX(), ul.getY() < 0 ? 1 : ul.getY());
499
                lr.setLocation(lr.getX() < 0 ? 1 : lr.getX(), lr.getY() < 0 ? 1 : lr.getY());
500
                
501
                ul.setLocation(ul.getX() - 0.5, ul.getY() - 0.5);
502
                lr.setLocation(lr.getX() - 0.5, lr.getY() - 0.5);
503
                
504
                adjustPoints(ul, lr);
505
                
506
                width = Math.abs(((int)lr.getX()) - ((int)ul.getX())) + 1;
507
                height = Math.abs(((int)lr.getY()) - ((int)ul.getY())) + 1;
508

    
509
                try {
510
                        file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), 
511
                                        width, height, bufWidth, bufHeight, adjustToExtent, status);
512
                } catch (GdalException e) {
513
                        throw new RasterDriverException("Error reading data");
514
                }
515

    
516
                return rasterBuf;
517
        }
518
        
519

    
520
        private void adjustPoints(Point2D ul, Point2D lr) {
521
                double a = (ul.getX() - (int)ul.getX());
522
                double b = (ul.getY() - (int)ul.getY());
523
                ul.setLocation(        (a > 0.95 || a < 0.05) ? Math.round(ul.getX()) : ul.getX(), 
524
                                                (b > 0.95 || b < 0.05) ? Math.round(ul.getY()) : ul.getY());
525
                lr.setLocation(        (a > 0.95 || a < 0.05) ? Math.round(lr.getX()) : lr.getX(), 
526
                                                (b > 0.95 || b < 0.05) ? Math.round(lr.getY()) : lr.getY());
527
        }
528

    
529
        /*
530
         * (non-Javadoc)
531
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
532
         */
533
        public Buffer getWindow(int x, int y, int w, int h, 
534
                        BandList bandList, Buffer rasterBuf, TaskStatus status) 
535
                throws ProcessInterruptedException, RasterDriverException {
536
                try {
537
                        setView(
538
                        new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
539
                                                getWidth(),
540
                                                getHeight(),
541
                                                new Rectangle2D.Double(x, y, w, h)))
542
                        );
543
                        file.readWindow(rasterBuf, bandList, x, y, w, h, status);
544
                } catch (GdalException e) {
545
                        throw new RasterDriverException("Error reading data");
546
                }
547
                return rasterBuf;
548
        }
549

    
550
        /*
551
         * (non-Javadoc)
552
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize()
553
         */
554
        public int getBlockSize(){
555
                if(file != null)
556
                        return file.getBlockSize();
557
                else
558
                        return 0;
559
        }
560

    
561
        /*
562
         * (non-Javadoc)
563
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getMetadata()
564
         */
565
        public DataStoreMetadata getMetadata() {
566
                if(file != null)
567
                        return file.metadata;
568
                else
569
                        return null;
570
        }
571

    
572
        /*
573
         * (non-Javadoc)
574
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency()
575
         */
576
        public Transparency getTransparency() {
577
                return file.fileTransparency;
578
        }
579

    
580
        /*
581
         * (non-Javadoc)
582
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isGeoreferenced()
583
         */
584
        public boolean isGeoreferenced() {
585
                if(file != null)
586
                        return file.georeferenced;
587
                else
588
                        return false;
589
        }
590

    
591
        /**
592
         * Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
593
         * el valor de esta variable cada vez que dibuja.
594
         * @return true si se ha supersampleado y false si no se ha hecho.
595
         */
596
        public boolean isSupersampling() {
597
                if(file != null)
598
                        return file.isSupersampling;
599
                else
600
                        return false;
601
        }
602

    
603
        public GdalNative getNative(){
604
                return file;
605
        }
606

    
607
        /*
608
         * (non-Javadoc)
609
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform)
610
         */
611
        public void setAffineTransform(AffineTransform t){
612
                super.setAffineTransform(t);
613
                file.setExternalTransform(t);
614
        }
615

    
616
        /*
617
         * (non-Javadoc)
618
         * @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewCount(int)
619
         */
620
        public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
621
                if(band >= getBandCount())
622
                        throw new BandAccessException("Wrong band");
623
                try {
624
                        return file.getRasterBand(band + 1).getOverviewCount();
625
                } catch (GdalException e) {
626
                        throw new RasterDriverException("");
627
                }
628
        }
629

    
630
        /*
631
         * (non-Javadoc)
632
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewWidth(int, int)
633
         */
634
        public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
635
                if (band >= getBandCount())
636
                        throw new BandAccessException("Wrong band");
637
                try {
638
                        if (overview >= file.getRasterBand(band + 1).getOverviewCount())
639
                                throw new BandAccessException("Wrong overview count");
640
                        return file.getRasterBand(band + 1).getOverview(overview).getRasterBandXSize();
641
                } catch (GdalException e) {
642
                        throw new RasterDriverException("");
643
                }
644
        }
645

    
646
        /*
647
         * (non-Javadoc)
648
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewHeight(int, int)
649
         */
650
        public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
651
                if (band >= getBandCount())
652
                        throw new BandAccessException("Wrong band");
653
                try {
654
                        if (overview >= file.getRasterBand(band + 1).getOverviewCount())
655
                                throw new BandAccessException("Wrong overview count");
656
                        return file.getRasterBand(band + 1).getOverview(overview).getRasterBandYSize();
657
                } catch (GdalException e) {
658
                        throw new RasterDriverException("");
659
                }
660
        }
661

    
662
        /*
663
         * (non-Javadoc)
664
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isOverviewsSupported()
665
         */
666
        public boolean isOverviewsSupported() {
667
                return true;
668
        }
669

    
670
        /*
671
         * (non-Javadoc)
672
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isReproyectable()
673
         */
674
        public boolean isReproyectable() {
675
                return true;
676
        }
677
        
678
        /*
679
         * (non-Javadoc)
680
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#needEnhanced()
681
         */
682
        public boolean needEnhanced() {
683
                return (getDataType()[0] != Buffer.TYPE_BYTE || 
684
                                (getBandCount() == 1 && getDataType()[0] == Buffer.TYPE_BYTE));
685
        }
686

    
687
        /*
688
         * (non-Javadoc)
689
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getName()
690
         */
691
        public String getName() {
692
                return NAME;
693
        }
694
        
695
        /*
696
         * (non-Javadoc)
697
         * @see org.gvsig.raster.impl.provider.RasterProvider#setStatus(org.gvsig.raster.impl.provider.RasterProvider)
698
         */
699
        public void setStatus(RasterProvider provider) {
700
                if(provider instanceof GdalProvider) {
701
                        //Not implemented yet
702
                }
703
        }
704
        
705
        /*
706
         * (non-Javadoc)
707
         * @see org.gvsig.raster.impl.provider.RasterProvider#getTileServer()
708
         */
709
        public TileServer getTileServer() {
710
                if(tileServer == null)
711
                        tileServer = new FileTileServer(this);
712
                return tileServer;
713
        }
714
        
715
        /*
716
         * (non-Javadoc)
717
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
718
         */
719
        public void close() {
720
                if(file != null){
721
                        file.dispose();
722
                }
723
                try {
724
                        finalize();
725
                } catch (Throwable e) {
726
                }
727
        }
728
        
729
        /*
730
         * (non-Javadoc)
731
         * @see java.lang.Object#finalize()
732
         */
733
        protected void finalize() throws Throwable {
734
                file           = null;
735
                viewRequest    = null;
736
                if(formatList != null) {
737
                        for (int i = 0; i < formatList.length; i++) {
738
                                formatList[i] = null;
739
                        }
740
                        formatList = null;
741
                }
742
                super.finalize();
743
        }
744
}