Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.io / org.gvsig.raster.io.base / src / main / java / org / gvsig / fmap / dal / coverage / dataset / io / gdal / GdalProvider.java @ 453

History | View | Annotate | Download (24.3 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.fmap.dal.coverage.dataset.io.gdal;
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.dataset.Buffer;
37
import org.gvsig.fmap.dal.coverage.dataset.io.tile.downloader.FileTileServer;
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.RasterFileStoreParameters;
48
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
49
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
50
import org.gvsig.metadata.MetadataLocator;
51
import org.gvsig.raster.cache.tile.provider.TileListener;
52
import org.gvsig.raster.cache.tile.provider.TileServer;
53
import org.gvsig.raster.impl.datastruct.ExtentImpl;
54
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
55
import org.gvsig.raster.impl.provider.RasterProvider;
56
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
57
import org.gvsig.raster.impl.store.AbstractRasterDataStore;
58
import org.gvsig.raster.impl.store.DefaultStoreFactory;
59
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
60
import org.gvsig.raster.impl.store.properties.DataStoreMetadata;
61
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
62
import org.gvsig.tools.ToolsLocator;
63
import org.gvsig.tools.extensionpoint.ExtensionPoint;
64
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
65

    
66
import es.gva.cit.jgdal.GdalException;
67
/**
68
 * Clase que representa al driver de acceso a datos de gdal.
69
 *
70
 * @author Luis W. Sevilla
71
 * @author Nacho Brodin (nachobrodin@gmail.com)
72
 */
73
public class GdalProvider extends DefaultRasterProvider {
74
        public static String        NAME                     = "Gdal Store";
75
        public static String        DESCRIPTION              = "Gdal Raster file";
76
        public static final String  METADATA_DEFINITION_NAME = "GdalStore";
77
        
78
        public static final String  FORMAT_GTiff    = "GTiff";
79
        public static final String  FORMAT_VRT      = "VRT";
80
        public static final String  FORMAT_NITF     = "NITF";
81
        public static final String  FORMAT_HFA      = "HFA";
82
        public static final String  FORMAT_ELAS     = "ELAS";
83
        public static final String  FORMAT_MEM      = "MEM";
84
        public static final String  FORMAT_BMP      = "BMP";
85
        public static final String  FORMAT_PCIDSK   = "PCIDSK";
86
        public static final String  FORMAT_ILWIS    = "ILWIS";
87
        public static final String  FORMAT_HDF4     = "HDF4Image";
88
        public static final String  FORMAT_PNM      = "PNM";
89
        public static final String  FORMAT_ENVI     = "ENVI";
90
        public static final String  FORMAT_EHDR     = "EHdr";
91
        public static final String  FORMAT_PAUX     = "PAux";
92
        public static final String  FORMAT_MFF      = "MFF";
93
        public static final String  FORMAT_MFF2     = "MFF2";
94
        public static final String  FORMAT_BT       = "BT";
95
        public static final String  FORMAT_IDA      = "IDA";
96
        public static final String  FORMAT_RMF      = "RMF";
97
        public static final String  FORMAT_RST      = "RST";
98
        public static final String  FORMAT_LEVELLER = "Leveller";
99
        public static final String  FORMAT_TERRAGEN = "Terragen";
100
        public static final String  FORMAT_ERS      = "ERS";
101
        public static final String  FORMAT_INGR     = "INGR";
102
        public static final String  FORMAT_GSAG     = "GSAG";
103
        public static final String  FORMAT_GSBG     = "GSBG";
104
        public static final String  FORMAT_ADRG     = "ADRG";
105
        public static final int     BAND_HEIGHT     = 64;
106
        protected GdalNative        file            = null;
107
        private static String[]     formatList      = new String[]{
108
                "bmp", 
109
                "gif",
110
                "tif",
111
                "tiff",
112
                "jpg",
113
                "jpeg",
114
                "png",
115
                "vrt",
116
                "dat", // Envi
117
                "lan", // Erdas
118
                "gis", // Erdas
119
                "img", // Erdas
120
                "pix", // PCI Geomatics
121
                "aux", // PCI Geomatics
122
                "adf", // ESRI Grids
123
                "mpr", // Ilwis
124
                "mpl", // Ilwis
125
                "map", // PC Raster
126
                "asc",
127
                "pgm", //Ficheros PNM en escala de grises
128
                "ppm", //Ficheros PNM en RGB
129
                "rst", //IDRISIS
130
                "rmf", //Raster Matrix Format
131
                "nos",
132
                "kap",
133
                "hdr",
134
                "raw",
135
                "ers",};
136

    
137
        private Extent       viewRequest   = null;
138
        private TileServer   tileServer    = null;
139

    
140
        public static void register() {
141
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
142
                ExtensionPoint point = extensionPoints.get("RasterReader");
143
                addFormatsToRegistry(point, GdalProvider.class);
144
                
145
                point = extensionPoints.get("DefaultDriver");
146
                point.append("reader", "", GdalProvider.class);
147
                
148
                DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
149
                if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
150
                        dataman.registerStoreProvider(NAME,
151
                                        GdalProvider.class, GdalDataParameters.class);
152
                }
153
                
154
                if(DALFileLocator.getFilesystemServerExplorerManager() != null)
155
                        DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
156
                                        NAME, DESCRIPTION,
157
                                        GdalFilesystemServerExplorer.class);
158
                
159
                dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
160
        }
