Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / buffer / DefaultRasterQuery.java @ 1057

History | View | Annotate | Download (14.3 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.impl.buffer;
23

    
24
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
25
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
26
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
27
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
28
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
29
import org.gvsig.raster.cache.tile.TileCacheLibrary;
30
import org.gvsig.raster.cache.tile.provider.CacheStruct;
31
import org.gvsig.raster.cache.tile.provider.TileListener;
32
import org.gvsig.timesupport.Time;
33
import org.gvsig.tools.persistence.PersistentState;
34
import org.gvsig.tools.persistence.exception.PersistenceException;
35
import org.gvsig.tools.task.Cancellable;
36
import org.gvsig.tools.task.TaskStatus;
37

    
38
/**
39
 * Default implementation for RasterQuery
40
 * 
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public class DefaultRasterQuery implements RasterQuery {
44
        public static final int  TYPE_ENTIRE                = 0;
45
        public static final int  TYPE_COORDS                = 1;
46
        public static final int  TYPE_COORDS_SIZE           = 2;
47
        public static final int  TYPE_PX                    = 3;
48
        public static final int  TYPE_PX_SIZE               = 4;
49
        public static final int  TYPE_COORDS_SIZE_TILED     = 5;
50
        public static final int  TYPE_ONE_TILE              = 6;
51
        
52
        private int              type                       = 0;
53
        
54
        private double           x                          = 0;
55
        private double           y                          = 0;
56
        private double           w                          = 0;
57
        private double           h                          = 0;
58
        
59
        private int              pixelX                     = 0;
60
        private int              pixelY                     = 0;
61
        private int              pixelW                     = 0;
62
        private int              pixelH                     = 0;
63
        
64
        private Extent           bbox                       = null;
65
        
66
        private int              bufWidth                   = 0;
67
        private int              bufHeight                  = 0;
68
        
69
        private boolean          adjustToExtent             = true;
70
        private int[]            drawableBands              = new int[]{0};
71
        private boolean          readOnly                   = false;
72
        private boolean          memoryBuffer               = false;
73
        private boolean          storeLastBuffer            = false;
74
        private Time             time                       = null;
75
        
76
        private int              resolutionLevel            = -1;
77
        
78
        /**
79
         * Activa o desactiva el supersampleo en la carga del buffer.
80
         */
81
        private boolean                         supersamplingLoadingBuffer = true;
82
        /**
83
         * Valor NoData con el que se rellenan las celdas cuando adjustToExtent es false
84
         */
85
        private NoData           noDataValueToFill          = null;
86
        
87
        private int              frameWidth                 = 0;
88
        private TileListener     listener                   = null;
89
        private int              alphaBandNumber            = -1;
90
        private int              tileRow                    = 0;
91
        private int              tileCol                    = 0;
92
        private CacheStruct      cacheStruct                = null;   
93
        private TaskStatus       taskStatus                 = null;
94
        
95
        //Parameters only for providers
96
        private BandList         bandList                   = null;
97
        private Buffer           buffer                     = null;
98
        
99
        private Cancellable      cancel                     = null;
100
        
101
        /*
102
         * (non-Javadoc)
103
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setAreaOfInterest(double, double, double, double)
104
         */
105
        public void setAreaOfInterest(double x, double y, double w, double h) {
106
                this.x = x;
107
                this.y = y;
108
                this.w = w;
109
                this.h = h;
110
                this.type = TYPE_COORDS;
111
        }
112
        
113
        /*
114
         * (non-Javadoc)
115
         * @see org.gvsig.fmap.dal.coverage.store.RasterQuery#setAreaOfInterest(org.gvsig.fmap.dal.coverage.datastruct.Extent)
116
         */
117
        public void setAreaOfInterest(Extent bbox) {
118
                this.bbox = bbox;
119
                this.type = TYPE_COORDS;
120
        }
121
        
122
        /*
123
         * (non-Javadoc)
124
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setAreaOfInterest(double, double, double, double, int, int)
125
         */
126
        public void setAreaOfInterest(Extent bbox, int bufWidth, int bufHeight) {
127
                this.bbox = bbox;
128
                this.bufWidth = bufWidth;
129
                this.bufHeight = bufHeight;
130
                this.type = TYPE_COORDS_SIZE;
131
        }
132
        
133
        /*
134
         * (non-Javadoc)
135
         * @see org.gvsig.fmap.dal.coverage.store.RasterQuery#setAreaOfInterest(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.grid.render.TileListener, int)
136
         */
137
        public void setAreaOfInterest(Extent bbox, 
138
                        int bufWidth, int bufHeight, TileListener listener) {
139
                this.bbox = bbox;;
140
                this.bufWidth = bufWidth;
141
                this.bufHeight = bufHeight;
142
                this.type = TYPE_COORDS_SIZE_TILED;
143
                this.listener = listener;
144
        }
145
        
146
        /*
147
         * (non-Javadoc)
148
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setAreaOfInterest(int, int, int, int)
149
         */
150
        public void setAreaOfInterest(int x, int y, int w, int h) {
151
                this.pixelX = x;
152
                this.pixelY = y;
153
                this.pixelW = w;
154
                this.pixelH = h;
155
                this.type = TYPE_PX;
156
        }
157
        
158
        /*
159
         * (non-Javadoc)
160
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setAreaOfInterest()
161
         */
162
        public void setAreaOfInterest() {
163
                this.type = TYPE_ENTIRE;
164
        }
165
        
166
        /*
167
         * (non-Javadoc)
168
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setAreaOfInterest(int, int, int, int, int, int)
169
         */
170
        public void setAreaOfInterest(int x, int y, int w, int h, int bufWidth,
171
                        int bufHeight) {
172
                this.pixelX = x;
173
                this.pixelY = y;
174
                this.pixelW = w;
175
                this.pixelH = h;
176
                this.bufWidth = bufWidth;
177
                this.bufHeight = bufHeight;
178
                this.type = TYPE_PX_SIZE;
179
        }
180
        
181
        /*
182
         * (non-Javadoc)
183
         * @see org.gvsig.fmap.dal.coverage.store.RasterQuery#setTileParameters(int, int, int, org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.raster.cache.tile.provider.CacheStruct)
184
         */
185
        public void setTileParameters(int level, int tileCol, int tileRow, Extent bbox, CacheStruct cacheStruct) {
186
                this.type = TYPE_ONE_TILE;
187
                this.bbox = bbox;
188
                this.resolutionLevel = level;
189
                this.tileRow = tileRow;
190
                this.tileCol = tileCol;
191
                int[] size = null;
192
                if(cacheStruct != null) {
193
                        this.cacheStruct = cacheStruct;
194
                        size = cacheStruct.getTileSizeByLevel(level);
195
                } else {
196
                        size = new int[]{TileCacheLibrary.DEFAULT_TILEWIDTH, TileCacheLibrary.DEFAULT_TILEHEIGHT};
197
                }
198
                this.bufWidth = size[0];
199
                this.bufHeight = size[1];
200
        }
201
        
202
        /*
203
         * (non-Javadoc)
204
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#storeLastBuffer(boolean)
205
         */
206
        public void storeLastBuffer(boolean store) {
207
                this.storeLastBuffer = store;
208
        }
209
        
210
        /**
211
         * The user can told if the buffer will be stored or not in the RasterDatasource.
212
         * @return store
213
         */
214
        public boolean isStoredLastBuffer() {
215
                return storeLastBuffer;
216
        }
217

    
218
        /*
219
         * (non-Javadoc)
220
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setAdjustToExtent(boolean)
221
         */
222
        public void setAdjustToExtent(boolean adjustToExtent) {
223
                this.adjustToExtent = adjustToExtent;
224
        }
225
        
226
        /*
227
         * (non-Javadoc)
228
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#isAdjustToExtent()
229
         */
230
        public boolean isAdjustToExtent() {
231
                return adjustToExtent;
232
        }
233
        
234
        /*
235
         * (non-Javadoc)
236
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#getDrawableBands()
237
         */
238
        public int[] getDrawableBands() {
239
                return drawableBands;
240
        }
241

    
242
        /*
243
         * (non-Javadoc)
244
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setAllDrawableBands()
245
         */
246
        public void setAllDrawableBands() {
247
                this.drawableBands = null;
248
        }
249

    
250
        /*
251
         * (non-Javadoc)
252
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setDrawableBands(int[])
253
         */
254
        public void setDrawableBands(int[] drawableBands) {
255
                this.drawableBands = drawableBands;
256
        }
257

    
258
        /*
259
         * (non-Javadoc)
260
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setReadOnly(boolean)
261
         */
262
        public void setReadOnly(boolean readOnly) {
263
                this.readOnly = readOnly;
264
        }
265
        
266
        /*
267
         * (non-Javadoc)
268
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#isSupersamplingLoadingBuffer()
269
         */
270
        public boolean isSupersamplingLoadingBuffer() {
271
                return supersamplingLoadingBuffer;
272
        }
273

    
274
        /*
275
         * (non-Javadoc)
276
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setSupersamplingLoadingBuffer(boolean)
277
         */
278
        public void setSupersamplingLoadingBuffer(boolean supersamplingLoadingBuffer) {
279
                this.supersamplingLoadingBuffer = supersamplingLoadingBuffer;
280
        }
281
        
282
        /*
283
         * (non-Javadoc)
284
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setMemoryBuffer(boolean)
285
         */
286
        public void setMemoryBuffer(boolean memoryBuffer) {
287
                this.memoryBuffer = memoryBuffer;
288
        }
289
        
290
        /**
291
         * Obtiene el flag que dice si la carga del siguiente buffer es en memoria
292
         * @return memory true si la siguiente carga de buffer se hace en memoria y false se deja decidir al dataset 
293
         * el tipo de buffer
294
         */
295
        public boolean isMemoryBuffer() {
296
                return memoryBuffer;
297
        }
298
        
299
        /*
300
         * (non-Javadoc)
301
         * @see org.gvsig.fmap.dal.coverage.buffer.RasterQuery#setNoDataToFill(double)
302
         */
303
        public void setNoDataToFill(NoData noData) {
304
                this.noDataValueToFill = noData;
305
        }
306
        
307
        /*
308
         * (non-Javadoc)
309
         * @see org.gvsig.fmap.dal.coverage.store.RasterQuery#setAlphaBand(int)
310
         */
311
        public void setAlphaBand(int bandNumber) {
312
                this.alphaBandNumber = bandNumber;
313
        }
314
        
315
        /*
316
         * (non-Javadoc)
317
         * @see org.gvsig.fmap.dal.coverage.store.RasterQuery#setFrameWidth(int)
318
         */
319
        public void setFrameWidth(int n) {
320
                this.frameWidth = n;
321
        }
322
        
323
        public int getAlphaBandNumber() {
324
                return alphaBandNumber;
325
        }
326
        
327
        public NoData getNoDataValueToFill() {
328
                return this.noDataValueToFill;
329
        }
330

    
331
        public int getType() {
332
                return type;
333
        }
334
        
335
        public void setType(int type) {
336
                this.type = type;
337
        }
338

    
339
        public double getX() {
340
                return x;
341
        }
342

    
343
        public double getY() {
344
                return y;
345
        }
346

    
347
        public double getW() {
348
                return w;
349
        }
350

    
351
        public double getH() {
352
                return h;
353
        }
354

    
355
        public int getPixelX() {
356
                return pixelX;
357
        }
358

    
359
        public int getPixelY() {
360
                return pixelY;
361
        }
362

    
363
        public int getPixelW() {
364
                return pixelW;
365
        }
366

    
367
        public int getPixelH() {
368
                return pixelH;
369
        }
370
        
371
        public void setPixelX(int x) {
372
                pixelX = x;
373
        }
374

    
375
        public void setPixelY(int y) {
376
                pixelY = y;
377
        }
378

    
379
        public void setPixelW(int w) {
380
                pixelW = w;
381
        }
382

    
383
        public void setPixelH(int h) {
384
                pixelH = h;
385
        }
386

    
387
        public Extent getBBox() {
388
                return bbox;
389
        }
390
        
391
        public void setBBox(Extent bbox) {
392
                this.bbox = bbox;
393
        }
394

    
395
        public int getBufWidth() {
396
                return bufWidth;
397
        }
398

    
399
        public int getBufHeight() {
400
                return bufHeight;
401
        }
402
        
403
        public void setBufHeight(int h) {
404
                bufHeight = h;
405
        }
406
        
407
        public void setBufWidth(int w) {
408
                bufWidth = w;
409
        }
410

    
411
        public boolean isReadOnly() {
412
                return readOnly;
413
        }
414
        
415
        public int getFrameWidth() {
416
                return frameWidth;
417
        }
418

    
419
        public TileListener getTileListener() {
420
                return listener;
421
        }
422
        
423
        public void setTileListener(TileListener listener) {
424
                this.listener = listener;
425
        }
426
        
427
        /*
428
         * (non-Javadoc)
429
         * @see org.gvsig.fmap.dal.coverage.store.RasterQuery#getTime()
430
         */
431
        public Time getTime() {
432
                return time;
433
        }
434

    
435
        /*
436
         * (non-Javadoc)
437
         * @see org.gvsig.fmap.dal.coverage.store.RasterQuery#setTime(org.gvsig.timesupport.Time)
438
         */
439
        public void setTime(Time time) {
440
                this.time = time;
441
        }
442
        
443
        public int getTileRow() {
444
                return tileRow;
445
        }
446

    
447
        public int getTileCol() {
448
                return tileCol;
449
        }
450

    
451
        public CacheStruct getCacheStruct() {
452
                return cacheStruct;
453
        }
454
        
455
        public void setCacheStruct(CacheStruct cacheStruct) {
456
                this.cacheStruct = cacheStruct;
457
        }
458

    
459
        public int getResolutionLevel() {
460
                return resolutionLevel;
461
        }
462
        
463
        /*
464
         * (non-Javadoc)
465
         * @see org.gvsig.fmap.dal.coverage.store.RasterQuery#setTaskStatus(org.gvsig.tools.task.TaskStatus)
466
         */
467
        public void setTaskStatus(TaskStatus taskStatus) {
468
                this.taskStatus = taskStatus;
469
        }
470
        
471
        /**
472
         * Gets the task status
473
         */
474
        public TaskStatus getTaskStatus() {
475
                return taskStatus;
476
        }
477
        
478
        //****************************************************
479
        //*********Parameters only for providers**************
480
        //****************************************************
481
        
482
        public BandList getBandList() {
483
                return bandList;
484
        }
485

    
486
        public void setBandList(BandList bandList) {
487
                this.bandList = bandList;
488
        }
489

    
490
        public Buffer getBuffer() {
491
                return buffer;
492
        }
493

    
494
        public void setBuffer(Buffer buffer) {
495
                this.buffer = buffer;
496
        }
497
        
498
        //****************************************************
499
        //*********Implementing DataQuery methods*************
500
        //****************************************************
501
        
502
        /*
503
         * (non-Javadoc)
504
         * @see org.gvsig.fmap.dal.DataQuery#getQueryParameter(java.lang.String)
505
         */
506
        public Object getQueryParameter(String name) {
507
                // TODO Auto-generated method stub
508
                return null;
509
        }
510

    
511
        /*
512
         * (non-Javadoc)
513
         * @see org.gvsig.fmap.dal.DataQuery#getScale()
514
         */
515
        public double getScale() {
516
                // TODO Auto-generated method stub
517
                return 0;
518
        }
519

    
520
        /*
521
         * (non-Javadoc)
522
         * @see org.gvsig.fmap.dal.DataQuery#setQueryParameter(java.lang.String, java.lang.Object)
523
         */
524
        public void setQueryParameter(String name, Object value) {
525
                // TODO Auto-generated method stub
526
                
527
        }
528

    
529
        /*
530
         * (non-Javadoc)
531
         * @see org.gvsig.fmap.dal.DataQuery#setScale(double)
532
         */
533
        public void setScale(double scale) {
534
                // TODO Auto-generated method stub
535
                
536
        }
537
        
538
        //****************************************************
539
        //*********Implementing Persistent methods************
540
        //****************************************************
541

    
542
        /*
543
         * (non-Javadoc)
544
         * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
545
         */
546
        public void loadFromState(PersistentState state)
547
                        throws PersistenceException {
548
                // TODO Auto-generated method stub
549
                
550
        }
551

    
552
        /*
553
         * (non-Javadoc)
554
         * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
555
         */
556
        public void saveToState(PersistentState state) throws PersistenceException {
557
                // TODO Auto-generated method stub
558
                
559
        }
560
        
561
        public void setCancel(Cancellable cancel) {
562
                this.cancel = cancel;
563
        }
564
        
565
        public Cancellable getCancel() {
566
                return cancel;
567
        }
568
}