Revision 26348 branches/v2_0_0_prep/extensions/extRemoteSensing/src-test/org/gvsig/remotesensing/processtest/TTasseledCapProcess.java
TTasseledCapProcess.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Iba?ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha) |
|
34 |
* Campus Universitario s/n |
|
35 |
* 02071 Alabacete |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 967 599 200 |
|
39 |
*/ |
|
40 |
|
|
1 | 41 |
package org.gvsig.remotesensing.processtest; |
2 | 42 |
|
3 | 43 |
import junit.framework.TestCase; |
... | ... | |
2 | 42 |
|
43 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
|
3 | 44 |
import org.gvsig.raster.RasterLibrary; |
4 | 45 |
import org.gvsig.raster.buffer.BufferFactory; |
5 | 46 |
import org.gvsig.raster.buffer.RasterBufferInvalidAccessException; |
47 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
|
6 | 48 |
import org.gvsig.raster.dataset.IBuffer; |
49 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
|
7 | 50 |
import org.gvsig.raster.dataset.RasterDataset; |
51 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
|
52 |
import org.gvsig.raster.grid.Grid; |
|
53 |
import org.gvsig.remotesensing.tasseledcap.TasseledCapProcess; |
|
8 | 54 |
|
55 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
|
9 | 56 |
|
57 |
|
|
10 | 58 |
/** |
... | ... | |
17 | 65 |
* detallan a continuaci?n calculados previamente con Envi. |
18 | 66 |
* Para el caso de la Imagen LandSat TM, se compara el resultado con Imagen: LandSatTM_Envi |
19 | 67 |
* Para el caso de la Imagen LandSat ETM, se compara el resultado con Imagen LandSatETM_Envi |
20 |
* Para el caso de la Imagen LandSat MSS, se compara el resultado con Imagen LandSatMSS_Envi |
|
68 |
* Para el caso de la Imagen LandSat MSS, se compara el resultado con Imagen LandSatMSS_Envi.tif
|
|
21 | 69 |
* |
22 | 70 |
* @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es) |
23 | 71 |
* */ |
... | ... | |
29 | 77 |
private String path2 = baseDir + "LandSatTM_Envi"; |
30 | 78 |
private String path3 = baseDir + "LandSatETM_Envi"; |
31 | 79 |
private String path4 = baseDir + "LandSatMSS_Envi"; |
32 |
private RasterDataset f1,f2,f3,f4 = null;
|
|
33 |
private BufferFactory ds1,ds2,ds3,ds4 = null;
|
|
34 |
|
|
80 |
private RasterDataset f2,f3,f4 = null; |
|
81 |
private BufferFactory ds2,ds3,ds4 = null; |
|
82 |
private FLyrRasterSE lyr1 = null; |
|
35 | 83 |
|
36 | 84 |
static{ |
37 | 85 |
RasterLibrary.wakeUp(); |
... | ... | |
39 | 87 |
|
40 | 88 |
public void start() { |
41 | 89 |
this.setUp(); |
42 |
//this.testStack();
|
|
90 |
this.testStack();
|
|
43 | 91 |
} |
44 | 92 |
|
45 | 93 |
public void setUp() { |
46 |
/*System.err.println("TTasseledCapProcess running..."); |
|
94 |
System.err.println("TTasseledCapProcess running..."); |
|
95 |
|
|
47 | 96 |
try { |
48 |
f1 = RasterDataset.open(null,path1); |
|
97 |
lyr1 = FLyrRasterSE.createLayer( |
|
98 |
path1, |
|
99 |
path1, |
|
100 |
null |
|
101 |
); |
|
102 |
} catch (LoadLayerException e) { |
|
103 |
System.out.print("Error en la construcci?n de la capa"); |
|
104 |
} |
|
105 |
|
|
106 |
try { |
|
49 | 107 |
f2= RasterDataset.open(null,path2); |
50 | 108 |
f3 = RasterDataset.open(null,path3); |
51 | 109 |
f4= RasterDataset.open(null, path4); |
52 |
|
|
53 |
|
|
54 | 110 |
} catch (NotSupportedExtensionException e) { |
55 | 111 |
e.printStackTrace(); |
56 | 112 |
} catch (RasterDriverException e) { |
57 | 113 |
// TODO Auto-generated catch block |
58 | 114 |
e.printStackTrace(); |
59 | 115 |
} |
60 |
ds1 = new BufferFactory(f1); |
|
61 | 116 |
ds2= new BufferFactory (f2); |
62 | 117 |
ds3= new BufferFactory (f3); |
63 | 118 |
ds4= new BufferFactory (f4); |
... | ... | |
66 | 121 |
|
67 | 122 |
public void testStack() { |
68 | 123 |
|
69 |
Grid g=null; |
|
70 | 124 |
Grid enviResultTM=null; |
71 | 125 |
Grid enviResultETM=null; |
72 | 126 |
Grid enviResultMSS=null; |
73 | 127 |
|
74 | 128 |
try { |
75 |
g = new Grid(ds1); |
|
76 | 129 |
enviResultTM= new Grid(ds2); |
77 | 130 |
enviResultETM= new Grid(ds3); |
78 | 131 |
enviResultMSS= new Grid (ds4); |
... | ... | |
82 | 135 |
} |
83 | 136 |
|
84 | 137 |
|
85 |
*//**Caso LandSat TM*//* |
|
86 |
TasseledCapProcess tC= new TasseledCapProcess(); |
|
87 |
tC.addParam("filename",); |
|
88 |
tC.run(); |
|
89 |
try { |
|
90 |
compare(tC.getBufferResult(),enviResultTM.getRasterBuf()); |
|
91 |
} catch (RasterBufferInvalidAccessException e) { |
|
92 |
e.printStackTrace(); |
|
93 |
} |
|
138 |
// **Caso LandSat MSS |
|
139 |
TasseledCapProcess mssProcess= new TasseledCapProcess(); |
|
140 |
mssProcess.addParam("bands", new int[]{0,1,2,3}); |
|
141 |
mssProcess.addParam("layer",lyr1); |
|
142 |
mssProcess.addParam("type",new Integer(0)); |
|
143 |
mssProcess.run(); |
|
144 |
//try { |
|
145 |
// compare(mssProcess.getBufferResult(),enviResultMSS.getRasterBuf()); |
|
146 |
//} catch (RasterBufferInvalidAccessException e) { |
|
147 |
// e.printStackTrace(); |
|
148 |
//} |
|
94 | 149 |
|
95 | 150 |
|
96 |
*//**Caso LandSat ETM*//* |
|
97 | 151 |
|
98 |
tC= new TasseledCapProcess(ds1.getDataSource(),null,2,"LandSat ETM"); |
|
99 |
tC.run(); |
|
152 |
//**Caso LandSat TM |
|
153 |
TasseledCapProcess tmProcess= new TasseledCapProcess(); |
|
154 |
tmProcess.addParam("bands", new int[]{0,1,2,3,4,5}); |
|
155 |
tmProcess.addParam("layer",lyr1); |
|
156 |
tmProcess.addParam("type",new Integer(1)); |
|
157 |
tmProcess.run(); |
|
100 | 158 |
try { |
101 |
compare(tC.getBufferResult(),enviResultETM.getRasterBuf());
|
|
159 |
compare(tmProcess.getBufferResult(),enviResultTM.getRasterBuf());
|
|
102 | 160 |
} catch (RasterBufferInvalidAccessException e) { |
103 | 161 |
e.printStackTrace(); |
104 | 162 |
} |
105 | 163 |
|
106 |
|
|
107 |
*//**Caso de LandSat MSS*//* |
|
164 |
|
|
165 |
//**Caso LandSat ETM |
|
166 |
TasseledCapProcess etmProcess= new TasseledCapProcess(); |
|
167 |
etmProcess.addParam("bands", new int[]{0,1,2,3,4,5}); |
|
168 |
etmProcess.addParam("layer",lyr1); |
|
169 |
etmProcess.addParam("type",new Integer(2)); |
|
170 |
etmProcess.run(); |
|
108 | 171 |
try { |
109 |
g = new Grid(ds1,new int[]{0,1,2,3}); |
|
110 |
} catch (RasterBufferInvalidException e1) { |
|
111 |
e1.printStackTrace(); |
|
112 |
} |
|
113 |
tC= new TasseledCapProcess(ds1.getDataSource(),null,0,"LandSat MSS"); |
|
114 |
tC.run(); |
|
115 |
*//** La imagen LandSat MSS No se compara porque los coeficientes utilizados por ENVI no son similares |
|
116 |
a los de la matriz de coeficientes proporcionados por Jose *//* |
|
117 |
try { |
|
118 |
|
|
119 |
//compare(tC.getGridResult(),enviResultMSS); |
|
120 |
|
|
172 |
compare(etmProcess.getBufferResult(),enviResultETM.getRasterBuf()); |
|
121 | 173 |
} catch (RasterBufferInvalidAccessException e) { |
122 | 174 |
e.printStackTrace(); |
123 | 175 |
} |
124 |
*/ |
|
176 |
|
|
177 |
|
|
125 | 178 |
} |
126 |
|
|
127 | 179 |
|
128 |
/**Metodo que compara celda a celda cada uno de los valores de dos grids. |
|
129 |
* Para imagenes LandSat ETM, la sexta banda no se compara porque envi realiza una transformacion
|
|
130 |
* para evitar los numeros negativos */
|
|
180 |
//**Metodo que compara celda a celda cada uno de los valores de dos grids.
|
|
181 |
// Para imagenes LandSat ETM, la sexta banda no se compara porque envi realiza una transformacion
|
|
182 |
// para evitar los numeros negativos *//*
|
|
131 | 183 |
private void compare(IBuffer buffer, IBuffer buffer2) throws RasterBufferInvalidAccessException { |
132 | 184 |
assertEquals(buffer.getBandCount(),buffer2.getBandCount()); |
133 | 185 |
for(int band=0; band<buffer.getBandCount();band++){ |
... | ... | |
141 | 193 |
|
142 | 194 |
} |
143 | 195 |
} |
144 |
|
|
145 | 196 |
} |
Also available in: Unified diff