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

History | View | Annotate | Download (24 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.parameter.RasterFileStoreParameters;
48
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
49
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
50
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
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.extensionpoint.ExtensionPoint;
63
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
64

    
65
import es.gva.cit.jgdal.GdalException;
66
/**
67
 * Clase que representa al driver de acceso a datos de gdal.
68
 *
69
 * @author Luis W. Sevilla
70
 * @author Nacho Brodin (nachobrodin@gmail.com)
71
 */
72
public class GdalProvider extends DefaultRasterProvider {
73
        public static String        NAME                     = "Gdal Store";
74
        public static String        DESCRIPTION              = "Gdal Raster file";
75
        public static final String  METADATA_DEFINITION_NAME = "GdalStore";
76
        
77
        public static final String  FORMAT_GTiff    = "GTiff";
78
        public static final String  FORMAT_VRT      = "VRT";
79
        public static final String  FORMAT_NITF     = "NITF";
80
        public static final String  FORMAT_HFA      = "HFA";
81
        public static final String  FORMAT_ELAS     = "ELAS";
82
        public static final String  FORMAT_MEM      = "MEM";
83
        public static final String  FORMAT_BMP      = "BMP";
84
        public static final String  FORMAT_PCIDSK   = "PCIDSK";
85
        public static final String  FORMAT_ILWIS    = "ILWIS";
86
        public static final String  FORMAT_HDF4     = "HDF4Image";
87
        public static final String  FORMAT_PNM      = "PNM";
88
        public static final String  FORMAT_ENVI     = "ENVI";
89
        public static final String  FORMAT_EHDR     = "EHdr";
90
        public static final String  FORMAT_PAUX     = "PAux";
91
        public static final String  FORMAT_MFF      = "MFF";
92
        public static final String  FORMAT_MFF2     = "MFF2";
93
        public static final String  FORMAT_BT       = "BT";
94
        public static final String  FORMAT_IDA      = "IDA";
95
        public static final String  FORMAT_RMF      = "RMF";
96
        public static final String  FORMAT_RST      = "RST";
97
        public static final String  FORMAT_LEVELLER = "Leveller";
98
        public static final String  FORMAT_TERRAGEN = "Terragen";
99
        public static final String  FORMAT_ERS      = "ERS";
100
        public static final String  FORMAT_INGR     = "INGR";
101
        public static final String  FORMAT_GSAG     = "GSAG";
102
        public static final String  FORMAT_GSBG     = "GSBG";
103
        public static final String  FORMAT_ADRG     = "ADRG";
104
        public static final int     BAND_HEIGHT     = 64;
105
        protected GdalNative        file            = null;
106
        private Extent              viewRequest     = null;
107
        protected static String[]   formatList      = null;
108

    
109
        public static void register() {
110
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
111
                registerFormats();
112
                
113
                ExtensionPoint point = extensionPoints.get("DefaultDriver");
114
                point.append("reader", GdalProvider.NAME, GdalProvider.class);
115
                
116
                RasterLocator.getManager().registerFileProvidersTiled(GdalProvider.class);
117
                
118
                DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
119
                if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
120
                        dataman.registerStoreProvider(NAME,
121
                                        GdalProvider.class, GdalDataParameters.class);
122
                }
123
                
124
                if(DALFileLocator.getFilesystemServerExplorerManager() != null)
125
                        DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
126
                                        NAME, DESCRIPTION,
127
                                        GdalFilesystemServerExplorer.class);
128
                
129
                dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
130
        }
131
        
132
        private static void registerFormats() {
133
                formatList      = new String[] {
134
                                "bmp", 
135
                                "gif",
136
                                "tif",
137
                                "tiff",
138
                                "jpg",
139
                                "jpeg",
140
                                "png",
141
                                "vrt",
142
                                "dat", // Envi
143
                                "lan", // Erdas
144
                                "gis", // Erdas
145
                                "img", // Erdas
146
                                "pix", // PCI Geomatics
147
                                "aux", // PCI Geomatics
148
                                "adf", // ESRI Grids
149
                                "mpr", // Ilwis
150
                                "mpl", // Ilwis
151
                                "map", // PC Raster
152
                                "asc",
153
                                "pgm", //Ficheros PNM en escala de grises
154
                                "ppm", //Ficheros PNM en RGB
155
                                "rst", //IDRISIS
156
                                "rmf", //Raster Matrix Format
157
                                "nos",
158
                                "kap",
159
                                "hdr",
160
                                "raw",
161
                                "ers"};
162
                for (int i = 0; i < formatList.length; i++) 
163
                        RasterLocator.getManager().addFormat(formatList[i], GdalProvider.class);
164
        }
