Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / impl / rocache / TestReplicateBand.java @ 1965

History | View | Annotate | Download (2.21 KB)

1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

    
3
import java.io.IOException;
4

    
5
import junit.framework.TestCase;
6

    
7
import org.gvsig.jgdal.GdalException;
8
import org.gvsig.raster.cache.buffer.Band;
9
import org.gvsig.raster.cache.buffer.Buffer;
10
import org.gvsig.raster.cache.buffer.BufferDataSource;
11
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl;
12
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
14

    
15
/** 
16
 * This test insert one band at the end of the layer. The data of this new band is a copy 
17
 * of the band in position zero. Finally data of band zero and band three are compared
18
 * checking if both have the same values. 
19
 *  
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestReplicateBand extends TestCase {
23
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
        private String rasterOut = "/tmp/out-replicateBands.tif";
25
        
26
        public void start() {
27
                this.setUp();
28
                this.testStack();
29
        }
30

    
31
        public void setUp() {
32
                System.err.println("ROCache TestReplicateBand running...");
33
        }
34
        
35
        public void testStack() {
36
                long t1 = System.currentTimeMillis();
37
                GdalRead input1 = null;
38
                GdalWrite out = null;
39
                try {
40
                                                
41
                        //Read input data
42
                        input1 = new GdalRead(rasterIn);
43
                        BufferDataSource ds = null;
44
                        try {
45
                                ds = new BufferDataSourceImpl(rasterIn);
46
                        } catch (IOException e) {
47
                                e.printStackTrace();
48
                        }
49
                        Buffer buf = new RasterReadOnlyBuffer(ds);
50
                                                
51
                        buf.replicateBand(0, 3);
52
                        
53
                        //Write output file 
54
                        out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
55
                        out.writeBands(buf.getBands());
56
                        out.close();        
57
                        
58
                        Band band1 = buf.getBand(0);
59
                        Band band2 = buf.getBand(3);
60
                        for (int i = 0; i < band1.getHeight(); i++) {
61
                                for (int j = 0; j < band1.getWidth(); j++) {
62
                                        byte b1 = band1.getElemByte(i, j);
63
                                        byte b2 = band2.getElemByte(i, j);
64
                                        assertEquals(b1, b2);
65
                                }
66
                        }
67
                        
68
                        buf.free();
69
                } catch (GdalException e) {
70
                        e.printStackTrace();
71
                } catch (IOException e) {
72
                        e.printStackTrace();
73
                }
74
                long t2 = System.currentTimeMillis();
75
                System.out.println("Tiempo ROCache TestReplicateBand: " + (t2 - t1) + " milisegundos");
76
        }
77
        
78
}