Revision 7880

View differences:

org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/series/TestSaveSerialToRmf.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.series;
23

  
24
import java.io.File;
25
import java.text.ParseException;
26

  
27
import org.gvsig.fmap.dal.coverage.BaseTestCase;
28
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
29
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
30
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
31
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
32
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
33
import org.gvsig.fmap.dal.coverage.store.props.TimeSeries;
34
/**
35
 * Saves serial information to rmf file
36
 * 
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39
public class TestSaveSerialToRmf extends BaseTestCase {
40
	private String            path1    = baseDir + "serie1.tif";
41
	private String            path2    = baseDir + "serie2.tif";
42
	private String            path3    = baseDir + "serie3.tif";
43
	private RasterDataStore   f1       = null;	
44
	private RasterDataStore   f2       = null;
45
	private RasterDataStore   f3       = null;
46
	//private RasterQuery       query    = null;
47
	protected Buffer          buf1     = null;
48
	
49
	public void start() throws Exception {
50
		this.setUp();
51
		this.testStack();
52
	}
53
	
54
	protected void doSetUp() throws Exception {
55
		System.err.println("TestSaveSerialToRmf running...");
56
		
57
		try {
58
			super.doSetUp();
59
		} catch (Exception e) {
60
			e.printStackTrace();
61
		}
62
		File a = new File(baseDir + "serie1.rmf");
63
		if(a.exists())
64
			a.delete();
65
		a = new File(baseDir + "serie2.rmf");
66
		if(a.exists())
67
			a.delete();
68
		a = new File(baseDir + "serie3.rmf");
69
		if(a.exists())
70
			a.delete();
71
		
72
		try {
73
			f1 = manager.open(path1);
74
			f2 = manager.open(path2);
75
			f3 = manager.open(path3);
76
		} catch (NotSupportedExtensionException e1) {
77
			e1.printStackTrace();
78
		} catch (RasterDriverException e1) {
79
			e1.printStackTrace();
80
		}
81
	}
82
	
83
	public void testStack() {
84
		TimeSeries serialInfo = null;
85
		try {
86
			serialInfo = f1.getTimeSerials(); //Lo da vacio pq antes hemos borrado el rmf
87
			serialInfo.setName("Katrina");
88
			serialInfo.setDescription("Evoluci?n del katrina");
89
			serialInfo.createNewTimeInterval("25/8/2005-00:05:00", "27/8/2005-14:36:00");
90
			f1.setTimeSerials(serialInfo);   //Salvamos la serie
91
			
92
			serialInfo.setName("Katrina2");
93
			serialInfo.setDescription("Evoluci?n del katrina en otra serie");
94
			serialInfo.createNewTimeInterval(152322, 152400);
95
			f1.setTimeSerials(serialInfo);   //Salvamos la serie
96
			
97
			//------------------------------------
98
			
99
			serialInfo = f2.getTimeSerials();
100
			serialInfo.setName("Katrina");
101
			serialInfo.setDescription("Evoluci?n del katrina");
102
			serialInfo.createNewTimeValue("28/8/2005-00:05:00");
103
			f2.setTimeSerials(serialInfo);
104
			
105
			serialInfo.setName("Katrina2");
106
			serialInfo.setDescription("Evoluci?n del katrina en otra serie");
107
			serialInfo.createNewTimeValue(152438);
108
			f2.setTimeSerials(serialInfo);   //Salvamos la serie
109
			
110
			//------------------------------------
111
			
112
			serialInfo = f3.getTimeSerials();
113
			serialInfo.setName("Katrina");
114
			serialInfo.setDescription("Evoluci?n del katrina");
115
			serialInfo.createNewTimeValue("29/8/2005");
116
			f3.setTimeSerials(serialInfo);
117
			
118
			serialInfo.setName("Katrina2");
119
			serialInfo.setDescription("Evoluci?n del katrina en otra serie");
120
			serialInfo.createNewTimeValue(152550.0);
121
			f3.setTimeSerials(serialInfo);   //Salvamos la serie
122
			
123
		} catch (RmfSerializerException e1) {
124
			// TODO Auto-generated catch block
125
			e1.printStackTrace();
126
		} catch (ParseException e) {
127
			// TODO Auto-generated catch block
128
			e.printStackTrace();
129
		}
130
		
131
		
132
		/*query = manager.createQuery();
133
		query.setAllDrawableBands();
134
		try {
135
			query.setAreaOfInterest(f1.getExtent().getMin().getX(), f1.getExtent().getMax().getY(), f1.getExtent().width(), f1.getExtent().height());
136
			buf1 = f1.query(query);
137
		} catch (RasterDriverException e) {
138
			e.printStackTrace();
139
		} catch (InvalidSetViewException e) {
140
			e.printStackTrace();
141
		} catch (ProcessInterruptedException e) {
142
			e.printStackTrace();
143
		}
144
		
145
		System.out.println("R:" + (buf1.getElemByte(0, 0, 0) & 0xff));
146
		System.out.println("G:" + (buf1.getElemByte(0, 0, 1) & 0xff));
147
		System.out.println("B:" + (buf1.getElemByte(0, 0, 2) & 0xff));*/
148
	}
149
}
0 150

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/series/TestReadDataTDataStore.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.series;
23

  
24
import java.text.ParseException;
25

  
26
import org.gvsig.fmap.dal.coverage.BaseTestCase;
27
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
28
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
29
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
30
import org.gvsig.fmap.dal.coverage.exception.OperationNotSupportedException;
31
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
32
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
33
import org.gvsig.fmap.dal.coverage.exception.TimeException;
34
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
35
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
36
/**
37
 * Saves serial information to rmf file
38
 * 
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class TestReadDataTDataStore extends BaseTestCase {
42
	private String            path1    = baseDir + "serie1.tif";
43
	private String            path2    = baseDir + "serie2.tif";
44
	private String            path3    = baseDir + "serie3.tif";
45
	private RasterDataStore   f1       = null;	
46
	private RasterDataStore   f2       = null;
47
	private RasterDataStore   f3       = null;
48
	//private RasterQuery       query    = null;
49
	protected Buffer          buf1     = null;
50
	
51
	public void start() throws Exception {
52
		this.setUp();
53
		this.testStack();
54
	}
55
	
56
	protected void doSetUp() throws Exception {
57
		System.err.println("TestSaveSerialToRmf running...");
58
		
59
		try {
60
			super.doSetUp();
61
		} catch (Exception e) {
62
			e.printStackTrace();
63
		}
64
		
65
		try {
66
			f1 = manager.open(path1);
67
			f2 = manager.open(path2);
68
			f3 = manager.open(path3);
69
		} catch (NotSupportedExtensionException e1) {
70
			e1.printStackTrace();
71
		} catch (RasterDriverException e1) {
72
			e1.printStackTrace();
73
		}
74
	}
75
	
76
	public void testStack() {
77
		/*try {
78
			RasterDataStore store = new DefaultTRasterStore(f1);
79
			store.addTemporalDataStore(f2);
80
			store.addTemporalDataStore(f3);*/
