Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / buffer / TestAdjustToExtent.java @ 21615

History | View | Annotate | Download (3.4 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.buffer;
20

    
21
import junit.framework.TestCase;
22

    
23
import org.gvsig.raster.RasterLibrary;
24
import org.gvsig.raster.dataset.IBuffer;
25
import org.gvsig.raster.dataset.InvalidSetViewException;
26
import org.gvsig.raster.dataset.MultiRasterDataset;
27
import org.gvsig.raster.dataset.NotSupportedExtensionException;
28
import org.gvsig.raster.dataset.io.RasterDriverException;
29

    
30
/**
31
 * Prueba del acceso a datos usando el flag setAdjustToExtent a true. Esto consigue que 
32
 * no se ajuste la petici?n a los margenes del raster sino que se dibuje dentro y el resto 
33
 * se rellene con valores NoData.
34
 * 
35
 * @author Nacho Brodin (nachobrodin@gmail.com)
36
 *
37
 */
38
public class TestAdjustToExtent extends TestCase{
39

    
40
        private String baseDir = "./test-images/";
41
        private String path = baseDir + "miniRaster25x24.tif";
42
        private MultiRasterDataset f = null;        
43
        private BufferFactory ds = null;
44
        
45
        public void start(){
46
                this.setUp();
47
                this.testStack();
48
        }
49
        
50
        public void setUp() {
51
                System.err.println("TestAdjustToExtent running...");
52
        }
53
        
54
        static{
55
                RasterLibrary.wakeUp();
56
        }
57
        
58
        public void testStack(){
59
                int[] drawableBands = {0, 1, 2};
60
                try {
61
                        f = MultiRasterDataset.open(null, path);
62
                } catch (NotSupportedExtensionException e) {
63
                        e.printStackTrace();
64
                        return;
65
                } catch (RasterDriverException e) {
66
                        e.printStackTrace();
67
                        return;
68
                }
69
                ds = new BufferFactory(f);
70
                ds.setDrawableBands(drawableBands);
71
                try {
72
                        ds.setAdjustToExtent(false);
73
                        ds.setAreaOfInterest(645800.0, 4923870.0, 645830.0, 4923820, 10, 10); //Inferior derecha
74
                        //ds.setAreaOfInterest(645830.0, 4923870.0, 645880.0, 4923820, 10, 10); //Inferior izquierda
75
                        
76
                } catch (InvalidSetViewException e) {
77
                        e.printStackTrace();
78
                } catch (InterruptedException e) {
79
                        e.printStackTrace();
80
                } catch (RasterDriverException e) {
81
                        e.printStackTrace();
82
                        return;
83
                }
84
                //print();
85
                dataTest1();
86
                
87
        }
88
                
89
        private void dataTest1(){
90
                IBuffer raster = ds.getRasterBuf();
91
                //Upper Left
92
                assertEquals((int)(raster.getElemByte(4, 7, 0) & 0xff), 97);
93
                assertEquals((int)(raster.getElemByte(4, 7, 1) & 0xff), 101);
94
                assertEquals((int)(raster.getElemByte(4, 7, 2) & 0xff), 68);
95
        }
96
        
97
        /**
98
         * Imprime todos los pixels de la fuente de datos en RGB
99
         */
100
        /*private void print(){
101
                IBuffer raster = ds.getRasterBuf();
102
                for(int line = 0; line < raster.getHeight(); line++){
103
                        for(int col = 0; col < raster.getWidth(); col++)
104
                                System.out.print("(" + (int)(raster.getElemByte(line, col, 0) & 0xff) + " " + (int)(raster.getElemByte(line, col, 1) & 0xff) + " " + (int)(raster.getElemByte(line, col, 2) & 0xff) + ")");
105
                        System.out.println();
106
                }
107
        }*/
108

    
109
}