161
        
162
        /**
163
         * Adds the list format to the extension point
164
         * @param point
165
         */
166
        public static void addFormatsToRegistry(ExtensionPoint point, Class<?> c) {
167
                for (int i = 0; i < formatList.length; i++) {
168
                        point.append(formatList[i], "", c);
169
                }
170
        }
171
        
172
        /**
173
         * Returns true if the extension is supported and false if doesn't
174
         * @param ext
175
         * @return
176
         */
177
        public static boolean isExtensionSupported(String ext) {
178
                for (int i = 0; i < formatList.length; i++) {
179
                        if(formatList[i].compareTo(ext) == 0)
180
                                return true;
181
                }
182
                return false;
183
        }
184
        
185
        /**
186
         * Constructor. Abre el dataset.
187
         * @param proj Proyecci?n
188
         * @param fName Nombre del fichero
189
         * @throws NotSupportedExtensionException
190
         */
191
        public GdalProvider(String params) throws NotSupportedExtensionException {
192
                super(params);
193
                if(params instanceof String) {
194
                        GdalDataParameters p = new GdalDataParameters();
195
                        p.setURI((String)params);
196
                        super.init(p, null, ToolsLocator.getDynObjectManager()
197
                                        .createDynObject(
198
                                                        MetadataLocator.getMetadataManager().getDefinition(
199
                                                                        DataStore.METADATA_DEFINITION_NAME)));
200
                        init(p, null);
201
                }
202
        }
203
        
204
        public GdalProvider (GdalDataParameters params,
205
                        AbstractRasterDataStore storeServices) throws NotSupportedExtensionException {
206
                super(params, storeServices, ToolsLocator.getDynObjectManager()
207
                                .createDynObject(
208
                                                MetadataLocator.getMetadataManager().getDefinition(
209
                                                                DataStore.METADATA_DEFINITION_NAME)));
210
                init(params, storeServices);
211
        }
212

    
213
        /**
214
         * Crea las referencias al fichero y carga
215
         * las estructuras con la informaci?n y los metadatos.
216
         * @param proj Proyecci?n
217
         * @param param Parametros de carga
218
         * @throws NotSupportedExtensionException
219
         */
220
        public void init (AbstractRasterDataParameters params,
221
                        DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
222
                try {
223
                        if(((RasterFileStoreParameters)params).getFile().exists()) {
224
                                setParam(params);
225
                                validRmf(params.getURI());
226
                                file = new GdalNative(translateFileName(params.getURI()));
227
                                setColorTable(file.palette);
228
                                noData = file.getNoDataValue();
229
                                wktProjection = file.getProjectionRef();
230
                                //CrsWkt crs = new CrsWkt(wktProjection);
231
                                //IProjection proj = CRSFactory.getCRS("EPSG:23030");
232
                                noDataEnabled = file.existsNoDataValue();
233
                                ownTransformation = file.getOwnTransformation();
234
                                externalTransformation = (AffineTransform)ownTransformation.clone();
235
                                load();
236
                        } else
237
                                setParam(params);
238
                                //TODO: FUNCIONALIDAD: Formatos gestionados por gdal que no tienen extensi?n. Estos tendr?n un objeto IRegistrableRasterFormat Por ej: Grass
239
                        bandCount = file.getRasterCount();
240
                } catch (GdalException e) {
241
                        throw new NotSupportedExtensionException("Extension not supported", e);
242
                } catch(Exception e) {
243
                                System.out.println("Error en GdalOpen");
244
                                e.printStackTrace();
245
                                file = null;
246
                }
247

    
248
                //Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
249
                int[] dt = new int[file.getDataType().length];
250
                for (int i = 0; i < dt.length; i++)
251
                        dt[i] = rasterUtil.getRasterBufTypeFromGdalType(file.getDataType()[i]);
252
                setDataType(dt);
253

    
254
                super.init();
255

    
256
                try {
257
                        loadFromRmf(getRmfBlocksManager());
258
                } catch (ParsingException e) {
259
                        //No lee desde rmf
260
                }
261
        }
262

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

    
306
        /*
307
         * (non-Javadoc)
308
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
309
         */
