Revision 17980

View differences:

trunk/libraries/libjni-gdal/src/test/java/jgdal/TestReadData.java
1 1
package jgdal;
2 2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
3 6
import es.gva.cit.jgdal.Gdal;
4
import junit.framework.TestCase;
7
import es.gva.cit.jgdal.GdalBuffer;
8
import es.gva.cit.jgdal.GdalException;
9
import es.gva.cit.jgdal.GdalRasterBand;
5 10

  
6 11
/**
7 12
 * 
8
 * @author Miguel Ángel Qierol Carratalá <miguelangel.querol@iver.es>
13
 * @author Miguel Ángel Querol Carratalá <miguelangel.querol@iver.es>
9 14
 *
10 15
 * TODO: Realizar el test de lectura de datos.
11 16
 */
12 17
public class TestReadData extends TestCase{
13 18

  
14 19
	private Gdal gdal = null;
20
	private GdalRasterBand[] bands = null;
21
	
22
	private int bandCount = 0;
23
	
24
	private String fileName = "testGdal.tif";
15 25
	private String baseDir = "./test-images/";
16
	private String file1 = baseDir + "testGdal.tif"; 
26
	private String file1 = baseDir + fileName;
17 27
	
28
	private String[] metadata = null;
29
	private String proj = null;
30
	
31
	private int						blockXSize = 0;
32
	private int						blockYSize = 0;
33
	private int						dataType = 0;
34
	private int						interpretation = 0;
35
	private int						xSize = 0;
36
	private int						ySize = 0;
37
	
38
	
39
	private int iter = 20;
40
	
18 41
	public void start(){
19 42
		setUp();
20 43
		testStack();
21 44
	}
22
	
45

  
23 46
	public void setUp(){
24
		
47
		gdal = new Gdal();
48
		try {
49

  
50
			System.out.println("***** TEST DE ACCESO A RASTER *****");
51
			System.out.println("     IMAGEN: " + fileName + "\n");
52
			gdal.open(file1, gdal.GA_ReadOnly);
53
			bandCount = gdal.getRasterCount();
54
			System.out.println("Número de bandas: " + bandCount);
55
			bands = new GdalRasterBand[bandCount];
56

  
57

  
58
			for (int j = 1; j<=bandCount ; j++){
59
				bands[j-1] = gdal.getRasterBand(j);
60
			}
61

  
62
			metadata = gdal.getMetadata();
63
			proj = gdal.getProjectionRef();
64

  
65
			for (int j = 0 ; j<bands.length ; j++){
66
				blockXSize = bands[j].getBlockXSize();
67
				blockYSize = bands[j].getBlockYSize();
68
				dataType = bands[j].getRasterDataType();
69
				interpretation = bands[j].getRasterColorInterpretation();
70
				xSize = bands[j].getRasterBandXSize();
71
				ySize = bands[j].getRasterBandYSize();
72

  
73
				System.out.println("Información de la banda " + j + "\n");
74
				System.out.println("*************************");
75
				System.out.println("Tamaño de bloque en X: " + blockXSize);
76
				System.out.println("Tamaño de bloque en Y: " + blockYSize);
77
				System.out.println("Tipo de datos: " + dataType);
78
				System.out.println("Interpretación de color: " + interpretation);
79
				System.out.println("Tamaño en X: " + xSize);
80
				System.out.println("Tamaño en Y: " + ySize);
81
				System.out.println("*************************\n");
82
			}
83
			
84
			
85

  
86
		} catch (GdalException e) {
87
		} catch (IOException e) {
88
		}
25 89
	}
26
	
90

  
27 91
	public void testStack(){
28
		
92
		try{
93
			for (int x = 0 ; x<xSize ; x+=50){
94
				for (int y = 0 ; y<ySize ; y+=50){
95
					if (((x+50)>xSize)  || ((y+50)>ySize)){
96
						break;
97
					}
98
					GdalBuffer[] buff = new GdalBuffer[bandCount];
99
					for (int i = 0 ; i<bandCount ; i++){
100
						buff[i] = bands[i].readRaster(x, y, 50, 50, 50, 50, dataType);
101
						System.out.println("Zoom " + x + " - " + y + ". --- Banda " + i);
102
					}
103
				}
104
			}
105
			gdal.close();
106
		}catch(GdalException e){
107
		}
29 108
	}
30 109
	
31 110
}

Also available in: Unified diff