Statistics
| Revision:

root / trunk / libraries / libRaster / src-test / org / gvsig / raster / buffer / TDSDoubleAdjustToExtentBufferGdal.java @ 11074

History | View | Annotate | Download (5.96 KB)

1 11074 nacho
/* 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.buffer.BufferFactory;
25
import org.gvsig.raster.dataset.IBuffer;
26
import org.gvsig.raster.dataset.NotSupportedExtensionException;
27
import org.gvsig.raster.dataset.RasterDataset;
28
import org.gvsig.raster.dataset.RasterDriverException;
29
import org.gvsig.raster.dataset.io.EcwDriver;
30
import org.gvsig.raster.dataset.io.GdalDriver;
31
32
/**
33
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
34
 * para un raster leido con Gdal con coordenadas pixel.
35
 *
36
 * Lee el raster completo y comprueba que los datos leidos sean correctos
37
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
38
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
39
 * leidos sean correctos.
40
 *
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 *
43
 */
44
public class TDSDoubleAdjustToExtentBufferGdal extends TestCase{
45
46
        private String baseDir = "./test-images/";
47
        private String path = baseDir + "miniRaster25x24.tif";
48
        private RasterDataset f = null;
49
        private BufferFactory ds = null;
50
51
        public void start(){
52
                this.setUp();
53
                this.testStack();
54
        }
55
56
        public void setUp() {
57
                System.err.println("TDSDoubleAdjustToExtentBufferGdal running...");
58
                //System.out.println("TestDataSource (Real Coord) Adjust To Extent With Buffer [Gdal] running...");
59
        }
60
61
        static{
62
                RasterLibrary.wakeUp();
63
        }
64
65
        public void testStack(){
66
                int[] drawableBands = {0, 1, 2};
67
                try {
68
                        f = RasterDataset.open(null, path);
69
                } catch (NotSupportedExtensionException e) {
70
                        e.printStackTrace();
71
                        return;
72
                } catch (RasterDriverException e) {
73
                        e.printStackTrace();
74
                        return;
75
                }
76
                ds = new BufferFactory(f);
77
                ds.addDrawableBands(drawableBands);
78
                ds.setAreaOfInterest(645817.0, 4923851.0, 645853.0, 4923815.0, 10, 10, true);
79
                //print();
80
                dataTest1();
81
82
                ds.setAreaOfInterest(645826.9, 4923844.0, 645838.3, 4923833.3, 2, 2, true);
83
                dataTest2();
84
                //print();
85
        }
86
87
        private void dataTest2(){
88
                IBuffer raster = ds.getRasterBuf();
89
                //Upper Left
90
                assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 24);
91
                assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 37);
92
                assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 7);
93
                //Upper Right
94
                assertEquals((int)(raster.getElemByte(0, 1, 0) & 0xff), 70);
95
                assertEquals((int)(raster.getElemByte(0, 1, 1) & 0xff), 78);
96
                assertEquals((int)(raster.getElemByte(0, 1, 2) & 0xff), 55);
97
                //Lower Left
98
                assertEquals((int)(raster.getElemByte(1, 0, 0) & 0xff), 97);
99
                assertEquals((int)(raster.getElemByte(1, 0, 1) & 0xff), 115);
100
                assertEquals((int)(raster.getElemByte(1, 0, 2) & 0xff), 73);
101
                //Lower Right
102
                assertEquals((int)(raster.getElemByte(1, 1, 0) & 0xff), 65);
103
                assertEquals((int)(raster.getElemByte(1, 1, 1) & 0xff), 75);
104
                assertEquals((int)(raster.getElemByte(1, 1, 2) & 0xff), 51);
105
        }
106
107
        private void dataTest1(){
108
                IBuffer raster = ds.getRasterBuf();
109
                //Upper Left
110
                assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 97);
111
                assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 101);
112
                assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 68);
113
                //Upper Right
114
                assertEquals((int)(raster.getElemByte(0, 9, 0) & 0xff), 58);
115
                assertEquals((int)(raster.getElemByte(0, 9, 1) & 0xff), 85);
116
                assertEquals((int)(raster.getElemByte(0, 9, 2) & 0xff), 42);
117
                //Lower Left
118
                assertEquals((int)(raster.getElemByte(9, 0, 0) & 0xff), 164);
119
                assertEquals((int)(raster.getElemByte(9, 0, 1) & 0xff), 158);
120
                assertEquals((int)(raster.getElemByte(9, 0, 2) & 0xff), 144);
121
                //Lower Right
122
                assertEquals((int)(raster.getElemByte(9, 9, 0) & 0xff), 135);
123
                assertEquals((int)(raster.getElemByte(9, 9, 1) & 0xff), 126);
124
                assertEquals((int)(raster.getElemByte(9, 9, 2) & 0xff), 127);
125
126
                assertEquals((int)(raster.getElemByte(6, 6, 0) & 0xff), 120);
127
                assertEquals((int)(raster.getElemByte(6, 6, 1) & 0xff), 127);
128
                assertEquals((int)(raster.getElemByte(6, 6, 2) & 0xff), 96);
129
130
                assertEquals((int)(raster.getElemByte(2, 3, 0) & 0xff), 24);
131
                assertEquals((int)(raster.getElemByte(2, 3, 1) & 0xff), 37);
132
                assertEquals((int)(raster.getElemByte(2, 3, 2) & 0xff), 7);
133
134
                assertEquals((int)(raster.getElemByte(5, 4, 0) & 0xff), 88);
135
                assertEquals((int)(raster.getElemByte(5, 4, 1) & 0xff), 103);
136
                assertEquals((int)(raster.getElemByte(5, 4, 2) & 0xff), 82);
137
138
                assertEquals((int)(raster.getElemByte(9, 2, 0) & 0xff), 157);
139
                assertEquals((int)(raster.getElemByte(9, 2, 1) & 0xff), 143);
140
                assertEquals((int)(raster.getElemByte(9, 2, 2) & 0xff), 130);
141
142
                assertEquals((int)(raster.getElemByte(7, 8, 0) & 0xff), 222);
143
                assertEquals((int)(raster.getElemByte(7, 8, 1) & 0xff), 222);
144
                assertEquals((int)(raster.getElemByte(7, 8, 2) & 0xff), 220);
145
        }
146
147
        /**
148
         * Imprime todos los pixels de la fuente de datos en RGB
149
         */
150
        private void print(){
151
                IBuffer raster = ds.getRasterBuf();
152
                for(int line = 0; line < raster.getHeight(); line++){
153
                        for(int col = 0; col < raster.getWidth(); col++)
154
                                System.out.print("(" + (int)(raster.getElemByte(line, col, 0) & 0xff) + " " + (int)(raster.getElemByte(line, col, 1) & 0xff) + " " + (int)(raster.getElemByte(line, col, 2) & 0xff) + ")");
155
                        System.out.println();
156
                }
157
        }
158
159
}