165
        
166
        /*
167
         * (non-Javadoc)
168
         * @see org.gvsig.raster.impl.provider.RasterProvider#getFormatList()
169
         */
170
        public String[] getFormatList() {
171
                return formatList;
172
        }
173
        
174
        /**
175
         * Returns true if the extension is supported and false if doesn't
176
         * @param ext
177
         * @return
178
         */
179
        public boolean isExtensionSupported(String ext) {
180
                if(ext.indexOf(".") != -1)
181
                        ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length());
182
                for (int i = 0; i < formatList.length; i++) {
183
                        if(formatList[i].compareTo(ext) == 0)
184
                                return true;
185
                }
186
                return false;
187
        }
188
        
189
        /**
190
         * Mandatory constructor to instantiate an empty provider
191
         */
192
        public GdalProvider() {
193
        }
194
        
195
        /**
196
         * Constructor. Abre el dataset.
197
         * @param proj Proyecci?n
198
         * @param fName Nombre del fichero
199
         * @throws NotSupportedExtensionException
200
         */
201
        public GdalProvider(String params) throws NotSupportedExtensionException {
202
                super(params);
203
                if(params instanceof String) {
204
                        GdalDataParameters p = new GdalDataParameters();
205
                        p.setURI((String)params);
206
                        super.init(p, null, ToolsLocator.getDynObjectManager()
207
                                        .createDynObject(
208
                                                        MetadataLocator.getMetadataManager().getDefinition(
209
                                                                        DataStore.METADATA_DEFINITION_NAME)));
210
                        init(p, null);
211
                }
212
        }
213
        
214
        public GdalProvider (GdalDataParameters params,
215
                        DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
216
                super(params, storeServices, ToolsLocator.getDynObjectManager()
217
                                .createDynObject(
218
                                                MetadataLocator.getMetadataManager().getDefinition(
219
                                                                DataStore.METADATA_DEFINITION_NAME)));
220
                init(params, storeServices);
221
        }
222
        
223
        /**
224
         * Crea las referencias al fichero y carga
225
         * las estructuras con la informaci?n y los metadatos.
226
         * @param proj Proyecci?n
227
         * @param param Parametros de carga
228
         * @throws NotSupportedExtensionException
229
         */
230
        public void init (AbstractRasterDataParameters params,
231
                        DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
232
                try {
233
                        if(((RasterFileStoreParameters)params).getFile().exists()) {
234
                                setParam(storeServices, params);
235
                                validRmf(params.getURI());
236
                                file = new GdalNative(translateFileName(params.getURI()));
237
                                setColorInterpretation(file.colorInterpr);
238
                                setColorTable(file.palette);
239
                                noData = file.getNoDataValue();
240
                                wktProjection = file.getProjectionRef();
241
                                //CrsWkt crs = new CrsWkt(wktProjection);
242
                                //IProjection proj = CRSFactory.getCRS("EPSG:23030");
243
                                noDataEnabled = file.existsNoDataValue();
244
                                ownTransformation = file.getOwnTransformation();
245
                                externalTransformation = (AffineTransform)ownTransformation.clone();
246
                                load();
247
                        } else
248
                                setParam(storeServices, params);
249
                                //TODO: FUNCIONALIDAD: Formatos gestionados por gdal que no tienen extensi?n. Estos tendr?n un objeto IRegistrableRasterFormat Por ej: Grass
250
                        bandCount = file.getRasterCount();
251
                } catch (GdalException e) {
252
                        throw new NotSupportedExtensionException("Extension not supported", e);
253
                } catch(Exception e) {
254
                                System.out.println("Error en GdalOpen");
255
                                e.printStackTrace();
256
                                file = null;
257
                }
258

    
259
                //Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
260
                int[] dt = new int[file.getDataType().length];
261
                for (int i = 0; i < dt.length; i++)
262
                        dt[i] = rasterUtil.getRasterBufTypeFromGdalType(file.getDataType()[i]);
263
                setDataType(dt);
264

    
265
                super.init();
266

    
267
                try {
268
                        loadFromRmf(getRmfBlocksManager());
269
                } catch (ParsingException e) {
270
                        //No lee desde rmf
271
                }
272
        }
