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

History | View | Annotate | Download (4.52 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.basicformats.FormatsFile;
28
import org.gvsig.basicformats.HDRFile;
29
import org.gvsig.fmap.dal.exception.InitializeException;
30
import org.gvsig.fmap.dal.exception.OpenException;
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
    protected HDRFile hdrFile;
41

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

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

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

    
69
    @Override
70
    public int getColumns() {
71
        this.autoOpen();
72
        return this.hdrFile.getNcols();
73
    }
74

    
75
    @Override
76
    protected void doDispose() throws BaseException {
77
        super.doDispose();
78
        this.hdrFile = null;
79
    }
80

    
81
    @Override
82
    public void open() throws OpenException {
83
        if (this.hdrFile != null) {
84
            return;
85
        }
86
        HDRFile theHDRFile;
87
        theHDRFile = FormatsFile.getHDRFile(this.getFile());
88
        if (theHDRFile == null || !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
                        this.hdrFile.getByteorder()
120
                );
121
                this.pageManagers.add(pageManager);
122
            }
123
        } catch (IOException ex) {
124
            this.hdrFile = null;
125
            throw new OpenException(storeProviderName, ex);
126
        }
127
    }
128

    
129
}