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

History | View | Annotate | Download (24.8 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.io.BufferedReader;
26
import java.io.File;
27
import java.io.FileNotFoundException;
28
import java.io.FileReader;
29
import java.io.IOException;
30
import java.net.URI;
31
import java.net.URISyntaxException;
32

    
33
import org.apache.commons.io.FileUtils;
34
import org.apache.commons.io.FilenameUtils;
35
import org.apache.commons.lang3.StringUtils;
36
import org.cresques.cts.ICRSFactory;
37
import org.cresques.cts.IProjection;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

    
41
import org.gvsig.fmap.crs.CRSFactory;
42
import org.gvsig.fmap.dal.DALFileLocator;
43
import org.gvsig.fmap.dal.DALLocator;
44
import org.gvsig.fmap.dal.DataStore;
45
import org.gvsig.fmap.dal.coverage.RasterLocator;
46
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
47
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
48
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
49
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
50
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
51
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
52
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
53
import org.gvsig.fmap.dal.coverage.exception.ParsingException;
54
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
55
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
56
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
57
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
58
import org.gvsig.fmap.dal.exception.OpenException;
59
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
60
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
61
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
62
import org.gvsig.jgdal.GdalException;
63
import org.gvsig.metadata.MetadataLocator;
64
import org.gvsig.raster.cache.tile.provider.TileServer;
65
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
66
import org.gvsig.raster.impl.datastruct.ExtentImpl;
67
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
68
import org.gvsig.raster.impl.provider.RasterProvider;
69
import org.gvsig.raster.impl.provider.tile.FileTileServer;
70
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
71
import org.gvsig.raster.impl.store.DefaultRasterStore;
72
import org.gvsig.raster.impl.store.DefaultStoreFactory;
73
import org.gvsig.raster.impl.store.properties.DataStoreMetadata;
74
import org.gvsig.tools.ToolsLocator;
75
import org.gvsig.tools.dynobject.DynObject;
76
import org.gvsig.tools.extensionpoint.ExtensionPoint;
77
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
78

    
79

    
80
/**
81
 * This class represents the data access for gdal formats.
82
 *
83
 * @author Nacho Brodin (nachobrodin@gmail.com)
84
 */
85
public class GdalProvider extends AbstractRasterProvider {
86

    
87
    public static String NAME = "Gdal Store";
88
    public static String DESCRIPTION = "Gdal Raster file";
89
    public static final String METADATA_DEFINITION_NAME = "GdalStore";
90
    private static final Logger logger = LoggerFactory.getLogger(GdalProvider.class);
91

    
92
    public static final String FORMAT_GTiff = "GTiff";
93
    public static final String FORMAT_VRT = "VRT";
94
    public static final String FORMAT_NITF = "NITF";
95
    public static final String FORMAT_HFA = "HFA";
96
    public static final String FORMAT_ELAS = "ELAS";
97
    public static final String FORMAT_MEM = "MEM";
98
    public static final String FORMAT_BMP = "BMP";
99
    public static final String FORMAT_PCIDSK = "PCIDSK";
100
    public static final String FORMAT_ILWIS = "ILWIS";
101
    public static final String FORMAT_HDF4 = "HDF4Image";
102
    public static final String FORMAT_PNM = "PNM";
103
    public static final String FORMAT_ENVI = "ENVI";
104
    public static final String FORMAT_EHDR = "EHdr";
105
    public static final String FORMAT_PAUX = "PAux";
106
    public static final String FORMAT_MFF = "MFF";
107
    public static final String FORMAT_MFF2 = "MFF2";
108
    public static final String FORMAT_BT = "BT";
109
    public static final String FORMAT_IDA = "IDA";
110
    public static final String FORMAT_RMF = "RMF";
111
    public static final String FORMAT_RST = "RST";
112
    public static final String FORMAT_LEVELLER = "Leveller";
113
    public static final String FORMAT_TERRAGEN = "Terragen";
114
    public static final String FORMAT_ERS = "ERS";
115
    public static final String FORMAT_INGR = "INGR";
116
    public static final String FORMAT_GSAG = "GSAG";
117
    public static final String FORMAT_GSBG = "GSBG";
118
    public static final String FORMAT_ADRG = "ADRG";
119
    public static final String FORMAT_JP2 = "JPEG2000";
120
    public static final String FORMAT_GRD = "GRD";
121
    public static final int BAND_HEIGHT = 64;
122
    protected GdalDataSource file = null;
123
    private Extent viewRequest = null;
124
    protected static String[][] formatList = null;
125

    
126
    public static void register() {
127
        ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
128
        registerFormats();
129

    
130
        ExtensionPoint point = extensionPoints.get("DefaultRasterProvider");
131
        point.append("reader", GdalProvider.NAME, GdalProvider.class);
132

    
133
        RasterLocator.getManager().getProviderServices().registerFileProvidersTiled(GdalProvider.class);
134

    
135
        DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
136
        if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
137
            dataman.registerStoreProvider(NAME,
138
                    GdalProvider.class, GdalDataParameters.class);
139
        }
140

    
141
        if (DALFileLocator.getFilesystemServerExplorerManager() != null) {
142
            DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
143
                    NAME, DESCRIPTION,
144
                    GdalFilesystemServerExplorer.class);
145
        }
146

    
147
        dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
148
    }