273

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

    
317
        /*
318
         * (non-Javadoc)
319
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
320
         */
321
        public void close() {
322
                try {
323
                        if(file != null){
324
                                file.close();
325
                                file = null;
326
                        }
327
                        viewRequest = null;
328
                } catch (GdalException e) {
329
                        e.printStackTrace();
330
                }
331
        }
332

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

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

    
352
        /*
353
         * (non-Javadoc)
354
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
355
         */
356
        public Extent getView() {
357
                return viewRequest;
358
        }
359

    
360
        /*
361
         * (non-Javadoc)
362
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
363
         */
364
        public double getWidth() {
365
                return file.width;
366
        }
367

    
368
        /*
369
         * (non-Javadoc)
370
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight()
371
         */
372
        public double getHeight() {
373
                return file.height;
374
        }
375

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

    
391
                try{
392
                        return file.readCompleteLine(line, band);
393
                }catch(GdalException e){
394
                        throw new RasterDriverException("Error reading data from Gdal library");
395
                }
396
        }
397

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

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

    
416
        /*
417
         * (non-Javadoc)
418
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
419
         */
420
        public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
421
                if(file != null){
422
                        if(x < 0 || y < 0 || x >= file.width || y >= file.height)
423
                                throw new InvalidSetViewException("Request out of grid");
424
                        Object[] data = file.getData(x, y);
425
                        return data[band];
426
                }
427
                throw new FileNotOpenException("GdalNative not exist");
428
        }
429
        
430
        /*
431
         * (non-Javadoc)
432
         * @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)
433
         */
434
        public void getWindow(Extent ex, int bufWidth, int bufHeight, 
435
                        BandList bandList, TileListener listener) throws ProcessInterruptedException, RasterDriverException {
436
                 
437
        }
438

    
439
        /*
440
         * (non-Javadoc)
441
         * @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)
442
         */
443
        public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf) 
444
                throws ProcessInterruptedException, RasterDriverException {
445
                setView(ex);
446

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

    
453
                return rasterBuf;
454
        }
455

    
456
        /*
457
         * (non-Javadoc)
458
         * @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)
459
         */
460
        public Buffer getWindow(double ulx, double uly, double w, double h, 
461
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
462
                //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
463
                //tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h
464
                Extent ext = getExtent();
465
                Point2D pInit = rasterToWorld(new Point2D.Double(0, 0));
466
                Point2D pEnd = rasterToWorld(new Point2D.Double(getWidth(), getHeight()));
467
                double wRaster = Math.abs(pEnd.getX() - pInit.getX());
468
                double hRaster = Math.abs(pEnd.getY() - pInit.getY());
469
                double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w);
470
                double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h);
471

    
472
                Extent selectedExtent = new ExtentImpl(ulx, uly, lrx, lry);
473
                setView(selectedExtent);
474

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

    
481
                return rasterBuf;
482
        }
483

    
484
        /*
485
         * (non-Javadoc)
486
         * @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)
487
         */
488
        public Buffer getWindow(Extent extent, 
489
                        int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
490
                //draw method
491
                setView(extent);
492

    
493
                double width = 0;
494
                double height = 0;
495

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

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

    
517
                return rasterBuf;
518
        }
519
        
520

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

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

    
552
        /*
553
         * (non-Javadoc)
554
         * @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)
555
         */
556
        public Buffer getWindow(int x, int y, int w, int h, 
557
                        int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
558
                try {
559
                        setView(
560
                        new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
561
                                                getWidth(),
562
                                                getHeight(),
563
                                                new Rectangle2D.Double(x, y, w, h)))
564
                        );
565
                        file.readWindow(rasterBuf, bandList, x, y, w, h, bufWidth, bufHeight);
566
                } catch (GdalException e) {
567
                        throw new RasterDriverException("Error reading data");
568
                }
569
                return rasterBuf;
570
        }
571

    
572
        /*
573
         * (non-Javadoc)
574
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize()
575
         */