81
			
82
			//Selecci?n temporal por valor
83
			
84
			/*TimeInfo tInfo = new DefaultTimeInfo();
85
			tInfo.addValue("29/8/2005"); //Blue
86
			store.setTime(tInfo);
87
			
88
			Buffer buf = readData(store);
89
			byte[] data = new byte[3];
90
			buf.getElemByte(0, 0, data);
91
			assertEquals(0, data[0]);
92
			assertEquals(0, data[1]);
93
			assertEquals(-1, data[2]);
94
			System.out.println("RGB:" + data[0] + ", " + data[1] + ", " + data[2]);*/
95
			
96
			
97
			//Selecci?n temporal por rango
98
			
99
			/*tInfo = new DefaultTimeInfo();
100
			tInfo.addValue("26/8/2005-10:05:00"); //Red
101
			tInfo.addValue("26/8/2005-12:36:00");
102
			store.setTime(tInfo);
103
			
104
			buf = readData(store);
105
			data = new byte[3];
106
			buf.getElemByte(0, 0, data);
107
			assertEquals(-1, data[0]);
108
			assertEquals(0, data[1]);
109
			assertEquals(0, data[2]);
110
			System.out.println("RGB:" + data[0] + ", " + data[1] + ", " + data[2]);
111
			
112
			//Tests para los intervalos numericos
113
			tInfo = new DefaultTimeInfo();
114
			tInfo.addValue(152438); //Green
115
			store.selectSerial("Katrina2");
116
			store.setTime(tInfo);
117
			
118
			buf = readData(store);
119
			data = new byte[3];
120
			buf.getElemByte(0, 0, data);
121
			assertEquals(0, data[0]);
122
			assertEquals(-1, data[1]);
123
			assertEquals(0, data[2]);
124
			System.out.println("RGB:" + data[0] + ", " + data[1] + ", " + data[2]);
125
			
126
			tInfo = new DefaultTimeInfo();
127
			tInfo.addValue(152340); //Red
128
			store.setTime(tInfo);
129
			
130
			buf = readData(store);
131
			data = new byte[3];
132
			buf.getElemByte(0, 0, data);
133
			assertEquals(-1, data[0]);
134
			assertEquals(0, data[1]);
135
			assertEquals(0, data[2]);
136
			System.out.println("RGB:" + data[0] + ", " + data[1] + ", " + data[2]);
137
			
138
			tInfo = new DefaultTimeInfo();
139
			tInfo.addValue(152550); //Red
140
			store.setTime(tInfo);
141
			
142
			buf = readData(store);
143
			data = new byte[3];
144
			buf.getElemByte(0, 0, data);
145
			assertEquals(0, data[0]);
146
			assertEquals(0, data[1]);
147
			assertEquals(-1, data[2]);
148
			System.out.println("RGB:" + data[0] + ", " + data[1] + ", " + data[2]);
149
			
150
		} catch (ParseException e) {
151
			e.printStackTrace();
152
		} catch (TimeException e) {
153
			e.printStackTrace();
154
		} catch (OperationNotSupportedException e) {
155
			e.printStackTrace();
156
		}*/
157
		
158
	}
159
	
160
	private Buffer readData(RasterDataStore store) {
161
		RasterQuery query = manager.createQuery();
162
		query.setAllDrawableBands();
163
		try {
164
			query.setAreaOfInterest(0, 0, (int)store.getWidth(), (int)store.getHeight());
165
			return store.query(query);
166
		} catch (InvalidSetViewException e1) {
167
			e1.printStackTrace();
168
		} catch (ProcessInterruptedException e) {
169
			e.printStackTrace();
170
		} catch (RasterDriverException e) {
171
			e.printStackTrace();
172
		}
173
		
174
		return null;
175
	}
176
}
0 177

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestDSDoubleAdjustToExtentBufferGdal.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
23

  
24
import org.gvsig.fmap.dal.coverage.BaseTestCase;
25
import org.gvsig.fmap.dal.coverage.RasterLocator;
26
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
27
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
28
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
29
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
30
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
31
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
32
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
33
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
34

  
35
/**
36
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
37
 * para un raster leido con Gdal con coordenadas pixel. 
38
 * 
39
 * Lee el raster completo y comprueba que los datos leidos sean correctos 
40
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
41
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
42
 * leidos sean correctos.
43
 * 
44
 * @author Nacho Brodin (nachobrodin@gmail.com)
45
 *
46
 */