149

    
150
    private static void registerFormats() {
151
        formatList = new String[][]{
152
            new String[]{"bmp", "image/bmp"},
153
            new String[]{"gif", "image/gif"},
154
            new String[]{"tif", "image/tiff"},
155
            new String[]{"tiff", "image/tiff"},
156
            new String[]{"jpg", "image/jpeg"},
157
            new String[]{"jpeg", "image/jpeg"},
158
            new String[]{"png", "image/png"},
159
            new String[]{"vrt", "image/vrt"},
160
            new String[]{"dat", "image/dat"}, // Envi
161
            new String[]{"lan", "image/lan"}, // Erdas
162
            new String[]{"gis", "image/gis"}, // Erdas
163
            new String[]{"img", "image/img"}, // Erdas
164
            new String[]{"pix", "image/pix"},// PCI Geomatics
165
            new String[]{"aux", "image/aux"}, // PCI Geomatics
166
            new String[]{"adf", "image/adf"}, // ESRI Grids
167
            new String[]{"mpr", "image/mpr"}, // Ilwis
168
            new String[]{"mpl", "image/mpl"}, // Ilwis
169
            new String[]{"map", "image/map"},// PC Raster
170
            new String[]{"asc", "image/asc"},
171
            new String[]{"pgm", "image/pgn"},//Ficheros PNM en escala de grises
172
            new String[]{"ppm", "image/ppm"},//Ficheros PNM en RGB
173
            new String[]{"rst", "image/rst"},//IDRISIS
174
            new String[]{"rmf", "image/rmf"},//Raster Matrix Format
175
            new String[]{"nos", "image/nos"},
176
            new String[]{"kap", "image/kap"},
177
            new String[]{"hdr", "image/hdr"},
178
            new String[]{"raw", "image/raw"},
179
            new String[]{"ers", "image/ers"},
180
            new String[]{"xml", "image/xml"},
181
            new String[]{"grd", "image/grd"},
182
            /*
183
             new String[] {"jp2","image/jp2" },
184
             new String[] {"mrsid","image/mrsid" },
185
             new String[] {"ecw","image/ecw" },
186
             */
187
            new String[]{"txt", "image/txt"}
188
        };
189
        for (int i = 0; i < formatList.length; i++) {
190
            RasterLocator.getManager().getProviderServices().addFormat(formatList[i][0], GdalProvider.class);
191
        }
192
    }
193

    
194
    public String[] getFormatList() {
195
        String[] fl = new String[formatList.length];
196
        for (int i = 0; i < fl.length; i++) {
197
            fl[i] = formatList[i][0];
198
        }
199
        return fl;
200
    }
201

    
202
    /**
203
     * Returns true if the extension is supported and false if doesn't
204
     *
205
     * @param ext
206
     * @return
207
     */
