Revision 8045
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
3 |
|
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.raster.cache</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>org.gvsig.raster.cache</name> |
|
8 |
<description>Cache management for raster files</description> |
|
9 |
<version>2.2.21</version> |
|
10 |
<scm> |
|
11 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21</connection> |
|
12 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21</developerConnection> |
|
13 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21</url> |
|
14 |
</scm> |
|
15 |
|
|
16 |
<repositories> |
|
17 |
<repository> |
|
18 |
<id>gvsig-public-http-repository</id> |
|
19 |
<name>gvSIG maven public HTTP repository</name> |
|
20 |
<url>http://devel.gvsig.org/m2repo/j2se</url> |
|
21 |
<releases> |
|
22 |
<enabled>true</enabled> |
|
23 |
<updatePolicy>daily</updatePolicy> |
|
24 |
<checksumPolicy>warn</checksumPolicy> |
|
25 |
</releases> |
|
26 |
<snapshots> |
|
27 |
<enabled>true</enabled> |
|
28 |
<updatePolicy>daily</updatePolicy> |
|
29 |
<checksumPolicy>warn</checksumPolicy> |
|
30 |
</snapshots> |
|
31 |
</repository> |
|
32 |
</repositories> |
|
33 |
|
|
34 |
<parent> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.desktop</artifactId> |
|
37 |
<version>2.0.205</version> |
|
38 |
</parent> |
|
39 |
|
|
40 |
<developers> |
|
41 |
<developer> |
|
42 |
<id>nbrodin</id> |
|
43 |
<name>Nacho Brodin</name> |
|
44 |
<email>nachobrodin@gmail.com</email> |
|
45 |
<roles> |
|
46 |
<role>Architect</role> |
|
47 |
<role>Developer</role> |
|
48 |
</roles> |
|
49 |
</developer> |
|
50 |
</developers> |
|
51 |
|
|
52 |
<dependencyManagement> |
|
53 |
<dependencies> |
|
54 |
|
|
55 |
|
|
56 |
<!-- |
|
57 |
Versions of child projects |
|
58 |
--> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.raster.cache.lib.api</artifactId> |
|
62 |
<version>2.2.21</version> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>org.gvsig</groupId> |
|
66 |
<artifactId>org.gvsig.raster.cache.lib.impl</artifactId> |
|
67 |
<version>2.2.21</version> |
|
68 |
</dependency> |
|
69 |
|
|
70 |
|
|
71 |
</dependencies> |
|
72 |
</dependencyManagement> |
|
73 |
|
|
74 |
|
|
75 |
<build> |
|
76 |
<plugins> |
|
77 |
<plugin> |
|
78 |
<groupId>org.apache.maven.plugins</groupId> |
|
79 |
<artifactId>maven-release-plugin</artifactId> |
|
80 |
<configuration> |
|
81 |
<tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.cache/tags/</tagBase> |
|
82 |
<goals>deploy</goals> |
|
83 |
</configuration> |
|
84 |
</plugin> |
|
85 |
<plugin> |
|
86 |
<groupId>org.apache.maven.plugins</groupId> |
|
87 |
<artifactId>maven-compiler-plugin</artifactId> |
|
88 |
<configuration> |
|
89 |
<source>1.5</source> |
|
90 |
<target>1.5</target> |
|
91 |
</configuration> |
|
92 |
</plugin> |
|
93 |
<plugin> |
|
94 |
<groupId>org.codehaus.mojo</groupId> |
|
95 |
<artifactId>animal-sniffer-maven-plugin</artifactId> |
|
96 |
<configuration> |
|
97 |
<skip>true</skip> |
|
98 |
</configuration> |
|
99 |
</plugin> |
|
100 |
</plugins> |
|
101 |
</build> |
|
102 |
<modules> |
|
103 |
<module>org.gvsig.raster.cache.lib.api</module> |
|
104 |
<module>org.gvsig.raster.cache.lib.impl</module> |
|
105 |
</modules> |
|
106 |
</project> |
|
0 | 107 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/io/TRWTIFFFullDataBuffer.java | ||
---|---|---|
1 |
package org.gvsig.raster.cache.buffer.impl.io; |
|
2 |
import java.io.IOException; |
|
3 |
|
|
4 |
import org.gvsig.jgdal.GdalException; |
|
5 |
|
|
6 |
/** |
|
7 |
* Common use of TIFFRead and TIFFWrite class for read and save full data buffers. |
|
8 |
* |
|
9 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
10 |
*/ |
|
11 |
public class TRWTIFFFullDataBuffer { |
|
12 |
|
|
13 |
private String rasterOut = "/tmp/out.tif"; |
|
14 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
15 |
//private String rasterIn = "/home/nacho/images1/MultiplesFicheros/ComunidadValenciana/p198r033_7t20010601_z31_nn10.tif"; |
|
16 |
public static void main(String[] args) { |
|
17 |
TRWTIFFFullDataBuffer t = new TRWTIFFFullDataBuffer(); |
|
18 |
t.save(); |
|
19 |
} |
|
20 |
|
|
21 |
public void save() { |
|
22 |
long t1 = System.currentTimeMillis(); |
|
23 |
|
|
24 |
GdalRead input = null; |
|
25 |
GdalWrite out = null; |
|
26 |
try { |
|
27 |
input = new GdalRead(rasterIn); |
|
28 |
Object data = input.readData(0, 0, input.getWidth(), input.getHeight()); |
|
29 |
|
|
30 |
out = new GdalWrite(rasterOut, input.getBandCount(), input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB); |
|
31 |
|
|
32 |
if(data instanceof byte[][]) { |
|
33 |
byte[][] d = (byte[][])data; |
|
34 |
out.writeByteBands(d); |
|
35 |
out.close(); |
|
36 |
} |
|
37 |
|
|
38 |
} catch (GdalException e) { |
|
39 |
e.printStackTrace(); |
|
40 |
} catch (IOException e) { |
|
41 |
e.printStackTrace(); |
|
42 |
} catch (InterruptedException e) { |
|
43 |
e.printStackTrace(); |
|
44 |
} |
|
45 |
|
|
46 |
long t2 = System.currentTimeMillis(); |
|
47 |
System.out.println("Tiempo: " + (t2 - t1) + " milisegundos"); |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
0 | 51 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestRWTiffAndCompareData.java | ||
---|---|---|
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.Buffer; |
|
9 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
|
10 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
|
11 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
|
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
13 |
|
|
14 |
/** |
|
15 |
* This test reads a Tiff from disk with the class TIFFRead and load data in |
|
16 |
* a memory buffer. Then it saves those bytes in a new out file in the same format. |
|
17 |
* Finally it compares the intput data with the output data to test if there are some |
|
18 |
* diferences. |
|
19 |
* |
|
20 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
21 |
*/ |
|
22 |
public class TestRWTiffAndCompareData extends TestCase { |
|
23 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
24 |
private String rasterOut = "/tmp/out.tif"; |
|
25 |
|
|
26 |
public void start() { |
|
27 |
this.setUp(); |
|
28 |
this.testStack(); |
|
29 |
} |
|
30 |
|
|
31 |
public void setUp() { |
|
32 |
System.err.println("MemoryBuffer TestRWTiffAndCompareData running..."); |
|
33 |
} |
|
34 |
|
|
35 |
public void testStack() { |
|
36 |
long t1 = System.currentTimeMillis(); |
|
37 |
GdalRead input = null; |
|
38 |
GdalWrite out = null; |
|
39 |
try { |
|
40 |
|
|
41 |
//Read input data |
|
42 |
input = new GdalRead(rasterIn); |
|
43 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
|
44 |
|
|
45 |
//Create Buffer |
|
46 |
Buffer buf = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
|
47 |
input.getWidth(), |
|
48 |
input.getHeight(), |
|
49 |
input.getBandCount(), |
|
50 |
true); |
|
51 |
|
|
52 |
//Set data to buffer |
|
53 |
if(dataIn instanceof byte[][][]) { |
|
54 |
byte[][][] d = (byte[][][])dataIn; |
|
55 |
for (int i = 0; i < d.length; i++) { |
|
56 |
for (int j = 0; j < d[i].length; j++) { |
|
57 |
buf.setLineInBandByte(d[i][j], j, i); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
//Write output file |
|
63 |
out = new GdalWrite(rasterOut, input.getBandCount(), input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB); |
|
64 |
out.writeBands(buf.getBands()); |
|
65 |
out.close(); |
|
66 |
|
|
67 |
//Open output file and compare |
|
68 |
GdalRead newFile = new GdalRead(rasterOut); |
|
69 |
Object dataOut = newFile.readBlock(0, 0, input.getWidth(), input.getHeight()); |
|
70 |
|
|
71 |
byte[][][] d1 = (byte[][][])dataIn; |
|
72 |
byte[][][] d2 = (byte[][][])dataOut; |
|
73 |
for (int iBand = 0; iBand < buf.getBandCount(); iBand++) { |
|
74 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
75 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
76 |
if(d1[iBand][row][col] != d2[iBand][row][col]) |
|
77 |
System.out.println("BAND:" + iBand +" ROW:" + row + " COL:" + col + " " + d1[iBand][row][col] + " " + d2[iBand][row][col]); |
|
78 |
assertEquals(d1[iBand][row][col], d2[iBand][row][col]); |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
} catch (GdalException e) { |
|
84 |
e.printStackTrace(); |
|
85 |
} catch (IOException e) { |
|
86 |
e.printStackTrace(); |
|
87 |
} catch (ProcessInterruptedException e) { |
|
88 |
e.printStackTrace(); |
|
89 |
} catch (OperationNotSupportedException e) { |
|
90 |
e.printStackTrace(); |
|
91 |
} |
|
92 |
long t2 = System.currentTimeMillis(); |
|
93 |
System.out.println("Tiempo MemoryBuffer TestRWTiffAndCompareData: " + (t2 - t1) + " milisegundos"); |
|
94 |
} |
|
95 |
|
|
96 |
} |
|
0 | 97 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestRWOneValue.java | ||
---|---|---|
1 |
package org.gvsig.raster.cache.buffer.impl.memory; |
|
2 |
|
|
3 |
import java.awt.image.DataBuffer; |
|
4 |
|
|
5 |
import junit.framework.TestCase; |
|
6 |
|
|
7 |
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl; |
|
8 |
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer; |
|
9 |
|
|
10 |
/** |
|
11 |
* Escribe y lee un n?mero en la cache |
|
12 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
13 |
*/ |
|
14 |
public class TestRWOneValue extends TestCase { |
|
15 |
|
|
16 |
public void start() { |
|
17 |
this.setUp(); |
|
18 |
this.testStack(); |
|
19 |
} |
|
20 |
|
|
21 |
public void setUp() { |
|
22 |
System.err.println("MemoryBuffer TestRWOneValue running..."); |
|
23 |
} |
|
24 |
|
|
25 |
public void testStack() { |
|
26 |
long t1 = System.currentTimeMillis(); |
|
27 |
|
|
28 |
BufferCacheManagerImpl.cacheSize = 1; |
|
29 |
BufferCacheManagerImpl.pageSize = 0.2; |
|
30 |
|
|
31 |
RasterMemoryBuffer buf = new RasterMemoryBuffer(DataBuffer.TYPE_BYTE, 2571, 1942, 3, true); |
|
32 |
|
|
33 |
for (int iBand = 0; iBand < buf.getBandCount(); iBand++) { |
|
34 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
35 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
36 |
byte n = (byte)(8 + iBand); |
|
37 |
byte m = (byte)(34 + iBand); |
|
38 |
if(row == 1001 && col == 1032) |
|
39 |
buf.setElem(row, col, iBand, n); |
|
40 |
else |
|
41 |
buf.setElem(row, col, iBand, m); |
|
42 |
} |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
for (int iBand = 0; iBand < buf.getBandCount(); iBand++) { |
|
47 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
48 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
49 |
byte n = buf.getElemByte(row, col, iBand); |
|
50 |
byte m = (byte)(34 + iBand); |
|
51 |
if(n != m) |
|
52 |
;//System.out.println(n + " " + row + "," + col); |
|
53 |
else |
|
54 |
assertEquals(n, m); |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
buf.free(); |
|
60 |
|
|
61 |
long t2 = System.currentTimeMillis(); |
|
62 |
System.out.println("Tiempo MemoryBuffer TestRWOneValue: " + (t2 - t1) + " milisegundos"); |
|
63 |
} |
|
64 |
|
|
65 |
} |
|
0 | 66 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestCreateBand.java | ||
---|---|---|
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 |
} |
|
0 | 86 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestAssignBand.java | ||
---|---|---|
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.BandNotCompatibleException; |
|
11 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
|
12 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
|
13 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
|
14 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
15 |
|
|
16 |
/** |
|
17 |
* |
|
18 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
19 |
*/ |
|
20 |
public class TestAssignBand extends TestCase { |
|
21 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
22 |
private String rasterOut = "/tmp/out-4bands.tif"; |
|
23 |
|
|
24 |
public void start() { |
|
25 |
this.setUp(); |
|
26 |
this.testStack(); |
|
27 |
} |
|
28 |
|
|
29 |
public void setUp() { |
|
30 |
System.err.println("MemoryBuffer TestAssignBand running..."); |
|
31 |
} |
|
32 |
|
|
33 |
public void testStack() { |
|
34 |
long t1 = System.currentTimeMillis(); |
|
35 |
GdalRead input1 = null; |
|
36 |
GdalRead input2 = null; |
|
37 |
GdalWrite out = null; |
|
38 |
try { |
|
39 |
//Read input data |
|
40 |
input1 = new GdalRead(rasterIn); |
|
41 |
Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight()); |
|
42 |
input2 = new GdalRead(rasterIn); |
|
43 |
Object dataIn2 = input1.readBlock(0, 0, input2.getWidth(), input2.getHeight()); |
|
44 |
|
|
45 |
//Create Buffer |
|
46 |
Buffer buf1 = new RasterMemoryBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), |
|
47 |
input1.getWidth(), |
|
48 |
input1.getHeight(), |
|
49 |
input1.getBandCount(), |
|
50 |
true); |
|
51 |
|
|
52 |
//Set data to buffer |
|
53 |
setLines(dataIn1, buf1); |
|
54 |
//Create Buffer |
|
55 |
Buffer buf2 = new RasterMemoryBuffer(input2.getRasterBufTypeFromGdalType(input2.getDataType()), |
|
56 |
input2.getWidth(), |
|
57 |
input2.getHeight(), |
|
58 |
input2.getBandCount(), |
|
59 |
true); |
|
60 |
|
|
61 |
//Set data to buffer |
|
62 |
setLines(dataIn2, buf2); |
|
63 |
|
|
64 |
Band rb = buf2.getBand(2); |
|
65 |
try { |
|
66 |
buf1.assignBand(1, rb); |
|
67 |
} catch (BandNotCompatibleException e) { |
|
68 |
e.printStackTrace(); |
|
69 |
} |
|
70 |
|
|
71 |
//Write output file |
|
72 |
out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
|
73 |
out.writeBands(buf1.getBands()); |
|
74 |
out.close(); |
|
75 |
|
|
76 |
Band band1 = buf1.getBand(1); |
|
77 |
Band band2 = buf1.getBand(3); |
|
78 |
for (int i = 0; i < band1.getHeight(); i++) { |
|
79 |
for (int j = 0; j < band1.getWidth(); j++) { |
|
80 |
byte b1 = band1.getElemByte(i, j); |
|
81 |
byte b2 = band2.getElemByte(i, j); |
|
82 |
assertEquals(b1, b2); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
buf1.free(); |
|
87 |
buf2.free(); |
|
88 |
} catch (GdalException e) { |
|
89 |
e.printStackTrace(); |
|
90 |
} catch (IOException e) { |
|
91 |
e.printStackTrace(); |
|
92 |
} catch (ProcessInterruptedException e) { |
|
93 |
e.printStackTrace(); |
|
94 |
} catch (OperationNotSupportedException e) { |
|
95 |
e.printStackTrace(); |
|
96 |
} |
|
97 |
long t2 = System.currentTimeMillis(); |
|
98 |
System.out.println("Tiempo MemoryBuffer TestAssignBand: " + (t2 - t1) + " milisegundos"); |
|
99 |
} |
|
100 |
|
|
101 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
|
102 |
if(dataIn instanceof byte[][][]) { |
|
103 |
byte[][][] d = (byte[][][])dataIn; |
|
104 |
for (int iBand = 0; iBand < d.length; iBand++) { |
|
105 |
for (int row = 0; row < d[iBand].length; row++) { |
|
106 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
} |
|
0 | 113 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/AllTests.java | ||
---|---|---|
1 |
package org.gvsig.raster.cache.buffer.impl.memory; |
|
2 |
|
|
3 |
import junit.framework.Test; |
|
4 |
import junit.framework.TestSuite; |
|
5 |
|
|
6 |
public class AllTests { |
|
7 |
|
|
8 |
public static Test suite() { |
|
9 |
TestSuite suite = new TestSuite( |
|
10 |
"Test for org.gvsig.raster.buffer.memory"); |
|
11 |
//$JUnit-BEGIN$ |
|
12 |
suite.addTestSuite(TestSwapBands.class); |
|
13 |
suite.addTestSuite(TestMemoryBuffer.class); |
|
14 |
suite.addTestSuite(TestRemoveBand.class); |
|
15 |
suite.addTestSuite(TestAddBand.class); |
|
16 |
suite.addTestSuite(TestSwapTwoBands.class); |
|
17 |
suite.addTestSuite(TestCopyBand.class); |
|
18 |
suite.addTestSuite(TestGetBufferWithOneBand.class); |
|
19 |
suite.addTestSuite(TestReplicateBand.class); |
|
20 |
suite.addTestSuite(TestRWOneValue.class); |
|
21 |
suite.addTestSuite(TestCopyBand2.class); |
|
22 |
suite.addTestSuite(TestCreateBand.class); |
|
23 |
suite.addTestSuite(TestAssignBand.class); |
|
24 |
suite.addTestSuite(TestRWTiffAndCompareData.class); |
|
25 |
//$JUnit-END$ |
|
26 |
return suite; |
|
27 |
} |
|
28 |
|
|
29 |
} |
|
0 | 30 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestGetBufferWithOneBand.java | ||
---|---|---|
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.Buffer; |
|
9 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
|
10 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
|
11 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
|
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
13 |
|
|
14 |
/** |
|
15 |
* This test gets bands from a raster with the method getBufferWithOneBand() and compare |
|
16 |
* each band from original source with obtained bands |
|
17 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
18 |
*/ |
|
19 |
public class TestGetBufferWithOneBand extends TestCase { |
|
20 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
21 |
private String rasterOut1 = "/tmp/out-b1.tif"; |
|
22 |
private String rasterOut2 = "/tmp/out-b2.tif"; |
|
23 |
private String rasterOut3 = "/tmp/out-b3.tif"; |
|
24 |
|
|
25 |
public void start() { |
|
26 |
this.setUp(); |
|
27 |
this.testStack(); |
|
28 |
} |
|
29 |
|
|
30 |
public void setUp() { |
|
31 |
System.err.println("MemoryBuffer TestGetBufferWithOneBand 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 |
|
|
52 |
Buffer b0 = buf.getBufferWithOneBand(0); |
|
53 |
Buffer b1 = buf.getBufferWithOneBand(1); |
|
54 |
Buffer b2 = buf.getBufferWithOneBand(2); |
|
55 |
|
|
56 |
//Write output file |
|
57 |
GdalWrite out1 = new GdalWrite(rasterOut1, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
|
58 |
out1.writeBands(b0.getBands()); |
|
59 |
out1.close(); |
|
60 |
|
|
61 |
GdalWrite out2 = new GdalWrite(rasterOut2, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
|
62 |
out2.writeBands(b1.getBands()); |
|
63 |
out2.close(); |
|
64 |
|
|
65 |
GdalWrite out3 = new GdalWrite(rasterOut3, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
|
66 |
out3.writeBands(b2.getBands()); |
|
67 |
out3.close(); |
|
68 |
|
|
69 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
70 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
71 |
byte b_0 = buf.getElemByte(row, col, 0); |
|
72 |
byte b_1 = buf.getElemByte(row, col, 1); |
|
73 |
byte b_2 = buf.getElemByte(row, col, 2); |
|
74 |
assertEquals(b_0, b0.getElemByte(row, col, 0)); |
|
75 |
assertEquals(b_1, b1.getElemByte(row, col, 0)); |
|
76 |
assertEquals(b_2, b2.getElemByte(row, col, 0)); |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
b0.free(); |
|
81 |
b1.free(); |
|
82 |
b2.free(); |
|
83 |
buf.free(); |
|
84 |
|
|
85 |
} catch (GdalException e) { |
|
86 |
e.printStackTrace(); |
|
87 |
} catch (IOException e) { |
|
88 |
e.printStackTrace(); |
|
89 |
} catch (ProcessInterruptedException e) { |
|
90 |
e.printStackTrace(); |
|
91 |
} catch (OperationNotSupportedException e) { |
|
92 |
e.printStackTrace(); |
|
93 |
} |
|
94 |
long t2 = System.currentTimeMillis(); |
|
95 |
System.out.println("Tiempo MemoryBuffer TestGetBufferWithOneBand: " + (t2 - t1) + " milisegundos"); |
|
96 |
} |
|
97 |
|
|
98 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
|
99 |
if(dataIn instanceof byte[][][]) { |
|
100 |
byte[][][] d = (byte[][][])dataIn; |
|
101 |
for (int iBand = 0; iBand < d.length; iBand++) { |
|
102 |
for (int row = 0; row < d[iBand].length; row++) { |
|
103 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
} |
|
0 | 110 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestSwapTwoBands.java | ||
---|---|---|
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.exception.WrongParameterException; |
|
13 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
|
14 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
15 |
|
|
16 |
/** |
|
17 |
* This test swap two bands of a raster and save the result in other file. |
|
18 |
* Finally it compares the output bands with the input bands. |
|
19 |
* |
|
20 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
21 |
*/ |
|
22 |
public class TestSwapTwoBands extends TestCase { |
|
23 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
24 |
private String rasterOut = "/tmp/out-swapedTwo.tif"; |
|
25 |
|
|
26 |
public void start() { |
|
27 |
this.setUp(); |
|
28 |
this.testStack(); |
|
29 |
} |
|
30 |
|
|
31 |
public void setUp() { |
|
32 |
System.err.println("MemoryBuffer TestSwapTwoBands running..."); |
|
33 |
} |
|
34 |
|
|
35 |
public void testStack() { |
|
36 |
long t1 = System.currentTimeMillis(); |
|
37 |
GdalRead input1 = null; |
|
38 |
GdalWrite out = null; |
|
39 |
try { |
|
40 |
//Read input data |
|
41 |
input1 = new GdalRead(rasterIn); |
|
42 |
Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight()); |
|
43 |
|
|
44 |
//Create Buffer |
|
45 |
Buffer buf1 = new RasterMemoryBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), |
|
46 |
input1.getWidth(), |
|
47 |
input1.getHeight(), |
|
48 |
input1.getBandCount(), |
|
49 |
true); |
|
50 |
|
|
51 |
//Set data to buffer |
|
52 |
setLines(dataIn1, buf1); |
|
53 |
|
|
54 |
Buffer buf2 = new RasterMemoryBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), |
|
55 |
input1.getWidth(), |
|
56 |
input1.getHeight(), |
|
57 |
input1.getBandCount(), |
|
58 |
true); |
|
59 |
|
|
60 |
//Set data to buffer |
|
61 |
setLines(dataIn1, buf2); |
|
62 |
try { |
|
63 |
buf2.swapBands(0, 2); |
|
64 |
} catch (WrongParameterException e) { |
|
65 |
e.printStackTrace(); |
|
66 |
} |
|
67 |
|
|
68 |
//Write output file |
|
69 |
out = new GdalWrite(rasterOut, input1.getBandCount(), input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_RGB); |
|
70 |
out.writeBands(buf2.getBands()); |
|
71 |
out.close(); |
|
72 |
|
|
73 |
Band band1 = buf1.getBand(0); |
|
74 |
Band band2 = buf2.getBand(2); |
|
75 |
compareBands(band1, band2); |
|
76 |
|
|
77 |
band1 = buf1.getBand(2); |
|
78 |
band2 = buf2.getBand(0); |
|
79 |
compareBands(band1, band2); |
|
80 |
|
|
81 |
band1 = buf1.getBand(1); |
|
82 |
band2 = buf2.getBand(1); |
|
83 |
compareBands(band1, band2); |
|
84 |
|
|
85 |
buf1.free(); |
|
86 |
buf2.free(); |
|
87 |
} catch (GdalException e) { |
|
88 |
e.printStackTrace(); |
|
89 |
} catch (IOException e) { |
|
90 |
e.printStackTrace(); |
|
91 |
} catch (ProcessInterruptedException e) { |
|
92 |
e.printStackTrace(); |
|
93 |
} catch (OperationNotSupportedException e) { |
|
94 |
e.printStackTrace(); |
|
95 |
} |
|
96 |
long t2 = System.currentTimeMillis(); |
|
97 |
System.out.println("Tiempo MemoryBuffer TestSwapTwoBands: " + (t2 - t1) + " milisegundos"); |
|
98 |
} |
|
99 |
|
|
100 |
public void compareBands(Band band1, Band band2) { |
|
101 |
for (int i = 0; i < band1.getHeight(); i++) { |
|
102 |
for (int j = 0; j < band1.getWidth(); j++) { |
|
103 |
byte b1 = band1.getElemByte(i, j); |
|
104 |
byte b2 = band2.getElemByte(i, j); |
|
105 |
assertEquals(b1, b2); |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
|
111 |
if(dataIn instanceof byte[][][]) { |
|
112 |
byte[][][] d = (byte[][][])dataIn; |
|
113 |
for (int iBand = 0; iBand < d.length; iBand++) { |
|
114 |
for (int row = 0; row < d[iBand].length; row++) { |
|
115 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
} |
|
0 | 122 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestAddBand.java | ||
---|---|---|
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 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
14 |
|
|
15 |
/** |
|
16 |
* This test add a band in a raster of 3 bands. As a result of this test a raster |
|
17 |
* of four bands is created and saved in the hard disk. The value of additional band |
|
18 |
* is zero in all its elements. Finally it gets the band added and compare each values |
|
19 |
* with 0. |
|
20 |
* |
|
21 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
22 |
*/ |
|
23 |
public class TestAddBand extends TestCase { |
|
24 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
25 |
private String rasterOut = "/tmp/out-4bands.tif"; |
|
26 |
|
|
27 |
public void start() { |
|
28 |
this.setUp(); |
|
29 |
this.testStack(); |
|
30 |
} |
|
31 |
|
|
32 |
public void setUp() { |
|
33 |
System.err.println("MemoryBuffer TestAddBand running..."); |
|
34 |
} |
|
35 |
|
|
36 |
public void testStack() { |
|
37 |
long t1 = System.currentTimeMillis(); |
|
38 |
GdalRead input = null; |
|
39 |
GdalWrite out = null; |
|
40 |
try { |
|
41 |
|
|
42 |
//Read input data |
|
43 |
input = new GdalRead(rasterIn); |
|
44 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
|
45 |
|
|
46 |
//Create Buffer |
|
47 |
Buffer buf = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
|
48 |
input.getWidth(), |
|
49 |
input.getHeight(), |
|
50 |
input.getBandCount(), |
|
51 |
true); |
|
52 |
|
|
53 |
//Set data to buffer |
|
54 |
setLines(dataIn, buf); |
|
55 |
buf.addBand(1); |
|
56 |
|
|
57 |
//Write output file |
|
58 |
out = new GdalWrite(rasterOut, 4, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
|
59 |
out.writeBands(buf.getBands()); |
|
60 |
out.close(); |
|
61 |
|
|
62 |
Band band = buf.getBand(1); |
|
63 |
for (int i = 0; i < band.getHeight(); i++) { |
|
64 |
for (int j = 0; j < band.getWidth(); j++) { |
|
65 |
byte b = band.getElemByte(i, j); |
|
66 |
assertEquals(0, b); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
buf.free(); |
|
71 |
} catch (GdalException e) { |
|
72 |
e.printStackTrace(); |
|
73 |
} catch (IOException e) { |
|
74 |
e.printStackTrace(); |
|
75 |
} catch (ProcessInterruptedException e) { |
|
76 |
e.printStackTrace(); |
|
77 |
} catch (OperationNotSupportedException e) { |
|
78 |
e.printStackTrace(); |
|
79 |
} |
|
80 |
long t2 = System.currentTimeMillis(); |
|
81 |
System.out.println("Tiempo MemoryBuffer TestAddBand: " + (t2 - t1) + " milisegundos"); |
|
82 |
} |
|
83 |
|
|
84 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
|
85 |
if(dataIn instanceof byte[][][]) { |
|
86 |
byte[][][] d = (byte[][][])dataIn; |
|
87 |
for (int iBand = 0; iBand < d.length; iBand++) { |
|
88 |
for (int row = 0; row < d[iBand].length; row++) { |
|
89 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
|
90 |
} |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
} |
|
0 | 96 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestReplicateBand.java | ||
---|---|---|
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 |
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("MemoryBuffer TestReplicateBand running..."); |
|
33 |
} |
|
34 |
|
|
35 |
public void testStack() { |
|
36 |
long t1 = System.currentTimeMillis(); |
|
37 |
GdalRead input1 = null; |
|
38 |
GdalWrite out = null; |
|
39 |
try { |
|
40 |
//Read input data |
|
41 |
input1 = new GdalRead(rasterIn); |
|
42 |
Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight()); |
|
43 |
|
|
44 |
//Create Buffer |
|
45 |
Buffer buf1 = new RasterMemoryBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), |
|
46 |
input1.getWidth(), |
|
47 |
input1.getHeight(), |
|
48 |
input1.getBandCount(), |
|
49 |
true); |
|
50 |
|
|
51 |
//Set data to buffer |
|
52 |
setLines(dataIn1, buf1); |
|
53 |
|
|
54 |
buf1.replicateBand(0, 3); |
|
55 |
|
|
56 |
//Write output file |
|
57 |
out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
|
58 |
out.writeBands(buf1.getBands()); |
|
59 |
out.close(); |
|
60 |
|
|
61 |
Band band1 = buf1.getBand(0); |
|
62 |
Band band2 = buf1.getBand(3); |
|
63 |
for (int i = 0; i < band1.getHeight(); i++) { |
|
64 |
for (int j = 0; j < band1.getWidth(); j++) { |
|
65 |
byte b1 = band1.getElemByte(i, j); |
|
66 |
byte b2 = band2.getElemByte(i, j); |
|
67 |
assertEquals(b1, b2); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
buf1.free(); |
|
72 |
} catch (GdalException e) { |
|
73 |
e.printStackTrace(); |
|
74 |
} catch (IOException e) { |
|
75 |
e.printStackTrace(); |
|
76 |
} catch (ProcessInterruptedException e) { |
|
77 |
e.printStackTrace(); |
|
78 |
} catch (OperationNotSupportedException e) { |
|
79 |
e.printStackTrace(); |
|
80 |
} |
|
81 |
long t2 = System.currentTimeMillis(); |
|
82 |
System.out.println("Tiempo MemoryBuffer TestReplicateBand: " + (t2 - t1) + " milisegundos"); |
|
83 |
} |
|
84 |
|
|
85 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
|
86 |
if(dataIn instanceof byte[][][]) { |
|
87 |
byte[][][] d = (byte[][][])dataIn; |
|
88 |
for (int iBand = 0; iBand < d.length; iBand++) { |
|
89 |
for (int row = 0; row < d[iBand].length; row++) { |
|
90 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
} |
|
0 | 97 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestCopyBand.java | ||
---|---|---|
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.BandNotCompatibleException; |
|
11 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
|
12 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
|
13 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
|
14 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
15 |
|
|
16 |
/** |
|
17 |
* Copy the band 0 from a buffer over the band 2 in the same buffer using the |
|
18 |
* method getBandCopy. |
|
19 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
20 |
*/ |
|
21 |
public class TestCopyBand extends TestCase { |
|
22 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
23 |
private String rasterOut = "/tmp/out-copyFirstBand.tif"; |
|
24 |
|
|
25 |
public void start() { |
|
26 |
this.setUp(); |
|
27 |
this.testStack(); |
|
28 |
} |
|
29 |
|
|
30 |
public void setUp() { |
|
31 |
System.err.println("MemoryBuffer TestCopyBand running..."); |
|
32 |
} |
|
33 |
|
|
34 |
public void testStack() { |
|
35 |
long t1 = System.currentTimeMillis(); |
|
36 |
GdalRead input = null; |
|
37 |
GdalWrite out = null; |
|
38 |
try { |
|
39 |
//Read input data |
|
40 |
input = new GdalRead(rasterIn); |
|
41 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
|
42 |
|
|
43 |
//Create Buffer |
|
44 |
Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
|
45 |
input.getWidth(), |
|
46 |
input.getHeight(), |
|
47 |
input.getBandCount(), |
|
48 |
true); |
|
49 |
|
|
50 |
//Set data to buffer |
|
51 |
setLines(dataIn, buf1); |
|
52 |
|
|
53 |
|
|
54 |
Band rb = buf1.getBandCopy(0); |
|
55 |
|
|
56 |
try { |
|
57 |
buf1.copyBand(2, rb); |
|
58 |
} catch (BandNotCompatibleException e) { |
|
59 |
e.printStackTrace(); |
|
60 |
} |
|
61 |
|
|
62 |
//Write output file |
|
63 |
out = new GdalWrite(rasterOut, 3, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB); |
|
64 |
out.writeBands(buf1.getBands()); |
|
65 |
out.close(); |
|
66 |
|
|
67 |
Band band1 = buf1.getBand(0); |
|
68 |
Band band2 = buf1.getBand(2); |
|
69 |
for (int i = 0; i < band1.getHeight(); i++) { |
|
70 |
for (int j = 0; j < band1.getWidth(); j++) { |
|
71 |
byte b1 = band1.getElemByte(i, j); |
|
72 |
byte b2 = band2.getElemByte(i, j); |
|
73 |
assertEquals(b1, b2); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
buf1.free(); |
|
78 |
} catch (GdalException e) { |
|
79 |
e.printStackTrace(); |
|
80 |
} catch (IOException e) { |
|
81 |
e.printStackTrace(); |
|
82 |
} catch (ProcessInterruptedException e) { |
|
83 |
e.printStackTrace(); |
|
84 |
} catch (OperationNotSupportedException e) { |
|
85 |
e.printStackTrace(); |
|
86 |
} |
|
87 |
long t2 = System.currentTimeMillis(); |
|
88 |
System.out.println("Tiempo MemoryBuffer TestCopyBand: " + (t2 - t1) + " milisegundos"); |
|
89 |
} |
|
90 |
|
|
91 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
|
92 |
if(dataIn instanceof byte[][][]) { |
|
93 |
byte[][][] d = (byte[][][])dataIn; |
|
94 |
for (int iBand = 0; iBand < d.length; iBand++) { |
|
95 |
for (int row = 0; row < d[iBand].length; row++) { |
|
96 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
|
97 |
} |
|
98 |
} |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
} |
|
0 | 103 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestCopyBand2.java | ||
---|---|---|
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.BandNotCompatibleException; |
|
11 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
|
12 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
|
13 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
|
14 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
15 |
import org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.RasterCacheBuffer; |
|
16 |
|
|
17 |
/** |
|
18 |
* Copy the band 0 from a buffer over the band 2 of other buffer using the |
|
19 |
* method getBand (reference). |
|
20 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
21 |
*/ |
|
22 |
public class TestCopyBand2 extends TestCase { |
|
23 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
24 |
private String rasterOut = "/tmp/out-copyFirstBand.tif"; |
|
25 |
|
|
26 |
public void start() { |
|
27 |
this.setUp(); |
|
28 |
this.testStack(); |
|
29 |
} |
|
30 |
|
|
31 |
public void setUp() { |
|
32 |
System.err.println("MemoryBuffer TestCopyBand2 running..."); |
|
33 |
} |
|
34 |
|
|
35 |
public void testStack() { |
|
36 |
long t1 = System.currentTimeMillis(); |
|
37 |
GdalRead input = null; |
|
38 |
GdalWrite out = null; |
|
39 |
try { |
|
40 |
//Read input data |
|
41 |
input = new GdalRead(rasterIn); |
|
42 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
|
43 |
|
|
44 |
//Create Buffer |
|
45 |
Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
|
46 |
input.getWidth(), |
|
47 |
input.getHeight(), |
|
48 |
input.getBandCount(), |
|
49 |
true); |
|
50 |
|
|
51 |
//Set data to buffer |
|
52 |
setLines(dataIn, buf1); |
|
53 |
|
|
54 |
//Create Buffer |
|
55 |
Buffer buf2 = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
|
56 |
input.getWidth(), |
|
57 |
input.getHeight(), |
|
58 |
input.getBandCount()); |
|
59 |
|
|
60 |
//Set data to buffer |
|
61 |
setLines(dataIn, buf2); |
|
62 |
|
|
63 |
Band rb = buf1.getBand(0); |
|
64 |
|
|
65 |
try { |
|
66 |
buf2.copyBand(2, rb); |
|
67 |
} catch (BandNotCompatibleException e) { |
|
68 |
e.printStackTrace(); |
|
69 |
} |
|
70 |
|
|
71 |
//Write output file |
|
72 |
out = new GdalWrite(rasterOut, 3, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB); |
|
73 |
out.writeBands(buf2.getBands()); |
|
74 |
out.close(); |
|
75 |
|
|
76 |
Band band1 = buf1.getBand(0); |
|
77 |
Band band2 = buf2.getBand(2); |
|
78 |
for (int i = 0; i < band1.getHeight(); i++) { |
|
79 |
for (int j = 0; j < band1.getWidth(); j++) { |
|
80 |
byte b1 = band1.getElemByte(i, j); |
|
81 |
byte b2 = band2.getElemByte(i, j); |
|
82 |
assertEquals(b1, b2); |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
buf1.free(); |
|
87 |
buf2.free(); |
|
88 |
} catch (GdalException e) { |
|
89 |
e.printStackTrace(); |
|
90 |
} catch (IOException e) { |
|
91 |
e.printStackTrace(); |
|
92 |
} catch (ProcessInterruptedException e) { |
|
93 |
e.printStackTrace(); |
|
94 |
} catch (OperationNotSupportedException e) { |
|
95 |
e.printStackTrace(); |
|
96 |
} |
|
97 |
long t2 = System.currentTimeMillis(); |
|
98 |
System.out.println("Tiempo MemoryBuffer TestCopyBand2: " + (t2 - t1) + " milisegundos"); |
|
99 |
} |
|
100 |
|
|
101 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
|
102 |
if(dataIn instanceof byte[][][]) { |
|
103 |
byte[][][] d = (byte[][][])dataIn; |
|
104 |
for (int iBand = 0; iBand < d.length; iBand++) { |
|
105 |
for (int row = 0; row < d[iBand].length; row++) { |
|
106 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
} |
|
0 | 113 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestMemoryBuffer.java | ||
---|---|---|
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.Buffer; |
|
9 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
|
10 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
|
11 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
|
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
13 |
|
|
14 |
/** |
|
15 |
* |
|
16 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
17 |
*/ |
|
18 |
public class TestMemoryBuffer extends TestCase { |
|
19 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
20 |
private String rasterOut = "/tmp/out.tif"; |
|
21 |
|
|
22 |
public void start() { |
|
23 |
this.setUp(); |
|
24 |
this.testStack(); |
|
25 |
} |
|
26 |
|
|
27 |
public void setUp() { |
|
28 |
System.err.println("MemoryBuffer TestMemoryBuffer running..."); |
|
29 |
} |
|
30 |
|
|
31 |
public void testStack() { |
|
32 |
long t1 = System.currentTimeMillis(); |
|
33 |
GdalRead input = null; |
|
34 |
GdalWrite out = null; |
|
35 |
try { |
|
36 |
input = new GdalRead(rasterIn); |
|
37 |
Object data = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
|
38 |
|
|
39 |
Buffer buf = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
|
40 |
input.getWidth(), |
|
41 |
input.getHeight(), |
|
42 |
input.getBandCount(), |
|
43 |
true); |
|
44 |
|
|
45 |
if(data instanceof byte[][][]) { |
|
46 |
byte[][][] d = (byte[][][])data; |
|
47 |
for (int i = 0; i < d.length; i++) { |
|
48 |
for (int j = 0; j < d[i].length; j++) { |
|
49 |
buf.setLineInBandByte(d[i][j], j, i); |
|
50 |
} |
|
51 |
} |
|
52 |
} |
|
53 |
out = new GdalWrite(rasterOut, input.getBandCount(), input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB); |
|
54 |
out.writeBands(buf.getBands()); |
|
55 |
out.close(); |
|
56 |
|
|
57 |
} catch (GdalException e) { |
|
58 |
e.printStackTrace(); |
|
59 |
} catch (IOException e) { |
|
60 |
e.printStackTrace(); |
|
61 |
} catch (ProcessInterruptedException e) { |
|
62 |
e.printStackTrace(); |
|
63 |
} catch (OperationNotSupportedException e) { |
|
64 |
e.printStackTrace(); |
|
65 |
} |
|
66 |
long t2 = System.currentTimeMillis(); |
|
67 |
System.out.println("Tiempo MemoryBuffer TestMemoryBuffer: " + (t2 - t1) + " milisegundos"); |
|
68 |
} |
|
69 |
|
|
70 |
} |
|
0 | 71 |
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.21/org.gvsig.raster.cache.lib.impl/deprecated/buffer/test/memory/TestRemoveBand.java | ||
---|---|---|
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.Buffer; |
|
9 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
|
10 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
|
11 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
|
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
|
13 |
|
|
14 |
/** |
|
15 |
* This test read a RGB image and remove one band from the read buffer. Then compare |
|
16 |
* the bands that have not been removed with the source bands. As a result of this test a raster |
|
17 |
* of two bands is created and saved in the hard disk |
|
18 |
* |
|
19 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
20 |
*/ |
|
21 |
public class TestRemoveBand extends TestCase { |
|
22 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
|
23 |
private String rasterOut = "/tmp/out-2bands.tif"; |
|
24 |
|
|
25 |
public void start() { |
|
26 |
this.setUp(); |
|
27 |
this.testStack(); |
|
28 |
} |
|
29 |
|
|
30 |
public void setUp() { |
|
31 |
System.err.println("MemoryBuffer TestRemoveBand running..."); |
|
32 |
} |
|
33 |
|
|
34 |
public void testStack() { |
|
35 |
long t1 = System.currentTimeMillis(); |
|
36 |
GdalRead input = null; |
|
37 |
GdalWrite out = null; |
|
38 |
try { |
|
39 |
//Read input data |
|
40 |
input = new GdalRead(rasterIn); |
|
41 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
|
42 |
|
|
43 |
//Create Buffer |
|
44 |
Buffer buf = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
|
45 |
input.getWidth(), |
|
46 |
input.getHeight(), |
|
47 |
input.getBandCount(), |
|
48 |
true); |
|
49 |
|
|
50 |
//Set data to buffer |
|
51 |
setLines(dataIn, buf); |
|
52 |
buf.removeBand(1); |
|
53 |
|
|
54 |
//Write output file |
|
55 |
out = new GdalWrite(rasterOut, 2, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
|
56 |
out.writeBands(buf.getBands()); |
|
57 |
buf.free(); |
|
58 |
out.close(); |
|
59 |
|
|
60 |
//Open output file and compare |
|
61 |
GdalRead newFile = new GdalRead(rasterOut); |
|
62 |
Object dataOut = newFile.readBlock(0, 0, input.getWidth(), input.getHeight()); |
|
63 |
|
|
64 |
byte[][][] d1 = (byte[][][])dataOut; |
|
65 |
byte[][][] d2 = (byte[][][])dataIn; |
|
66 |
|
|
67 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
68 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
69 |
if(d1[0][row][col] != d2[0][row][col]) |
|
70 |
System.out.println("BAND:" + 0 +" ROW:" + row + " COL:" + col + " " + d1[0][row][col] + " " + d2[0][row][col]); |
|
71 |
assertEquals(d1[0][row][col], d2[0][row][col]); |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
76 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
77 |
if(d1[1][row][col] != d2[2][row][col]) |
|
78 |
System.out.println("BAND:" + 1 +" ROW:" + row + " COL:" + col + " " + d1[1][row][col] + " " + d2[2][row][col]); |
|
79 |
assertEquals(d1[1][row][col], d2[2][row][col]); |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
} catch (GdalException e) { |
|
84 |
e.printStackTrace(); |
|
85 |
} catch (IOException e) { |
|
86 |
e.printStackTrace(); |
|
87 |
} catch (ProcessInterruptedException e) { |
|
88 |
e.printStackTrace(); |
|
89 |
} catch (OperationNotSupportedException e) { |
|
90 |
e.printStackTrace(); |
|
91 |
} |
|
92 |
long t2 = System.currentTimeMillis(); |
|
93 |
System.out.println("Tiempo MemoryBuffer TestRemoveBand: " + (t2 - t1) + " milisegundos"); |
|
94 |
} |
Also available in: Unified diff