Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.bsq / src / main / java / org / gvsig / fmap / dal / file / bsq / BSQStoreProvider.java @ 43867

History | View | Annotate | Download (4.46 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2016 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.dal.file.bsq;
24

    
25
import java.io.IOException;
26
import java.util.ArrayList;
27
import org.gvsig.fmap.dal.exception.InitializeException;
28
import org.gvsig.fmap.dal.exception.OpenException;
29
import org.gvsig.fmap.dal.fileutils.HDRFile;
30
import org.gvsig.fmap.dal.fileutils.spi.UtilsFile;
31
import org.gvsig.fmap.dal.raster.OpenRasterStoreParameters;
32
import org.gvsig.fmap.dal.raster.spi.BandDescriptorServices;
33
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
34
import org.gvsig.tools.exception.BaseException;
35

    
36
public class BSQStoreProvider extends AbstractFileRasterStoreProvider {
37

    
38
    // https://www.qgistutorials.com/en/docs/open_bil_bip_bsq_files.html
39
    // http://glcf.umd.edu/data/landcover/data.shtml
40
    
41
    protected HDRFile hdrFile;
42

    
43
    @SuppressWarnings("OverridableMethodCallInConstructor")
44
    public BSQStoreProvider(
45
            String name,
46
            String description,
47
            OpenRasterStoreParameters params, 
48
            DataStoreProviderServices storeServices) throws InitializeException {
49
        super(
50
                name,
51
                description,
52
                params,
53
                storeServices
54
        );
55
        this.init(params, storeServices);
56
    }
57

    
58
    @Override
59
    public int getBands() {
60
        this.autoOpen();
61
        return this.hdrFile.getNbands();
62
    }
63

    
64
    @Override
65
    public int getRows() {
66
        this.autoOpen();
67
        return this.hdrFile.getNrows();
68
    }
69

    
70
    @Override
71
    public int getColumns() {
72
        this.autoOpen();
73
        return this.hdrFile.getNcols();
74
    }
75
    
76
    @Override
77
    protected void doDispose() throws BaseException {
78
        super.doDispose();
79
        this.hdrFile = null;
80
    }
81
    
82
    @Override
83
    public void open() throws OpenException {
84
        if ( this.hdrFile!=null ) {
85
            return;
86
        }
87
        HDRFile theHDRFile = UtilsFile.createHDRFile(this.getFile());
88
        if (!theHDRFile.isValid()) {
89
            throw new OpenException(this.getProviderName(), null);
90
        }
91
        this.hdrFile = theHDRFile;
92
        this.envelope = this.hdrFile.getEnvelope();
93
        if (this.envelope == null) {
94
            this.envelope = this.wldFile.getEnvelope(
95
                    this.hdrFile.getNrows(),
96
                    this.hdrFile.getNcols()
97
            );
98
        }
99
        try {
100
            int dataType = this.hdrFile.getDataType();
101
            this.pageManagers = new ArrayList<>();
102
            for (int nband = 0; nband < this.hdrFile.getNbands(); nband++) {
103
                BandDescriptorServices bandDescriptor = getBandDescriptor(nband);
104
                bandDescriptor.setDataType(dataType);
105
                bandDescriptor.setName(String.valueOf(nband));
106
                try {
107
                    bandDescriptor.setDescription(this.getName()+ "- band "+nband);
108
                } catch (Exception e) {
109
                    bandDescriptor.setDescription("band "+nband);
110
                }
111
                bandDescriptor.add("X size", this.hdrFile.getNcols());
112
                bandDescriptor.add("Y size", this.hdrFile.getNrows());                
113
                BSQBandPageManager pageManager = new BSQBandPageManager(
114
                        getFile(),
115
                        nband * this.hdrFile.getBandSize(),
116
                        this.hdrFile.getNrows(),
117
                        this.hdrFile.getNcols(),
118
                        dataType
119
                );
120
                this.pageManagers.add(pageManager);
121
            }
122
        } catch (IOException ex) {
123
            this.hdrFile = null;
124
            throw new OpenException(storeProviderName, ex);
125
        }
126
    }
127

    
128
}