47
public class TestDSDoubleAdjustToExtentBufferGdal extends BaseTestCase {
48
	private String             path    = baseDir + "miniRaster25x24.tif";	
49
	private RasterDataStore    f       = null;	
50
	private RasterQuery        query   = null;
51
	protected Buffer           raster  = null;
52
	
53
    public void start() throws Exception {
54
		this.setUp();
55
		this.testStack();
56
	}
57
	
58
    @Override
59
    protected void doSetUp() throws Exception {
60
		System.err.println("TDSDoubleAdjustToExtentBufferGdal running...");
61
		//System.out.println("TestDataSource (Real Coord) Adjust To Extent With Buffer [Gdal] running...");
62
		try {
63
			super.doSetUp();
64
		} catch (Exception e) {
65
			e.printStackTrace();
66
		}
67
	}
68
	
69
	public void testStack() {
70
		int[] drawableBands = {0, 1, 2};
71
		try {
72
			f = manager.open(path);
73
		} catch (RasterDriverException e) {
74
			e.printStackTrace();
75
			return;
76
		} catch (NotSupportedExtensionException e) {
77
			e.printStackTrace();
78
			return;
79
		}
80
		query = manager.createQuery();
81
		query.setDrawableBands(drawableBands);
82
		try {
83
			Extent extent = RasterLocator.getManager().getDataStructFactory().createExtent(645817.0, 4923851.0, 645853.0, 4923815.0);
84
			query.setAreaOfInterest(extent, 10, 10);
85
			raster = f.query(query);
86
		} catch (RasterDriverException e) {
87
			e.printStackTrace();
88
		} catch (InvalidSetViewException e) {
89
			e.printStackTrace();
90
		} catch (ProcessInterruptedException e) {
91
			e.printStackTrace();
92
		}
93
		//print();
94
		dataTest1();
95
		
96
		try {
97
			Extent extent = RasterLocator.getManager().getDataStructFactory().createExtent(645826.9, 4923844.0, 645838.3, 4923833.3);
98
			query.setAreaOfInterest(extent, 2, 2);
99
			raster = f.query(query);
100
		} catch (RasterDriverException e) {
101
			e.printStackTrace();
102
		} catch (InvalidSetViewException e) {
103
			e.printStackTrace();
104
		} catch (ProcessInterruptedException e) {
105
			e.printStackTrace();
106
		}
107
		dataTest2();
108
		//print();
109
	}
110
	
111
	private void dataTest2(){
112
		//Upper Left
113
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 24);
114
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 37);
115
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 7);
116
		//Upper Right
117
		assertEquals((int)(raster.getElemByte(0, 1, 0) & 0xff), 70);
118
		assertEquals((int)(raster.getElemByte(0, 1, 1) & 0xff), 78);
119
		assertEquals((int)(raster.getElemByte(0, 1, 2) & 0xff), 55);
120
		//Lower Left
121
		assertEquals((int)(raster.getElemByte(1, 0, 0) & 0xff), 97);
122
		assertEquals((int)(raster.getElemByte(1, 0, 1) & 0xff), 115);
123
		assertEquals((int)(raster.getElemByte(1, 0, 2) & 0xff), 73);
124
		//Lower Right
125
		assertEquals((int)(raster.getElemByte(1, 1, 0) & 0xff), 65);
126
		assertEquals((int)(raster.getElemByte(1, 1, 1) & 0xff), 75);
127
		assertEquals((int)(raster.getElemByte(1, 1, 2) & 0xff), 51);
128
	}
129
	
130
	private void dataTest1(){
131
		//Upper Left
132
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 97);
133
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 101);
134
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 68);
135
		//Upper Right
136
		assertEquals((int)(raster.getElemByte(0, 9, 0) & 0xff), 58);
137
		assertEquals((int)(raster.getElemByte(0, 9, 1) & 0xff), 85);
138
		assertEquals((int)(raster.getElemByte(0, 9, 2) & 0xff), 42);
139
		//Lower Left
140
		assertEquals((int)(raster.getElemByte(9, 0, 0) & 0xff), 164);
141
		assertEquals((int)(raster.getElemByte(9, 0, 1) & 0xff), 158);
142
		assertEquals((int)(raster.getElemByte(9, 0, 2) & 0xff), 144);
143
		//Lower Right
144
		assertEquals((int)(raster.getElemByte(9, 9, 0) & 0xff), 135);
145
		assertEquals((int)(raster.getElemByte(9, 9, 1) & 0xff), 126);
146
		assertEquals((int)(raster.getElemByte(9, 9, 2) & 0xff), 127);
147
		
148
		assertEquals((int)(raster.getElemByte(6, 6, 0) & 0xff), 120);
149
		assertEquals((int)(raster.getElemByte(6, 6, 1) & 0xff), 127);
150
		assertEquals((int)(raster.getElemByte(6, 6, 2) & 0xff), 96);
151
		
152
		assertEquals((int)(raster.getElemByte(2, 3, 0) & 0xff), 24);
153
		assertEquals((int)(raster.getElemByte(2, 3, 1) & 0xff), 37);
154
		assertEquals((int)(raster.getElemByte(2, 3, 2) & 0xff), 7);
155
		
156
		assertEquals((int)(raster.getElemByte(5, 4, 0) & 0xff), 88);
157
		assertEquals((int)(raster.getElemByte(5, 4, 1) & 0xff), 103);
158
		assertEquals((int)(raster.getElemByte(5, 4, 2) & 0xff), 82);
159
		
160
		assertEquals((int)(raster.getElemByte(9, 2, 0) & 0xff), 157);
161
		assertEquals((int)(raster.getElemByte(9, 2, 1) & 0xff), 143);
162
		assertEquals((int)(raster.getElemByte(9, 2, 2) & 0xff), 130);
163
		
164
		assertEquals((int)(raster.getElemByte(7, 8, 0) & 0xff), 222);
165
		assertEquals((int)(raster.getElemByte(7, 8, 1) & 0xff), 222);
166
		assertEquals((int)(raster.getElemByte(7, 8, 2) & 0xff), 220);
167
	}
168
	
169
	/**
170
	 * Imprime todos los pixels de la fuente de datos en RGB
171
	 */
172
	/*private void print(){
173
		IBuffer raster = ds.getRasterBuf();
174
		for(int line = 0; line < raster.getHeight(); line++){
175
			for(int col = 0; col < raster.getWidth(); col++)
176
				System.out.print("(" + (int)(raster.getElemByte(line, col, 0) & 0xff) + " " + (int)(raster.getElemByte(line, col, 1) & 0xff) + " " + (int)(raster.getElemByte(line, col, 2) & 0xff) + ")");
177
			System.out.println();
178
		}
179
	}*/
180

  
181
}
0 182

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestDSIntGdal.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
23

  
24
import org.gvsig.fmap.dal.coverage.BaseTestCase;
25
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
26
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
27
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
31
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
32

  
33
/**
34
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
35
 * para un raster leido con Gdal con coordenadas pixel. 
36
 * 
37
 * Lee el raster completo y comprueba que los datos leidos sean correctos 
38
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
39
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
40
 * leidos sean correctos.
41
 * 
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 *
44
 */
