Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.fmap.dal.raster / org.gvsig.fmap.dal.raster.impl / src / main / java / org / gvsig / fmap / dal / raster / impl / DefaultRasterSet.java @ 6302

History | View | Annotate | Download (7.97 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.raster.impl;
24

    
25
import java.util.Iterator;
26

    
27
import org.cresques.cts.ICoordTrans;
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.dal.DataStore;
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.raster.api.RasterQuery;
32
import org.gvsig.fmap.dal.raster.api.RasterSet;
33
import org.gvsig.fmap.dal.raster.api.RasterStore;
34
import org.gvsig.fmap.dal.raster.api.exceptions.RasterSetInitializeException;
35
import org.gvsig.fmap.dal.raster.spi.RasterStoreProvider;
36
import org.gvsig.fmap.geom.primitive.Envelope;
37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.raster.lib.buffer.api.Band;
39
import org.gvsig.raster.lib.buffer.api.Band.BandByte;
40
import org.gvsig.raster.lib.buffer.api.Band.BandDouble;
41
import org.gvsig.raster.lib.buffer.api.Band.BandFloat;
42
import org.gvsig.raster.lib.buffer.api.Band.BandInt;
43
import org.gvsig.raster.lib.buffer.api.Band.BandShort;
44
import org.gvsig.raster.lib.buffer.api.Buffer;
45
import org.gvsig.raster.lib.buffer.api.FilterList;
46
import org.gvsig.raster.lib.buffer.api.NoData;
47
import org.gvsig.raster.lib.buffer.api.exceptions.BandException;
48
import org.gvsig.raster.lib.buffer.api.exceptions.BufferException;
49
import org.gvsig.raster.lib.buffer.api.statistics.Statistics;
50
import org.gvsig.tools.exception.BaseException;
51
import org.gvsig.tools.locator.LocatorException;
52
import org.gvsig.tools.observer.Observable;
53
import org.gvsig.tools.observer.Observer;
54
import org.gvsig.tools.task.SimpleTaskStatus;
55
import org.gvsig.tools.visitor.VisitCanceledException;
56
import org.gvsig.tools.visitor.Visitor;
57
import org.gvsig.tools.visitor.impl.AbstractIndexedVisitable;
58

    
59
/**
60
 * Implements RasterSet
61
 * 
62
 * @author dmartinezizquierdo
63
 *
64
 */
65
public class DefaultRasterSet extends AbstractIndexedVisitable implements RasterSet, Observer {
66

    
67
    private DefaultRasterStore store;
68
    protected RasterQuery query;
69
    protected Buffer buffer;
70

    
71
    /**
72
     * Creates a RasterSet with the raster filtered by the query
73
     * 
74
     * @param store
75
     * @param query
76
     * @throws DataException
77
     */
78
    public DefaultRasterSet(RasterStore store, RasterQuery query) throws DataException {
79

    
80
        this.store = (DefaultRasterStore) store;
81
        this.query = query;
82
        RasterStoreProvider provider = this.store.getProvider();
83

    
84
        try {
85
            buffer = provider.createBuffer(query);
86
            // Filter buffer by raster query
87
            if (query != null) {
88
                if (query.getClip() != null) {
89
                    buffer = buffer.clip(query.getClip());
90
                }
91
            }
92
        } catch (BufferException e) {
93
            throw new RasterSetInitializeException(e);
94
        }
95

    
96
        this.store.addObserver(this);
97
    }
98

    
99
    @Override
100
    public void filter(FilterList filterList) {
101
        this.buffer.filter(filterList);
102

    
103
    }
104

    
105
    @Override
106
    public int getBandCount() {
107
        return this.buffer.getBandCount();
108
    }
109

    
110
    @Override
111
    public Band[] getBands() {
112
        return this.buffer.getBands();
113
    }
114

    
115
    @Override
116
    public int getColumns() {
117
        return this.buffer.getColumns();
118
    }
119

    
120
    @Override
121
    public int getRows() {
122
        return this.buffer.getRows();
123
    }
124

    
125
    @Override
126
    public Envelope getEnvelope() {
127
        return this.buffer.getEnvelope();
128
    }
129

    
130
    @Override
131
    public IProjection getProjection() {
132
        return this.buffer.getProjection();
133
    }
134

    
135
    @Override
136
    public boolean isInside(int cellX, int cellY) {
137
        return this.buffer.isInside(cellX, cellY);
138
    }
139

    
140
    @Override
141
    public boolean isInside(Point point) {
142
        return this.buffer.isInside(point);
143
    }
144

    
145
    @Override
146
    public void addBand(Band band) {
147
        this.buffer.addBand(band);
148
    }
149

    
150
    @Override
151
    public void setBand(int pos, Band band) throws BandException {
152
        this.buffer.setBand(pos, band);
153
    }
154

    
155
    @Override
156
    public void removeBand(int pos) {
157
        this.buffer.removeBand(pos);
158
    }
159

    
160
    @Override
161
    public Band getBand(int pos) {
162
        return this.buffer.getBand(pos);
163
    }
164

    
165
    @Override
166
    public BandByte getBandByte(int pos) {
167
        return this.buffer.getBandByte(pos);
168
    }
169

    
170
    @Override
171
    public BandShort getBandShort(int pos) {
172
        return this.buffer.getBandShort(pos);
173
    }
174

    
175
    @Override
176
    public BandInt getBandInt(int pos) {
177
        return this.buffer.getBandInt(pos);
178
    }
179

    
180
    @Override
181
    public BandFloat getBandFloat(int pos) {
182
        return this.buffer.getBandFloat(pos);
183
    }
184

    
185
    @Override
186
    public BandDouble getBandDouble(int pos) {
187
        return this.buffer.getBandDouble(pos);
188
    }
189

    
190
    @Override
191
    public void switchBands(int[] positions) {
192
        this.buffer.switchBands(positions);
193
    }
194

    
195
    @Override
196
    public void switchBands(int pos1, int pos2) {
197
        this.buffer.switchBands(pos1, pos2);
198
    }
199

    
200
    @Override
201
    public Buffer createInterpolated(int rows, int columns, int interpolationMode,
202
        SimpleTaskStatus status) throws LocatorException, BufferException {
203
        return this.buffer.createInterpolated(rows, columns, interpolationMode, status);
204
    }
205

    
206
    @Override
207
    public Buffer convert(ICoordTrans ct, SimpleTaskStatus status) throws BufferException {
208
        return this.buffer.convert(ct, status);
209
    }
210

    
211
    @Override
212
    public int[] getBandTypes() {
213
        return this.buffer.getBandTypes();
214
    }
215

    
216
    @Override
217
    public NoData[] getBandNoData() {
218
        return this.buffer.getBandNoData();
219
    }
220

    
221
    @Override
222
    public Buffer clip(Envelope envelope) throws BufferException {
223
        return this.buffer.clip(envelope);
224
    }
225

    
226
    @Override
227
    public double getPixelSizeX() {
228
        return this.buffer.getPixelSizeX();
229
    }
230

    
231
    @Override
232
    public double getPixelSizeY() {
233
        return this.buffer.getPixelSizeY();
234
    }
235

    
236
    @Override
237
    public Statistics getStatistics(SimpleTaskStatus status) {
238
        return this.buffer.getStatistics(status);
239
    }
240

    
241
    @Override
242
    public void addObserver(Observer o) {
243
        this.buffer.addObserver(o);
244
    }
245

    
246
    @Override
247
    public void deleteObserver(Observer o) {
248
        this.buffer.deleteObserver(o);
249
    }
250

    
251
    @Override
252
    public void deleteObservers() {
253
        this.buffer.deleteObservers();
254
    }
255

    
256
    @Override
257
    public Iterator<Band> iterator() {
258
        return this.buffer.iterator();
259
    }
260

    
261
    @Override
262
    public boolean isFromStore(DataStore store) {
263
        return this.store.equals(store);
264
    }
265

    
266
    @Override
267
    public void dispose() {
268
        this.store.deleteObserver(this);
269

    
270
        this.store = null;
271

    
272
        this.query = null;
273
        this.buffer = null;
274
    }
275

    
276
    @Override
277
    public void update(Observable observable, Object notification) {
278
        // Do nothing
279
    }
280

    
281
    @Override
282
    protected void doAccept(Visitor visitor, long firstValueIndex) throws VisitCanceledException,
283
        BaseException {
284

    
285
        DefaultRasterKernel kernel = new DefaultRasterKernel(this.buffer);
286
        for (int row = 0; row < this.buffer.getRows(); row++) {
287
            for (int column = 0; column < this.buffer.getColumns(); column++) {
288
                kernel.set(row, column);
289
                visitor.visit(kernel);
290
            }
291
        }
292
    }
293

    
294
}