208
    public boolean isExtensionSupported(String ext) {
209
        if (ext.indexOf(".") != -1) {
210
            ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length());
211
        }
212
        for (int i = 0; i < formatList.length; i++) {
213
            if (formatList[i][0].compareTo(ext) == 0) {
214
                return true;
215
            }
216
        }
217
        return false;
218
    }
219

    
220
    /**
221
     * Mandatory constructor to instantiate an empty provider
222
     */
223
    public GdalProvider() {
224
    }
225

    
226
    /**
227
     * Constructor. Abre el dataset.
228
     *
229
     * @param params
230
     * @throws NotSupportedExtensionException
231
     * @throws OpenException
232
     * @deprecated use {@link #GdalProvider(URI)}, this constructor will be
233
     * removed in gvSIG 2.5
234
     */
235
    public GdalProvider(String params) throws NotSupportedExtensionException, OpenException {
236
        super(params);
237
        logger.info("Deprecated use of GdalProvider constructor");
238
        if (params instanceof String) {
239
            GdalDataParameters p = new GdalDataParameters();
240
            URI uriParam;
241
            try {
242
                uriParam = new URI((String) params);
243
            } catch (URISyntaxException e) {
244
                throw new OpenException("Can't create uri from " + (String) params, e);
245
            }
246
            p.setURI(uriParam);
247
            super.init(p, null, ToolsLocator.getDynObjectManager()
248
                    .createDynObject(
249
                            MetadataLocator.getMetadataManager().getDefinition(
250
                                    DataStore.METADATA_DEFINITION_NAME)));
251
            init(p, null);
252
        }
253
    }
254

    
255
    /**
256
     * Constructor. Abre el dataset.
257
     *
258
     * @param uri
259
     * @throws NotSupportedExtensionException
260
     */
261
    public GdalProvider(URI uri) throws NotSupportedExtensionException {
262
        super(uri);
263
        GdalDataParameters p = new GdalDataParameters();
264
        p.setURI(uri);
265
        super.init(
266
                p,
267
                null,
268
                ToolsLocator.getDynObjectManager().createDynObject(
269
                        MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME)));
270
        init(p, null);
271
    }
272

    
273
    public GdalProvider(GdalDataParameters params,
274
            DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
275
        super(params, storeServices, ToolsLocator.getDynObjectManager()
276
                .createDynObject(
277
                        MetadataLocator.getMetadataManager().getDefinition(
278
                                DataStore.METADATA_DEFINITION_NAME)));
279
        init(params, storeServices);
280
    }
281

    
282
    public GdalProvider(AbstractRasterDataParameters params,
283
            DataStoreProviderServices storeServices, DynObject metadata) {
284
        super(params, storeServices, metadata);
285
    }
286

    
287
    /**
288
     * Creates file references and loads structures with the information and
289
     * metadata
290
     *
291
     * @param params load parameters
292
     * @param storeServices
293
     * @throws NotSupportedExtensionException
294
     */