45
public class TestDSIntGdal extends BaseTestCase {
46
	private String path = baseDir + "miniRaster25x24.tif";	
47
	private RasterDataStore       f              = null;	
48
	private RasterQuery            query          = null;
49
	protected Buffer               raster         = null;
50
	
51
    public void start() throws Exception {
52
		this.setUp();
53
		this.testStack();
54
	}
55
	
56
    @Override
57
    protected void doSetUp() throws Exception {
58
		System.err.println("TestDataSetIntGdal running...");
59
		try {
60
			super.doSetUp();
61
		} catch (Exception e) {
62
			e.printStackTrace();
63
		}
64
	}
65
	
66
	public void testStack(){
67
		int[] drawableBands = {0, 1, 2};
68
		try {
69
			f = manager.open(path);
70
		} catch (NotSupportedExtensionException e) {
71
			e.printStackTrace();
72
		} catch (RasterDriverException e) {
73
			e.printStackTrace();
74
		}
75
		query = manager.createQuery();
76
		query.setDrawableBands(drawableBands);
77
		try {
78
			query.setAreaOfInterest(0, 0, 25, 24);
79
			raster = f.query(query);
80
		} catch (InvalidSetViewException e) {
81
			e.printStackTrace();
82
		} catch (ProcessInterruptedException e) {
83
			e.printStackTrace();
84
		} catch (RasterDriverException e) {
85
			e.printStackTrace();
86
			return;
87
		}
88
		dataTest1();
89
		//print();
90
		
91
		try {
92
			query.setAreaOfInterest(10, 10, 2, 2);
93
			raster = f.query(query);
94
		} catch (InvalidSetViewException e) {
95
			e.printStackTrace();
96
		} catch (ProcessInterruptedException e) {
97
			e.printStackTrace();
98
		} catch (RasterDriverException e) {
99
			e.printStackTrace();
100
			return;
101
		}
102
		dataTest2();
103
		//print();
104
	}
105
	
106
	private void dataTest2(){
107
		//Upper Left
108
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 80);
109
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 96);
110
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 60);
111
		//Upper Right
112
		assertEquals((int)(raster.getElemByte(0, 1, 0) & 0xff), 80);
113
		assertEquals((int)(raster.getElemByte(0, 1, 1) & 0xff), 96);
114
		assertEquals((int)(raster.getElemByte(0, 1, 2) & 0xff), 60);
115
		//Lower Left
116
		assertEquals((int)(raster.getElemByte(1, 0, 0) & 0xff), 82);
117
		assertEquals((int)(raster.getElemByte(1, 0, 1) & 0xff), 97);
118
		assertEquals((int)(raster.getElemByte(1, 0, 2) & 0xff), 68);
119
		//Lower Right
120
		assertEquals((int)(raster.getElemByte(1, 1, 0) & 0xff), 82);
121
		assertEquals((int)(raster.getElemByte(1, 1, 1) & 0xff), 97);
122
		assertEquals((int)(raster.getElemByte(1, 1, 2) & 0xff), 68);
123
	}
124
	
125
	private void dataTest1(){
126
		//Upper Left
127
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 14);
128
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 14);
129
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 0);
130
		//Upper Right
131
		assertEquals((int)(raster.getElemByte(0, 24, 0) & 0xff), 68);
132
		assertEquals((int)(raster.getElemByte(0, 24, 1) & 0xff), 90);
133
		assertEquals((int)(raster.getElemByte(0, 24, 2) & 0xff), 52);
134
		//Lower Left
135
		assertEquals((int)(raster.getElemByte(23, 0, 0) & 0xff), 129);
136
		assertEquals((int)(raster.getElemByte(23, 0, 1) & 0xff), 122);
137
		assertEquals((int)(raster.getElemByte(23, 0, 2) & 0xff), 106);
138
		//Lower Right
139
		assertEquals((int)(raster.getElemByte(23, 24, 0) & 0xff), 145);
140
		assertEquals((int)(raster.getElemByte(23, 24, 1) & 0xff), 140);
141
		assertEquals((int)(raster.getElemByte(23, 24, 2) & 0xff), 134);
142
		
143
		assertEquals((int)(raster.getElemByte(6, 6, 0) & 0xff), 21);
144
		assertEquals((int)(raster.getElemByte(6, 6, 1) & 0xff), 37);
145
		assertEquals((int)(raster.getElemByte(6, 6, 2) & 0xff), 10);
146
		
147
		assertEquals((int)(raster.getElemByte(6, 23, 0) & 0xff), 91);
148
		assertEquals((int)(raster.getElemByte(6, 23, 1) & 0xff), 105);
149
		assertEquals((int)(raster.getElemByte(6, 23, 2) & 0xff), 92);
150
		
151
		assertEquals((int)(raster.getElemByte(23, 6, 0) & 0xff), 153);
152
		assertEquals((int)(raster.getElemByte(23, 6, 1) & 0xff), 133);
153
		assertEquals((int)(raster.getElemByte(23, 6, 2) & 0xff), 122);
154
		
155
		assertEquals((int)(raster.getElemByte(9, 14, 0) & 0xff), 63);
156
		assertEquals((int)(raster.getElemByte(9, 14, 1) & 0xff), 69);
157
		assertEquals((int)(raster.getElemByte(9, 14, 2) & 0xff), 55);
158
		
159
		assertEquals((int)(raster.getElemByte(6, 13, 0) & 0xff), 70);
160
		assertEquals((int)(raster.getElemByte(6, 13, 1) & 0xff), 78);
161
		assertEquals((int)(raster.getElemByte(6, 13, 2) & 0xff), 55);
162
	}
163
	
164
	/**
165
	 * Imprime todos los pixels de la fuente de datos en RGB
166
	 */
167
	/*private void print(){
168
		IBuffer raster = ds.getRasterBuf();
169
		for(int line = 0; line < raster.getHeight(); line++){
170
			for(int col = 0; col < raster.getWidth(); col++)
171
				System.out.print("(" + (int)(raster.getElemByte(line, col, 0) & 0xff) + " " + (int)(raster.getElemByte(line, col, 1) & 0xff) + " " + (int)(raster.getElemByte(line, col, 2) & 0xff) + ")");
172
			System.out.println();
173
		}
174
	}*/
