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

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
                        setProjection(proj, true);
324
                        if ( StringUtils.isEmpty( proj.getAbrev()) ){
325
                            proj=null;
326
                        } else {
327
                            setProjection(proj, true);
328
                        }
329
                    } catch (Exception e ) {
330
                        proj=null;
331
                        logger.info("Error reading WKT from the raster provider", e);
332
                    }
333
                }
334
            } else {
335
                setProjection(proj, false);
336
            }
337

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

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

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

    
360
        super.init();
361

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
528
    }
529

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
694
    ;
695

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

    
707
}