310
        public void close() {
311
                try {
312
                        if(file != null){
313
                                file.close();
314
                                file = null;
315
                        }
316
                        viewRequest = null;
317
                } catch (GdalException e) {
318
                        e.printStackTrace();
319
                }
320
        }
321

    
322
        /*
323
         * (non-Javadoc)
324
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String)
325
         */
326
        public String translateFileName(String fileName) {
327
                if(fileName.endsWith("hdr"))
328
                        return fileName.substring(0, fileName.lastIndexOf("."));
329
                return fileName;
330
        }
331

    
332
        /**
333
         * Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n
334
         * de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v)
335
         * ha de estar en coordenadas del fichero.
336
         */
337
        public void setView(Extent e) {
338
                viewRequest = new ExtentImpl(e);
339
        }
340

    
341
        /*
342
         * (non-Javadoc)
343
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
344
         */
345
        public Extent getView() {
346
                return viewRequest;
347
        }
348

    
349
        /*
350
         * (non-Javadoc)
351
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
352
         */
353
        public double getWidth() {
354
                return file.width;
355
        }
356

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

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

    
380
                try{
381
                        return file.readCompleteLine(line, band);
382
                }catch(GdalException e){
383
                        throw new RasterDriverException("Error reading data from Gdal library");
384
                }
385
        }
386

    
387
        /*
388
         *  (non-Javadoc)
389
         * @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int)
390
         */
391
        public Object readBlock(int pos, int blockHeight)
392
                throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
393
                if(pos < 0)
394
                        throw new InvalidSetViewException("Request out of grid");
395

    
396
                if((pos + blockHeight) > getHeight())
397
                        blockHeight = Math.abs(((int)getHeight()) - pos);
398
                try{
399
                        return file.readBlock(pos, blockHeight);
400
                }catch(GdalException e){
401
                        throw new RasterDriverException("Error reading data from Gdal library");
402
                }
403
        }
404

    
405
        /*
406
         * (non-Javadoc)
407
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
408
         */
409
        public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
410
                if(file != null){
411
                        if(x < 0 || y < 0 || x >= file.width || y >= file.height)
412
                                throw new InvalidSetViewException("Request out of grid");
413
                        Object[] data = file.getData(x, y);
414
                        return data[band];
415
                }
416
                throw new FileNotOpenException("GdalNative not exist");
417
        }
418
        
419
        /*
420
         * (non-Javadoc)
421
         * @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)
422
         */
423
        public void getWindow(Extent ex, int bufWidth, int bufHeight, 
424
                        BandList bandList, TileListener listener) throws ProcessInterruptedException, RasterDriverException {
425
                 
426
        }
427

    
428
        /*
429
         * (non-Javadoc)
430
         * @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)
431
         */
432
        public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf) 
433
                throws ProcessInterruptedException, RasterDriverException {
434
                setView(ex);
435

    
436
                try {
437
                        file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight(), true);
438
                } catch (GdalException e) {
439
                        throw new RasterDriverException("Error reading data");
440
                }
441

    
442
                return rasterBuf;
443
        }
444

    
445
        /*
446
         * (non-Javadoc)
447
         * @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)
448
         */
449
        public Buffer getWindow(double ulx, double uly, double w, double h, 
450
                        BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
451
                //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
452
                //tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o y - h
453
                Extent ext = getExtent();
454
                Point2D pInit = rasterToWorld(new Point2D.Double(0, 0));
455
                Point2D pEnd = rasterToWorld(new Point2D.Double(getWidth(), getHeight()));
456
                double wRaster = Math.abs(pEnd.getX() - pInit.getX());
457
                double hRaster = Math.abs(pEnd.getY() - pInit.getY());
458
                double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w);
459
                double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h);
460

    
461
                Extent selectedExtent = new ExtentImpl(ulx, uly, lrx, lry);
462
                setView(selectedExtent);
463

    
464
                try {
465
                        file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight(), adjustToExtent);
466
                } catch (GdalException e) {
467
                        throw new RasterDriverException("Error reading data");
468
                }
469

    
470
                return rasterBuf;
471
        }
472

    
473
        /*
474
         * (non-Javadoc)
475
         * @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)
476
         */