295
    public void init(AbstractRasterDataParameters params,
296
            DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
297
        try {
298
            setParam(storeServices, params);
299
            String fname = getFileName(params);
300
            setFName(fname);
301
            file = new GdalDataSource(fname);
302
            setColorInterpretation(file.colorInterpr);
303
            setColorTable(file.palette);
304
            noData = file.getNoDataValue();
305
            ICRSFactory crsFactory = CRSFactory.getCRSFactory();
306

    
307
            IProjection proj = params.getSRS();
308
            if (proj == null) {
309
                File prjFile = getPrjFile(params.getURI());
310
                if (prjFile.exists()) {
311
                    String wktEsri = loadPrj(prjFile);
312
                    if (wktEsri != null) {
313
                        proj = crsFactory.get(ICRSFactory.FORMAT_WKT_ESRI,
314
                            wktEsri);
315
                    }
316
                }
317
            }
318
            if (proj == null) {
319
                String wktProjection = file.getProjectionRef();
320
                if (!StringUtils.isEmpty(wktProjection) ) {
321
                    try {
322
                        proj = crsFactory.get(ICRSFactory.FORMAT_WKT, wktProjection);
323
                        if ( StringUtils.isEmpty( proj.getAbrev()) ){
324
                            proj=null;
325
                        } else {
326
                            setProjection(proj, true);
327
                        }
328
                    } catch (Exception e ) {
329
                        proj=null;
330
                        logger.info("Error reading WKT from the raster provider", e);
331
                    }
332
                }
333
            } else {
334
                setProjection(proj, false);
335
            }
336

    
337
            ownTransformation = file.getOwnTransformation();
338
            externalTransformation = (AffineTransform) ownTransformation.clone();
339
            load();
340

    
341
            if (file != null) {
342
                bandCount = file.getRasterCount();
343
            }
344
        } catch (GdalException e) {
345
            throw new NotSupportedExtensionException("Extension not supported", e);
346
        } catch (Exception e) {
347
            System.out.println("Error en GdalOpen");
348
            e.printStackTrace();
349
            file = null;
350
        }
351

    
352
        //Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
353
        int[] dt = new int[file.getDataType().length];
354
        for (int i = 0; i < dt.length; i++) {
355
            dt[i] = GdalDataSource.getRasterBufTypeFromGdalType(file.getDataType()[i]);
356
        }
357
        setDataType(dt);
358

    
359
        super.init();
360

    
361
        try {
362
            loadFromRmf(getRmfBlocksManager());
363
        } catch (ParsingException e) {
364
            //No lee desde rmf
365
            logger.debug("Problems reading from the RMF file", e);
366
        }
367
    }
368

    
369
    private String getFileName(RasterDataParameters params) throws GdalException {
370
        File f = new File(params.getURI());
371
        validRmf(f.getAbsolutePath());
372
        return translateFileName(f.getAbsolutePath());
373
    }
374

    
375
    public String getMimeType() {
376
        try {
377
            File f = ((FilesystemStoreParameters) (this.getDataStoreParameters())).getFile();
378
            String ext = FilenameUtils.getExtension(f.getName());
379
            for (int i = 0; i < formatList.length; i++) {
380
                if (ext.equalsIgnoreCase(formatList[i][0])) {
381
                    return formatList[i][1];
382
                }
383
            }
384
        } catch (Exception ex) {
385
            logger.warn("Can't get mime type for GDAL archive.", ex);
386
        }
387
        return "image";
388
    }
389

    
390
    /**
391
     * Comprueba si el fichero abierto es un RasterMetaFile o una imagen raster.
392
     *
393
     * @throws GdalException
394
     */
395
    private void validRmf(String file) throws GdalException {
396
        if (file.endsWith(".rmf")) {
397
            File f = new File(file);
398
            try {
399
                FileReader fr = new FileReader(f);
400
                BufferedReader br = new BufferedReader(fr);
401
                char[] buffer = new char[5];
402
                br.read(buffer);
403
                StringBuffer st = new StringBuffer(new String(buffer));
404
                br.close();
405
                fr.close();
406
                if (st.toString().equals("<?xml")) {
407
                    throw new GdalException("RasterMetaFile");
408
                }
409
            } catch (FileNotFoundException e) {
410
                throw new GdalException("File Not Found");
411
            } catch (IOException e) {
412
                throw new GdalException("");
413
            }
414
        }
415
    }
416

    
417
    public RasterProvider load() {
418
        return this;
419
    }
420

    
421
    public boolean isOpen() {
422
        if (file != null && file.isOpen()) {
423
            return true;
424
        }
425
        return false;
426
    }
427

    
428
    public URI translateURI(URI uri) {
429
        String absolutePath = new File(uri).getAbsolutePath();
430
        if ("hdr".equalsIgnoreCase(FilenameUtils.getExtension(absolutePath))) {
431
            File file = new File(FilenameUtils.removeExtension(absolutePath));
432
            return file.toURI();
433
        }
434
        return uri;
435
    }