576
        public int getBlockSize(){
577
                if(file != null)
578
                        return file.getBlockSize();
579
                else
580
                        return 0;
581
        }
582

    
583
        /*
584
         * (non-Javadoc)
585
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getMetadata()
586
         */
587
        public DataStoreMetadata getMetadata() {
588
                if(file != null)
589
                        return file.metadata;
590
                else
591
                        return null;
592
        }
593

    
594
        /*
595
         * (non-Javadoc)
596
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency()
597
         */
598
        public Transparency getTransparency() {
599
                return file.fileTransparency;
600
        }
601

    
602
        /*
603
         * (non-Javadoc)
604
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isGeoreferenced()
605
         */
606
        public boolean isGeoreferenced() {
607
                if(file != null)
608
                        return file.georeferenced;
609
                else
610
                        return false;
611
        }
612

    
613
        /**
614
         * Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
615
         * el valor de esta variable cada vez que dibuja.
616
         * @return true si se ha supersampleado y false si no se ha hecho.
617
         */
618
        public boolean isSupersampling() {
619
                if(file != null)
620
                        return file.isSupersampling;
621
                else
622
                        return false;
623
        }
624

    
625
        public GdalNative getNative(){
626
                return file;
627
        }
628

    
629
        /*
630
         * (non-Javadoc)
631
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform)
632
         */
633
        public void setAffineTransform(AffineTransform t){
634
                super.setAffineTransform(t);
635
                file.setExternalTransform(t);
636
        }
637

    
638
        /*
639
         * (non-Javadoc)
640
         * @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewCount(int)
641
         */
642
        public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
643
                if(band >= getBandCount())
644
                        throw new BandAccessException("Wrong band");
645
                try {
646
                        return file.getRasterBand(band + 1).getOverviewCount();
647
                } catch (GdalException e) {
648
                        throw new RasterDriverException("");
649
                }
650
        }
651

    
652
        /*
653
         * (non-Javadoc)
654
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewWidth(int, int)
655
         */
656
        public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
657
                if (band >= getBandCount())
658
                        throw new BandAccessException("Wrong band");
659
                try {
660
                        if (overview >= file.getRasterBand(band + 1).getOverviewCount())
661
                                throw new BandAccessException("Wrong overview count");
662
                        return file.getRasterBand(band + 1).getOverview(overview).getRasterBandXSize();
663
                } catch (GdalException e) {
664
                        throw new RasterDriverException("");
665
                }
666
        }
667

    
668
        /*
669
         * (non-Javadoc)
670
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewHeight(int, int)
671
         */
672
        public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
673
                if (band >= getBandCount())
674
                        throw new BandAccessException("Wrong band");
675
                try {
676
                        if (overview >= file.getRasterBand(band + 1).getOverviewCount())
677
                                throw new BandAccessException("Wrong overview count");
678
                        return file.getRasterBand(band + 1).getOverview(overview).getRasterBandYSize();
679
                } catch (GdalException e) {
680
                        throw new RasterDriverException("");
681
                }
682
        }
683

    
684
        /*
685
         * (non-Javadoc)
686
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isOverviewsSupported()
687
         */
688
        public boolean isOverviewsSupported() {
689
                return true;
690
        }
691

    
692
        /*
693
         * (non-Javadoc)
694
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isReproyectable()
695
         */
696
        public boolean isReproyectable() {
697
                return true;
698
        }
699

    
700
        /*
701
         * (non-Javadoc)
702
         * @see org.gvsig.fmap.dal.spi.DataStoreProvider#getName()
703
         */
704
        public String getName() {
705
                return NAME;
706
        }
707
        
708
        /*
709
         * (non-Javadoc)
710
         * @see org.gvsig.raster.impl.provider.RasterProvider#setStatus(org.gvsig.raster.impl.provider.RasterProvider)
711
         */
712
        public void setStatus(RasterProvider provider) {
713
                if(provider instanceof GdalProvider) {
714
                        //Not implemented yet
715
                }
716
        }
717
        
718
        /*
719
         * (non-Javadoc)
720
         * @see org.gvsig.raster.impl.provider.RasterProvider#getTileServer()
721
         */
722
        public TileServer getTileServer() {
723
                if(tileServer == null)
724
                        tileServer = new FileTileServer(this);
725
                return tileServer;
726
        }
727
}