175

  
176
}
0 177

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestGdalByteHistogram.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
23

  
24
import org.gvsig.fmap.dal.coverage.BaseTestCase;
25
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
26
import org.gvsig.fmap.dal.coverage.exception.HistogramException;
27
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
31
import org.gvsig.raster.impl.datastruct.BufferHistogramImpl;
32
/**
33
 * Test a un histograma de una imagen de 3 bandas de un byte por dato leido con gdal. 
34
 * El test comprueba valores a lo largo de todo el histograma
35
 * 
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class TestGdalByteHistogram extends BaseTestCase {
39
	private String path = baseDir + "histograma.bmp";	
40
	private RasterDataStore       f              = null;	
41
	
42
    public void start() throws Exception {
43
		this.setUp();
44
		this.testStack();
45
	}
46
	
47
    @Override
48
    protected void doSetUp() throws Exception {
49
		System.err.println("TestGdalByteHistogram running...");
50
		try {
51
			super.doSetUp();
52
		} catch (Exception e) {
53
			e.printStackTrace();
54
		}
55
	}
56

  
57
	public void testStack() {
58
		try {
59
			f = manager.open(path);
60
		} catch (NotSupportedExtensionException e) {
61
			return;
62
		} catch (RasterDriverException e) {
63
			e.printStackTrace();
64
		}
65
//		ds = new BufferFactory(f);
66
		BufferHistogram histogram = null;
67
		try {
68
			histogram = ((RasterDataStore)f).getHistogramComputer().getBufferHistogram();
69
			histogram = BufferHistogramImpl.convertHistogramToRGB(histogram);
70
		} catch (ProcessInterruptedException e) {
71
			e.printStackTrace();
72
		} catch (HistogramException e) {
73
			e.printStackTrace();
74
		}
75
		//print(histogram);
76
		resultTest(histogram);
77
	}
78
	
79
	private void resultTest(BufferHistogram histogram) {
80
		for (int i = 0; i <= 255; i++) {
81
			switch (i) {
82
				case 0:
83
					assertEquals((int) histogram.getHistogramValue(0, i), 1);
84
					break;
85
				case 1:
86
					assertEquals((int) histogram.getHistogramValue(0, i), 2);
87
					break;
88
				case 2:
89
					assertEquals((int) histogram.getHistogramValue(0, i), 3);
90
					break;
91
				case 126:
92
					assertEquals((int) histogram.getHistogramValue(0, i), 4);
93
					break;
94
				case 127:
95
					assertEquals((int) histogram.getHistogramValue(0, i), 5);
96
					break;
97
				case 128:
98
					assertEquals((int) histogram.getHistogramValue(0, i), 6);
99
					break;
100
				case 129:
101
					assertEquals((int) histogram.getHistogramValue(0, i), 7);
102
					break;
103
				case 253:
104
					assertEquals((int) histogram.getHistogramValue(0, i), 8);
105
					break;
106
				case 254:
107
					assertEquals((int) histogram.getHistogramValue(0, i), 9);
108
					break;
109
				case 255:
110
					assertEquals((int) histogram.getHistogramValue(0, i), 10);
111
					break;
112
				default:
113
					assertEquals((int) histogram.getHistogramValue(0, i), 0);
114
					break;
115
			}
116
		}
117
	}
118

  
119
	public void print(BufferHistogram histogram) {
120
		for (int i = 0; i < histogram.getNumBands(); i++) {
121
			int cont = 0;
122
			for (int j = 0; j < histogram.getBandLenght(i); j++) {
123
				double var = histogram.getHistogramValue(i, j);
124
				if (var != 0) {
125
					System.out.println(j + ": " + var);
126
					cont += var;
127
				}
128
			}
129
			System.out.println("");
130
			System.out.println(cont + " ");
131
		}
132
	}
133
}
0 134

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestDSIntBufferEcw.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
0 23

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestDSIntBufferMrSID.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
0 23

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestDSDoubleAdjustToExtentGdal.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
23

  
24
import org.gvsig.fmap.dal.coverage.BaseTestCase;
25
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
26
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
27
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
31
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
32

  
33
/**
34
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
35
 * para un raster leido con Gdal con coordenadas pixel. 
36
 * 
37
 * Lee el raster completo y comprueba que los datos leidos sean correctos 
38
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
39
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
40
 * leidos sean correctos.
41
 * 
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 *
44
 */
45
public class TestDSDoubleAdjustToExtentGdal extends BaseTestCase {
46
	private String path = baseDir + "miniRaster25x24.tif";	
47
	private RasterDataStore       f              = null;	
48
	private RasterQuery            query          = null;
49
	protected Buffer               raster         = null;
50
	
51
    public void start() throws Exception {
52
		this.setUp();
53
		this.testStack();
54
	}
55
	
56
    @Override
57
    protected void doSetUp() throws Exception {
58
		System.err.println("TDSDoubleAdjustToExtentGdal running...");
59
		//System.out.println("TestDataSource (Real Coord) Adjust To Extent [Gdal] running...");
60
		try {
61
			super.doSetUp();
62
		} catch (Exception e) {
63
			e.printStackTrace();
64
		}
65
	}
66
	
67
	public void testStack(){
68
		int[] drawableBands = {0, 1, 2};
69
		try {
70
			f = manager.open(path);
71
		} catch (NotSupportedExtensionException e) {
72
			return;
73
		} catch (RasterDriverException e) {
74
			return;
75
		}
76
		query = manager.createQuery();
77
		query.setDrawableBands(drawableBands);
78
		try {
79
			query.setAreaOfInterest(645817.0, 4923851.0, 40, 40);
80
			raster = f.query(query);
81
		} catch (RasterDriverException e) {
82
			e.printStackTrace();
83
		} catch (InvalidSetViewException e) {
84
			e.printStackTrace();
85
		} catch (ProcessInterruptedException e) {
86
			e.printStackTrace();
87
		}
88
		dataTest1();
89
		//print();
90
		
91
		try {
92
			query.setAreaOfInterest(645829.8, 4923840.4, 2, 2);
93
			raster = f.query(query);
94
		} catch (RasterDriverException e) {
95
			e.printStackTrace();
96
		} catch (InvalidSetViewException e) {
97
			e.printStackTrace();
98
		} catch (ProcessInterruptedException e) {
99
			e.printStackTrace();
100
		}
101
		dataTest2();
102
		//print();
103
	}
104
	
105
	private void dataTest2(){
106
		//Upper Left
107
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 64);
108
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 81);
109
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 39);
110
		//Upper Right