436

    
437
    /**
438
     * Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer
439
     * una transformaci?n de la vista asignada ya que la petici?n viene en
440
     * coordenadas del fichero .rmf y la vista (v) ha de estar en coordenadas
441
     * del fichero.
442
     *
443
     * @param e
444
     */
445
    public void setView(Extent e) {
446
        viewRequest = new ExtentImpl(e);
447
    }
448

    
449
    public Extent getView() {
450
        return viewRequest;
451
    }
452

    
453
    public double getWidth() {
454
        return file.width;
455
    }
456

    
457
    public double getHeight() {
458
        return file.height;
459
    }
460

    
461
    /**
462
     * Read a line from the file
463
     *
464
     * @param line
465
     * @param band
466
     * @return
467
     * @throws InvalidSetViewException
468
     * @throws FileNotOpenException
469
     * @throws RasterDriverException
470
     * @Deprecated This operation is deprecated because is not useful and in the
471
     * future it will not be maintained. The abstract operation has dissapear
472
     */
473
    public Object readCompleteLine(int line, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
474
        if (line > this.getHeight() || band > this.getBandCount()) {
475
            throw new InvalidSetViewException("Request out of grid");
476
        }
477

    
478
        try {
479
            return file.readCompleteLine(line, band);
480
        } catch (GdalException e) {
481
            throw new RasterDriverException("Error reading data from Gdal library");
482
        }
483
    }
484

    
485
    public Object readBlock(int pos, int blockHeight, double scale)
486
            throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
487
        if (pos < 0) {
488
            throw new InvalidSetViewException("Request out of grid");
489
        }
490

    
491
        if ((pos + blockHeight) > getHeight()) {
492
            blockHeight = Math.abs(((int) getHeight()) - pos);
493
        }
494
        try {
495
            return file.readBlock(pos, blockHeight, scale);
496
        } catch (GdalException e) {
497
            throw new RasterDriverException("Error reading data from Gdal library");
498
        }
499
    }
500

    
501
    public Object getData(int x, int y, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
502
        if (file != null) {
503
            if (x < 0 || y < 0 || x >= file.width || y >= file.height) {
504
                throw new InvalidSetViewException("Request out of grid");
505
            }
506
            Object[] data = file.getData(x, y);
507
            return data[band];
508
        }
509
        throw new FileNotOpenException("GdalNative not exist");
510
    }
511

    
512
    @Override
513
    public void loadBuffer(SpiRasterQuery q)
514
            throws ProcessInterruptedException, RasterDriverException {
515
        setView(q.getAdjustedRequestBoundingBox());
516

    
517
        try {
518
            file.readWindow(q.getBufferForProviders(),
519
                    q.getBandList(),
520
                    q.getAdjustedRequestBoundingBox(),
521
                    q.getAdjustedRequestPxWindow(),
522
                    q.getTaskStatus());
523
        } catch (GdalException e) {
524
            throw new RasterDriverException("Error reading data", e);
525
        }
526

    
527
    }
528

    
529
    public int getBlockSize() {
530
        if (file != null) {
531
            return file.getBlockSize();
532
        } else {
533
            return 0;
534
        }
535
    }
536

    
537
    public DataStoreMetadata getMetadata() {
538
        if (file != null) {
539
            return file.metadata;
540
        } else {
541
            return null;
542
        }
543
    }
544

    
545
    public Transparency getTransparency() {
546
        return file.fileTransparency;
547
    }
548

    
549
    public boolean isGeoreferenced() {
550
        if (file != null) {
551
            return file.georeferenced;
552
        } else {
553
            return false;
554
        }
555
    }
556

    
557
    /**
558
     * Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el
559
     * driver el que colocar? el valor de esta variable cada vez que dibuja.
560
     *
561
     * @return true si se ha supersampleado y false si no se ha hecho.
562
     */
563
    public boolean isSupersampling() {
564
        if (file != null) {
565
            return file.isSupersampling;
566
        } else {
567
            return false;
568
        }
569
    }
570

    
571
    protected GdalDataSource getNative() {
572
        return file;
573
    }
574

    
575
    public void setAffineTransform(AffineTransform t) {
576
        super.setAffineTransform(t);
577
        file.setExternalTransform(t);
578
    }
579

    
580
    public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
581
        if (band >= getBandCount()) {
582
            throw new BandAccessException("Wrong band");
583
        }
584
        try {
585
            return file.getRasterBand(band + 1).getOverviewCount();
586
        } catch (GdalException e) {
587
            throw new RasterDriverException("");
588
        }
589
    }
590

    
591
    public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
592
        if (band >= getBandCount()) {
593
            throw new BandAccessException("Wrong band");
594
        }
595
        try {
596
            if (overview >= file.getRasterBand(band + 1).getOverviewCount()) {
597
                throw new BandAccessException("Wrong overview count");
598
            }
599
            return file.getRasterBand(band + 1).getOverview(overview).getRasterBandXSize();
600
        } catch (GdalException e) {
601
            throw new RasterDriverException("");
602
        }
603
    }
604

    
605
    public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
606
        if (band >= getBandCount()) {
607
            throw new BandAccessException("Wrong band");
608
        }
609
        try {
610
            if (overview >= file.getRasterBand(band + 1).getOverviewCount()) {
611
                throw new BandAccessException("Wrong overview count");
612
            }
613
            return file.getRasterBand(band + 1).getOverview(overview).getRasterBandYSize();
614
        } catch (GdalException e) {
615
            throw new RasterDriverException("");
616
        }
617
    }
618

    
619
    public boolean isOverviewsSupported() {
620
        return true;
621
    }
622

    
623
    public boolean isReproyectable() {
624
        return true;
625
    }
626

    
627
    public boolean needEnhanced() {
628
        return (getDataType()[0] != Buffer.TYPE_BYTE);
629
                //Desconozco pq raz?n estaba esta condici?n. Quiz?s haya que volver a a?adirla
630
        //Eliminada 30/5/2013
631
        //|| (getBandCount() == 1 && getDataType()[0] == Buffer.TYPE_BYTE));
632
    }
633

    
634
    public String getProviderName() {
635
        return NAME;
636
    }
637

    
638
    public void setStatus(RasterProvider provider) {
639
        if (provider instanceof GdalProvider) {
640
            //Not implemented yet
641
        }
642
    }
643

    
644
    public TileServer getTileServer() {
645
        if (tileServer == null) {
646
            DefaultRasterStore store = new DefaultRasterStore();
647
            store.setProvider(this);
648
            tileServer = new FileTileServer(store);
649
//                        tileServer.setFileSuffix("rmf");
650
        }
651
        return tileServer;
652
    }
653

    
654
    public void close() {
655
        if (file != null) {
656
            file.dispose();
657
        }
658
        try {
659
            finalize();
660
        } catch (Throwable e) {
661
        }
662
    }
663

    
664
    protected void finalize() throws Throwable {
665
        file = null;
666
        viewRequest = null;
667
        if (formatList != null) {
668
            for (int i = 0; i < formatList.length; i++) {
669
                formatList[i] = null;
670
            }
671
            formatList = null;
672
        }
673
        super.finalize();
674
    }
675

    
676
    public void addFile(File file) throws InvalidSourceException {
677
        // Do nothing
678
    }
679

    
680
    public void removeFile(File file) {
681
        // Do nothing
682
    }
683

    
684
    private File getPrjFile(URI uri) {
685
        if ("file".equalsIgnoreCase(uri.getScheme())) {
686
            String uriPath = new File(uri).getAbsolutePath();
687
            String prjPath = FilenameUtils.removeExtension(uriPath) + ".prj";
688
            return new File(prjPath);
689
        }
690
        return null;
691
    }
692

    
693
    ;
694

    
695
    private String loadPrj(File prjFile) {
696
        if (prjFile.exists()) {
697
            try {
698
                return FileUtils.readFileToString(prjFile);
699
            } catch (IOException e) {
700
                return null;
701
            }
702
        }
703
        return null;
704
    }
705

    
706
}