gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / memory / TestCreateBand.java @ 1965
History | View | Annotate | Download (2.5 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.memory; |
---|---|
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.exception.OperationNotSupportedException; |
11 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
13 |
|
14 |
/**
|
15 |
* This test add a band in a raster of 3 bands. As a result of this test a raster
|
16 |
* of four bands is created and saved in the hard disk. The value of additional band
|
17 |
* is zero in all its elements. Finally it gets the band added and compare each values
|
18 |
* with 0.
|
19 |
*
|
20 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
21 |
*/
|
22 |
public class TestCreateBand extends TestCase { |
23 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
24 |
|
25 |
public void start() { |
26 |
this.setUp();
|
27 |
this.testStack();
|
28 |
} |
29 |
|
30 |
public void setUp() { |
31 |
System.err.println("MemoryBuffer TestCreateBand running..."); |
32 |
} |
33 |
|
34 |
public void testStack() { |
35 |
long t1 = System.currentTimeMillis(); |
36 |
GdalRead input = null;
|
37 |
try {
|
38 |
//Read input data
|
39 |
input = new GdalRead(rasterIn);
|
40 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
41 |
|
42 |
//Create Buffer
|
43 |
Buffer buf = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
44 |
input.getWidth(), |
45 |
input.getHeight(), |
46 |
input.getBandCount(), |
47 |
true);
|
48 |
|
49 |
//Set data to buffer
|
50 |
setLines(dataIn, buf); |
51 |
Band rb = buf.createBand((byte)100); |
52 |
|
53 |
for (int i = 0; i < rb.getHeight(); i++) { |
54 |
for (int j = 0; j < rb.getWidth(); j++) { |
55 |
byte b = rb.getElemByte(i, j);
|
56 |
assertEquals((byte)100, b); |
57 |
} |
58 |
} |
59 |
|
60 |
buf.free(); |
61 |
} catch (GdalException e) {
|
62 |
e.printStackTrace(); |
63 |
} catch (IOException e) { |
64 |
e.printStackTrace(); |
65 |
} catch (ProcessInterruptedException e) {
|
66 |
e.printStackTrace(); |
67 |
} catch (OperationNotSupportedException e) { |
68 |
e.printStackTrace(); |
69 |
} |
70 |
long t2 = System.currentTimeMillis(); |
71 |
System.out.println("Tiempo MemoryBuffer TestCreateBand: " + (t2 - t1) + " milisegundos"); |
72 |
} |
73 |
|
74 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
75 |
if(dataIn instanceof byte[][][]) { |
76 |
byte[][][] d = (byte[][][])dataIn; |
77 |
for (int iBand = 0; iBand < d.length; iBand++) { |
78 |
for (int row = 0; row < d[iBand].length; row++) { |
79 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
80 |
} |
81 |
} |
82 |
} |
83 |
} |
84 |
|
85 |
} |