111
		assertEquals((int)(raster.getElemByte(0, 1, 0) & 0xff), 64);
112
		assertEquals((int)(raster.getElemByte(0, 1, 1) & 0xff), 81);
113
		assertEquals((int)(raster.getElemByte(0, 1, 2) & 0xff), 39);
114
		//Lower Left
115
		assertEquals((int)(raster.getElemByte(1, 0, 0) & 0xff), 64);
116
		assertEquals((int)(raster.getElemByte(1, 0, 1) & 0xff), 81);
117
		assertEquals((int)(raster.getElemByte(1, 0, 2) & 0xff), 39);
118
		//Lower Right
119
		assertEquals((int)(raster.getElemByte(1, 1, 0) & 0xff), 64);
120
		assertEquals((int)(raster.getElemByte(1, 1, 1) & 0xff), 81);
121
		assertEquals((int)(raster.getElemByte(1, 1, 2) & 0xff), 39);
122
	}
123
	
124
	private void dataTest1(){
125
		//Upper Left
126
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 14);
127
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 14);
128
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 0);
129
		//Upper Right
130
		assertEquals((int)(raster.getElemByte(0, 24, 0) & 0xff), 68);
131
		assertEquals((int)(raster.getElemByte(0, 24, 1) & 0xff), 90);
132
		assertEquals((int)(raster.getElemByte(0, 24, 2) & 0xff), 52);
133
		//Lower Left
134
		assertEquals((int)(raster.getElemByte(23, 0, 0) & 0xff), 129);
135
		assertEquals((int)(raster.getElemByte(23, 0, 1) & 0xff), 122);
136
		assertEquals((int)(raster.getElemByte(23, 0, 2) & 0xff), 106);
137
		//Lower Right
138
		assertEquals((int)(raster.getElemByte(23, 24, 0) & 0xff), 145);
139
		assertEquals((int)(raster.getElemByte(23, 24, 1) & 0xff), 140);
140
		assertEquals((int)(raster.getElemByte(23, 24, 2) & 0xff), 134);
141
		
142
		assertEquals((int)(raster.getElemByte(6, 6, 0) & 0xff), 21);
143
		assertEquals((int)(raster.getElemByte(6, 6, 1) & 0xff), 37);
144
		assertEquals((int)(raster.getElemByte(6, 6, 2) & 0xff), 10);
145
		
146
		assertEquals((int)(raster.getElemByte(6, 23, 0) & 0xff), 91);
147
		assertEquals((int)(raster.getElemByte(6, 23, 1) & 0xff), 105);
148
		assertEquals((int)(raster.getElemByte(6, 23, 2) & 0xff), 92);
149
		
150
		assertEquals((int)(raster.getElemByte(23, 6, 0) & 0xff), 153);
151
		assertEquals((int)(raster.getElemByte(23, 6, 1) & 0xff), 133);
152
		assertEquals((int)(raster.getElemByte(23, 6, 2) & 0xff), 122);
153
		
154
		assertEquals((int)(raster.getElemByte(9, 14, 0) & 0xff), 63);
155
		assertEquals((int)(raster.getElemByte(9, 14, 1) & 0xff), 69);
156
		assertEquals((int)(raster.getElemByte(9, 14, 2) & 0xff), 55);
157
		
158
		assertEquals((int)(raster.getElemByte(6, 13, 0) & 0xff), 70);
159
		assertEquals((int)(raster.getElemByte(6, 13, 1) & 0xff), 78);
160
		assertEquals((int)(raster.getElemByte(6, 13, 2) & 0xff), 55);
161
	}
162
	
163
	/**
164
	 * Imprime todos los pixels de la fuente de datos en RGB
165
	 */
166
	/*private void print(){
167
		IBuffer raster = ds.getRasterBuf();
168
		for(int line = 0; line < raster.getHeight(); line++){
169
			for(int col = 0; col < raster.getWidth(); col++)
170
				System.out.print("(" + (int)(raster.getElemByte(line, col, 0) & 0xff) + " " + (int)(raster.getElemByte(line, col, 1) & 0xff) + " " + (int)(raster.getElemByte(line, col, 2) & 0xff) + ")");
171
			System.out.println();
172
		}
173
	}*/
