Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.wmts / org.gvsig.wmts.provider / src / main / java / org / gvsig / wmts / provider / WMTSBandTileManager.java @ 8842

History | View | Annotate | Download (3.73 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.wmts.provider;
24

    
25
import java.io.IOException;
26
import java.nio.Buffer;
27

    
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30

    
31
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
32
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
33
import org.gvsig.raster.lib.buffer.api.Band;
34
import org.gvsig.raster.lib.buffer.api.BandInfo;
35
import org.gvsig.raster.lib.buffer.api.BandTileManager;
36
import org.gvsig.raster.lib.buffer.api.TileStruct;
37
import org.gvsig.tools.dispose.Disposable;
38
import org.gvsig.tools.dispose.DisposeUtils;
39
import org.gvsig.tools.dispose.impl.AbstractDisposable;
40
import org.gvsig.tools.exception.BaseException;
41

    
42

    
43
/**
44
 * @author fdiaz
45
 *
46
 */
47
public class WMTSBandTileManager extends AbstractDisposable implements BandTileManager {
48

    
49
    private static final Logger logger = LoggerFactory.getLogger(WMTSBandTileManager.class);
50

    
51
    private int bandNumber;
52
    private int zoomLevel;
53

    
54
    private TileStruct tileStruct;
55
    private WMTSImage wmtsImage;
56

    
57
    /**
58
     * @param tileStruct
59
     * @param wmtsImage
60
     * @param zoomLevel
61
     * @param bandNumber
62
     */
63
    public WMTSBandTileManager(TileStruct tileStruct, WMTSImage wmtsImage, int zoomLevel, int bandNumber) {
64
        this.bandNumber = bandNumber;
65
        this.tileStruct = tileStruct;
66
        DisposeUtils.bind((Disposable) this.tileStruct);
67
        this.zoomLevel = zoomLevel;
68
        this.wmtsImage = wmtsImage;
69
        DisposeUtils.bind(this.wmtsImage);
70
    }
71

    
72
    @Override
73
    public boolean isSupportedSave() {
74
        return false;
75
    }
76

    
77
    @Override
78
    public Band load(int row, int col, int dataType) throws IOException {
79

    
80
        int tileRow=(int)row/getRowsPerTile();
81
        int tileCol=(int)col/getColumnsPerTile();
82

    
83
        try {
84
            return wmtsImage.fetchTile(bandNumber, this.zoomLevel, tileRow, tileCol);
85
        } catch (ValidateDataParametersException | CreateEnvelopeException | CloneNotSupportedException e) {
86
            throw new IOException("Can't load band.", e);
87
        }
88
    }
89

    
90
    @Override
91
    public void save(Buffer buffer, int row, int rows, int col, int cols, int dataType) throws IOException {
92
        throw new UnsupportedOperationException();
93
    }
94

    
95
    @Override
96
    public BandInfo getBandInfo() {
97
        // TODO Auto-generated method stub
98
        return null;
99
    }
100

    
101
    @Override
102
    public int getRowsPerTile() {
103
        return tileStruct.getRowsPerTile();
104
    }
105

    
106
    @Override
107
    public int getColumnsPerTile() {
108
        return tileStruct.getColumnsPerTile();
109
    }
110

    
111
    @Override
112
    public TileStruct getTileStruct() {
113
        return this.tileStruct;
114
    }
115

    
116
    @Override
117
    public void doDispose() throws BaseException {
118
        DisposeUtils.dispose(wmtsImage);
119
        wmtsImage = null;
120
        DisposeUtils.dispose((Disposable) this.tileStruct);
121
        this.tileStruct=null;
122
    }
123

    
124
}