477
        public Buffer getWindow(Extent extent, 
478
                        int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
479
                setView(extent);
480

    
481
                double width = 0;
482
                double height = 0;
483

    
484
                Point2D ul = new Point2D.Double(viewRequest.getULX(), viewRequest.getULY());
485
                Point2D lr = new Point2D.Double(viewRequest.getLRX(), viewRequest.getLRY());
486
                ul = worldToRaster(ul);
487
                lr = worldToRaster(lr);
488
                ul.setLocation(ul.getX() < 0 ? 1 : ul.getX(), ul.getY() < 0 ? 1 : ul.getY());
489
                lr.setLocation(lr.getX() < 0 ? 1 : lr.getX(), lr.getY() < 0 ? 1 : lr.getY());
490
                
491
                ul.setLocation(ul.getX() - 0.5, ul.getY() - 0.5);
492
                lr.setLocation(lr.getX() - 0.5, lr.getY() - 0.5);
493
                
494
                adjustPoints(ul, lr);
495
                
496
                width = Math.abs(((int)lr.getX()) - ((int)ul.getX())) + 1;
497
                height = Math.abs(((int)lr.getY()) - ((int)ul.getY())) + 1;
498

    
499
                try {
500
                        file.readWindow(rasterBuf, bandList, viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), width, height, bufWidth, bufHeight, adjustToExtent);
501
                } catch (GdalException e) {
502
                        throw new RasterDriverException("Error reading data");
503
                }
504

    
505
                return rasterBuf;
506
        }
507
        
508

    
509
        private void adjustPoints(Point2D ul, Point2D lr) {
510
                double a = (ul.getX() - (int)ul.getX());
511
                double b = (ul.getY() - (int)ul.getY());
512
                ul.setLocation(        (a > 0.95 || a < 0.05) ? Math.round(ul.getX()) : ul.getX(), 
513
                                                (b > 0.95 || b < 0.05) ? Math.round(ul.getY()) : ul.getY());
514
                lr.setLocation(        (a > 0.95 || a < 0.05) ? Math.round(lr.getX()) : lr.getX(), 
515
                                                (b > 0.95 || b < 0.05) ? Math.round(lr.getY()) : lr.getY());
516
        }
517

    
518
        /*
519
         * (non-Javadoc)
520
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
521
         */
522
        public Buffer getWindow(int x, int y, 
523
                        BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
524
                try {
525
                        int w = rasterBuf.getWidth();
526
                        int h = rasterBuf.getHeight();
527
                        setView(
528
                        new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
529
                                                getWidth(),
530
                                                getHeight(),
531
                                                new Rectangle2D.Double(x, y, w, h)))
532
                        );
533
                        file.readWindow(rasterBuf, bandList, x, y, w, h);
534
                } catch (GdalException e) {
535
                        throw new RasterDriverException("Error reading data");
536
                }
537
                return rasterBuf;
538
        }
539

    
540
        /*
541
         * (non-Javadoc)
542
         * @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)
543
         */
544
        public Buffer getWindow(int x, int y, int w, int h, 
545
                        int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
546
                try {
547
                        setView(
548
                        new ExtentImpl( rasterUtil.getMapRectFromPxRect(getExtent().toRectangle2D(),
549
                                                getWidth(),
550
                                                getHeight(),
551
                                                new Rectangle2D.Double(x, y, w, h)))
552
                        );
553
                        file.readWindow(rasterBuf, bandList, x, y, w, h, bufWidth, bufHeight);
554
                } catch (GdalException e) {
555
                        throw new RasterDriverException("Error reading data");
556
                }
557
                return rasterBuf;
558
        }
559

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

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

    
582
        /*
583
         * (non-Javadoc)
584
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getColorInterpretation()
585
         */
586
        public DataStoreColorInterpretation getColorInterpretation(){
587
                if(file != null)
588
                        return file.colorInterpr;
589
                return null;
590
        }
591

    
592
        /*
593
         * (non-Javadoc)
594
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setColorInterpretation(org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation)
595
         */
596
        public void setColorInterpretation(DataStoreColorInterpretation colorInterpretation){
597
                if(file != null)
598
                        file.colorInterpr = colorInterpretation;
599
        }
600

    
601
        /*
602
         * (non-Javadoc)
603
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency()
604
         */
605
        public DataStoreTransparency getTransparency() {
606
                return file.fileTransparency;
607
        }
608

    
609
        /*
610
         * (non-Javadoc)
611
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isGeoreferenced()
612
         */
613
        public boolean isGeoreferenced() {
614
                if(file != null)
615
                        return file.georeferenced;
616
                else
617
                        return false;
618
        }
619

    
620
        /**
621
         * Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
622
         * el valor de esta variable cada vez que dibuja.
623
         * @return true si se ha supersampleado y false si no se ha hecho.
624
         */
625
        public boolean isSupersampling() {
626
                if(file != null)
627
                        return file.isSupersampling;
628
                else
629
                        return false;
630
        }
631

    
632
        public GdalNative getNative(){
633
                return file;
634
        }
635

    
636
        /*
637
         * (non-Javadoc)
638
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform)
639
         */
640
        public void setAffineTransform(AffineTransform t){
641
                super.setAffineTransform(t);
642
                file.setExternalTransform(t);
643
        }
644

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

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

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

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

    
699
        /*
700
         * (non-Javadoc)
701
         * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isReproyectable()
702
         */
703
        public boolean isReproyectable() {
704
                return true;
705
        }
706

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