174

  
175
}
0 176

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestDSDoubleAdjustToExtentBufferEcw.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
23

  
24
import org.gvsig.fmap.dal.coverage.BaseTestCase;
25
import org.gvsig.fmap.dal.coverage.RasterLocator;
26
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
27
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
28
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
29
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
30
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
31
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
32
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
33
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
34
/**
35
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
36
 * para un ECW con coordenadas reales.
37
 *
38
 * Lee el raster completo y comprueba que los datos leidos sean correctos
39
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
40
 * Se lee un ?rea m?s grande que el extent completo del raster para comprobar que el ajuste
41
 * al extent lo hace correctamente.
42
 *
43
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
44
 * leidos sean correctos.
45
 *
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class TestDSDoubleAdjustToExtentBufferEcw extends BaseTestCase {
49
	private String        path    = baseDir + "miniraster30x30.jp2";
50

  
51
	public void start() throws Exception {
52
		this.setUp();
53
		this.testStack();
54
	}
55

  
56
    @Override
57
    protected void doSetUp() throws Exception {
58
		try {
59
			super.doSetUp();
60
		} catch (Exception e) {
61
			e.printStackTrace();
62
		}
63
		System.err.println("TDSDoubleAdjustToExtentBufferEcw running...");
64
	}
65

  
66
	public void testStack() {
67
		RasterDataStore f;
68
		int[] drawableBands = { 0, 1, 2 };
69
		try {
70
			deleteRMF(path);
71
			f = manager.open(path);
72
		} catch (RasterDriverException e) {
73
			return;
74
		} catch (NotSupportedExtensionException e) {
75
			return;
76
		}
77
		RasterQuery query = manager.createQuery();
78
		query.setDrawableBands(drawableBands);
79
		Buffer buf = null;
80
		//Se selecciona un ?rea mayor que el extent para probar que lo ajusta a este
81
		try {
82
			Extent extent = RasterLocator.getManager().getDataStructFactory().createExtent(645860.0, 4923870.0, 645986.0, 4923744.0);
83
			query.setAreaOfInterest(extent, 10, 10);
84
			buf = f.query(query);
85
		} catch (RasterDriverException e) {
86
			e.printStackTrace();
87
		} catch (InvalidSetViewException e) {
88
			e.printStackTrace();
89
		} catch (ProcessInterruptedException e) {
90
			e.printStackTrace();
91
		}
92
//		print(ds.getRasterBuf());
93
		//dataTest1(buf);
94

  
95
		try {
96
			Extent extent = RasterLocator.getManager().getDataStructFactory().createExtent(645860.0, 4923870.0, 645986.0, 4923744.0);
97
			query.setAreaOfInterest(extent, 2, 2);
98
			buf = f.query(query);
99
		} catch (RasterDriverException e) {
100
			e.printStackTrace();
101
		} catch (InvalidSetViewException e) {
102
			e.printStackTrace();
103
		} catch (ProcessInterruptedException e) {
104
			e.printStackTrace();
105
		}
106
//		print(ds.getRasterBuf());
107
		dataTest2(buf);
108
	}
109

  
110
	@SuppressWarnings("unused")
111
	private void dataTest1(Buffer raster) {
112
		int band0[] = { 43, 14, 87, 166, 174, 109, 90, 93, 190, 143, 85, 93, 103, 112, 138, 94, 138, 192, 180, 196, 99, 209, 41, 98, 168, 170, 89, 141, 158, 199, 108, 71, 67, 92, 131, 176, 243, 98, 163, 141, 157, 170, 94, 159, 233, 114, 144, 62, 147, 173, 159, 173, 184, 94, 56, 18, 69, 78, 83, 115, 95, 37, 80, 57, 68, 68, 55, 59, 58, 101, 69, 44, 24, 58, 115, 40, 58, 56, 68, 111, 84, 117, 55, 88, 170, 135, 169, 99, 74, 42, 114, 223, 171, 67, 216, 104, 167, 83, 66, 45 };
113
		int band1[] = { 53, 15, 109, 154, 164, 111, 109, 93, 189, 151, 89, 102, 107, 111, 142, 100, 143, 195, 178, 190, 100, 192, 61, 108, 154, 172, 99, 149, 160, 206, 122, 74, 81, 94, 136, 195, 248, 105, 173, 141, 158, 162, 98, 158, 226, 114, 132, 66, 150, 176, 168, 172, 175, 105, 82, 39, 85, 89, 73, 104, 92, 51, 80, 71, 88, 84, 71, 74, 68, 106, 82, 62, 37, 74, 129, 49, 78, 67, 89, 126, 100, 132, 71, 107, 164, 145, 154, 108, 85, 48, 130, 210, 164, 66, 209, 115, 160, 85, 90, 61 };
114
		int band2[] = { 26, 11, 82, 145, 165, 97, 86, 71, 191, 135, 74, 75, 85, 110, 117, 82, 115, 186, 179, 183, 91, 181, 43, 85, 139, 178, 78, 133, 152, 206, 98, 61, 71, 109, 118, 181, 244, 82, 144, 117, 144, 159, 83, 155, 231, 98, 108, 60, 136, 163, 146, 170, 162, 111, 102, 41, 62, 60, 64, 68, 97, 26, 74, 50, 64, 70, 47, 48, 56, 70, 54, 35, 19, 50, 91, 35, 48, 52, 62, 101, 73, 91, 35, 80, 140, 119, 140, 91, 58, 36, 112, 202, 146, 66, 192, 81, 131, 71, 63, 37 };
115
		compareRaster(raster, band0, band1, band2);
116
	}
117

  
118
	private void dataTest2(Buffer raster) {
119
		int band0[] = { 43, 109, 159, 18 };
120
		int band1[] = { 53, 111, 168, 39 };
121
		int band2[] = { 26, 97, 146, 41 };
122
		compareRaster(raster, band0, band1, band2);
123
	}
124

  
125
	public void compareRaster(Buffer raster, int band0[], int band1[], int band2[]) {
126
		int cont = 0;
127
		for (int line = 0; line < raster.getHeight(); line++)
128
			for (int col = 0; col < raster.getWidth(); col++) {
129
				assertEquals((raster.getElemByte(line, col, 0) & 0xff), band0[cont]);
130
				assertEquals((raster.getElemByte(line, col, 1) & 0xff), band1[cont]);
131
				assertEquals((raster.getElemByte(line, col, 2) & 0xff), band2[cont]);
132
				cont++;
133
			}
134
	}
135

  
136
	/**
137
	 * Imprime todos los pixels de la fuente de datos en RGB
138
	 */
139
	public void print(Buffer raster) {
140
		System.out.println("");
141
		for (int band = 0; band < 3; band++) {
142
			System.out.print("int band" + band + "[] = { ");
143
			int cont = 0;
144
			for (int line = 0; line < raster.getHeight(); line++)
145
				for (int col = 0; col < raster.getWidth(); col++) {
146
					if (cont != 0)
147
						System.out.print(", ");
148
					System.out.print(((raster.getElemByte(line, col, band) & 0xff)));
149
					cont++;
150
				}
151
			System.out.println("};");
152
		}
153
	}
154
}
0 155

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestDSDoubleAdjustToExtentBufferMrSID.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
0 23

  
org.gvsig.raster/tags/org.gvsig.raster-2.2.70/org.gvsig.raster.main/src/test/java/org/gvsig/fmap/dal/coverage/buffer/TestDSIntEcw.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.buffer;
23

  
24
import org.gvsig.fmap.dal.coverage.BaseTestCase;
25
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
26
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
27
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
28
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
31
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
32

  
33
/**
34
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
35
 * para un ECW con coordenadas pixel. 
36
 * 
37
 * Lee el raster completo y comprueba que los datos leidos sean correctos 
38
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
39
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
40
 * leidos sean correctos.
41
 * 
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 *
44
 */
45
public class TestDSIntEcw extends BaseTestCase {
46
	private String path = baseDir + "miniraster30x30.jp2";	
47
	private RasterDataStore       f              = null;	
48
	private RasterQuery            query          = null;
49
	protected Buffer               raster         = null;
50
	
51
    public void start() throws Exception {
52
		this.setUp();
53
		this.testStack();
54
	}
55
	
56
    @Override
57
    protected void doSetUp() throws Exception {
58
		System.err.println("TDSIntEcw running...");
59
		//System.out.println("TestDataSource (Pixel Coord) [Ecw] running...");
60
		try {
61
			super.doSetUp();
62
		} catch (Exception e) {
63
			e.printStackTrace();
64
		}
65
	}
66
	
67
	public void testStack(){
68
		int[] drawableBands = {0, 1, 2};
69
		try {
70
			f = manager.open(path);
71
		} catch (NotSupportedExtensionException e) {
72
			return;
73
		} catch (RasterDriverException e) {
74
			return;
75
		}
76
		query = manager.createQuery();
77
		query.setDrawableBands(drawableBands);
78
		try {
79
			query.setAreaOfInterest(0, 0, 30, 30);
80
			raster = f.query(query);
81
		} catch (InvalidSetViewException e) {
82
			e.printStackTrace();
83
		} catch (ProcessInterruptedException e) {
84
			e.printStackTrace();
85
		} catch (RasterDriverException e) {
86
			e.printStackTrace();
87
		}
88
		dataTest1();
89
		//print();
90
		
91
		try {
92
			query.setAreaOfInterest(10, 10, 2, 2);
93
			raster = f.query(query);
94
		} catch (InvalidSetViewException e) {
95
			e.printStackTrace();
96
		} catch (ProcessInterruptedException e) {
97
			e.printStackTrace();
98
		} catch (RasterDriverException e) {
99
			e.printStackTrace();
100
		}
101
		dataTest2();
102
		//print();
103
	}
104
	
105
	private void dataTest2(){
106
		//Upper Left
107
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 123);
108
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 147);
109
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 111);
110
		//Upper Right
111
		assertEquals((int)(raster.getElemByte(0, 1, 0) & 0xff), 117);
112
		assertEquals((int)(raster.getElemByte(0, 1, 1) & 0xff), 148);
113
		assertEquals((int)(raster.getElemByte(0, 1, 2) & 0xff), 91);
114
		//Lower Left
115
		assertEquals((int)(raster.getElemByte(1, 0, 0) & 0xff), 187);
116
		assertEquals((int)(raster.getElemByte(1, 0, 1) & 0xff), 190);
117
		assertEquals((int)(raster.getElemByte(1, 0, 2) & 0xff), 173);
118
		//Lower Right
119
		assertEquals((int)(raster.getElemByte(1, 1, 0) & 0xff), 214);
120
		assertEquals((int)(raster.getElemByte(1, 1, 1) & 0xff), 213);
121
		assertEquals((int)(raster.getElemByte(1, 1, 2) & 0xff), 211);
122
	}
123
	
124
	private void dataTest1(){
125
		//Upper Left
126
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 43);
127
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 53);
128
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 26);
129
		//Upper Right
130
		assertEquals((int)(raster.getElemByte(0, 29, 0) & 0xff), 255);
131
		assertEquals((int)(raster.getElemByte(0, 29, 1) & 0xff), 252);
132
		assertEquals((int)(raster.getElemByte(0, 29, 2) & 0xff), 246);
133
		//Lower Left
134
		assertEquals((int)(raster.getElemByte(29, 0, 0) & 0xff), 175);
135
		assertEquals((int)(raster.getElemByte(29, 0, 1) & 0xff), 175);
136
		assertEquals((int)(raster.getElemByte(29, 0, 2) & 0xff), 147);
137
		//Lower Right
138
		assertEquals((int)(raster.getElemByte(29, 29, 0) & 0xff), 126);
139
		assertEquals((int)(raster.getElemByte(29, 29, 1) & 0xff), 134);
140
		assertEquals((int)(raster.getElemByte(29, 29, 2) & 0xff), 111);
141
		
142
		assertEquals((int)(raster.getElemByte(6, 6, 0) & 0xff), 61);
143
		assertEquals((int)(raster.getElemByte(6, 6, 1) & 0xff), 84);
144
		assertEquals((int)(raster.getElemByte(6, 6, 2) & 0xff), 64);
145
		
146
		assertEquals((int)(raster.getElemByte(6, 23, 0) & 0xff), 168);
147
		assertEquals((int)(raster.getElemByte(6, 23, 1) & 0xff), 171);
148
		assertEquals((int)(raster.getElemByte(6, 23, 2) & 0xff), 164);
149
		
150
		assertEquals((int)(raster.getElemByte(23, 6, 0) & 0xff), 46);
151
		assertEquals((int)(raster.getElemByte(23, 6, 1) & 0xff), 64);
152
		assertEquals((int)(raster.getElemByte(23, 6, 2) & 0xff), 26);
153
		
154
		assertEquals((int)(raster.getElemByte(23, 23, 0) & 0xff), 54);
155
		assertEquals((int)(raster.getElemByte(23, 23, 1) & 0xff), 57);
156
		assertEquals((int)(raster.getElemByte(23, 23, 2) & 0xff), 36);
157
		
158
		assertEquals((int)(raster.getElemByte(11, 13, 0) & 0xff), 203);
159
		assertEquals((int)(raster.getElemByte(11, 13, 1) & 0xff), 182);
160
		assertEquals((int)(raster.getElemByte(11, 13, 2) & 0xff), 181);
161
		
162
		assertEquals((int)(raster.getElemByte(22, 21, 0) & 0xff), 71);
163
		assertEquals((int)(raster.getElemByte(22, 21, 1) & 0xff), 97);
164
		assertEquals((int)(raster.getElemByte(22, 21, 2) & 0xff), 62);
165
	}
166
	
167
	/**
168
	 * Imprime todos los pixels de la fuente de datos en RGB
169
	 */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff