gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.main / src / test / java / org / gvsig / fmap / dal / coverage / dataset / TestStatisticMultiFile.java @ 2443
History | View | Annotate | Download (6.35 KB)
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.dataset; |
23 |
|
24 |
import java.io.File; |
25 |
|
26 |
import org.gvsig.fmap.dal.DALLocator; |
27 |
import org.gvsig.fmap.dal.DataManager; |
28 |
import org.gvsig.fmap.dal.coverage.BaseTestCase; |
29 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
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.store.RasterDataStore; |
34 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
35 |
import org.gvsig.fmap.dal.exception.InitializeException; |
36 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
37 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
38 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
39 |
import org.gvsig.raster.gdal.io.GdalProvider; |
40 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
41 |
import org.gvsig.raster.impl.store.DefaultMultiRasterStore; |
42 |
/**
|
43 |
* Prueba el calculo de estadisticas para un dataset con multiples ficheros.
|
44 |
* Comprueba que los valores obtenidos en las estadisticas son correctos.
|
45 |
*
|
46 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
47 |
*/
|
48 |
public class TestStatisticMultiFile extends BaseTestCase { |
49 |
private String path1 = baseDir + "band1-30x28byte.tif"; |
50 |
private String path2 = baseDir + "band2-30x28byte.tif"; |
51 |
private String path3 = baseDir + "band3-30x28byte.tif"; |
52 |
|
53 |
private DefaultRasterProvider f1 = null; |
54 |
private DefaultRasterProvider f2 = null; |
55 |
private DefaultRasterProvider f3 = null; |
56 |
protected Buffer raster = null; |
57 |
|
58 |
public void start() throws Exception { |
59 |
this.setUp();
|
60 |
this.testStack();
|
61 |
} |
62 |
|
63 |
protected void doSetUp() throws Exception { |
64 |
System.err.println("TestStatisticMultiFile running..."); |
65 |
|
66 |
try {
|
67 |
super.doSetUp();
|
68 |
} catch (Exception e) { |
69 |
e.printStackTrace(); |
70 |
} |
71 |
} |
72 |
|
73 |
public void testStack() { |
74 |
DefaultMultiRasterStore grmf = new DefaultMultiRasterStore();
|
75 |
|
76 |
try {
|
77 |
deleteRMF(path1); |
78 |
deleteRMF(path2); |
79 |
deleteRMF(path3); |
80 |
DataManager dm = DALLocator.getDataManager(); |
81 |
|
82 |
FilesystemStoreParameters p = (FilesystemStoreParameters)dm.createStoreParameters(GdalProvider.NAME); |
83 |
p.setFile(new File(path1)); |
84 |
f1 = (DefaultRasterProvider)loadProvider(p, (DataStoreProviderServices)grmf); |
85 |
|
86 |
FilesystemStoreParameters p1 = (FilesystemStoreParameters)dm.createStoreParameters(GdalProvider.NAME); |
87 |
p.setFile(new File(path2)); |
88 |
f2 = (DefaultRasterProvider)loadProvider(p1, (DataStoreProviderServices)grmf); |
89 |
|
90 |
FilesystemStoreParameters p2 = (FilesystemStoreParameters)dm.createStoreParameters(GdalProvider.NAME); |
91 |
p.setFile(new File(path3)); |
92 |
f3 = (DefaultRasterProvider)loadProvider(p2, (DataStoreProviderServices)grmf); |
93 |
|
94 |
} catch (ProviderNotRegisteredException e) {
|
95 |
e.printStackTrace(); |
96 |
} catch (InitializeException e) {
|
97 |
e.printStackTrace(); |
98 |
} |
99 |
|
100 |
try {
|
101 |
grmf.addDataStore(f1); |
102 |
grmf.addDataStore(f2); |
103 |
grmf.addDataStore(f3); |
104 |
} catch (OperationNotSupportedException e1) { |
105 |
// TODO Auto-generated catch block
|
106 |
e1.printStackTrace(); |
107 |
} |
108 |
try {
|
109 |
grmf.getStatistics().calculate(); |
110 |
} catch (FileNotOpenException e) {
|
111 |
e.printStackTrace(); |
112 |
} catch (RasterDriverException e) {
|
113 |
e.printStackTrace(); |
114 |
} catch (ProcessInterruptedException e) {
|
115 |
e.printStackTrace(); |
116 |
} |
117 |
// print(grmf);
|
118 |
dataTestB1(grmf.getStatistics()); |
119 |
dataTestB2(grmf.getStatistics()); |
120 |
dataTestB3(grmf.getStatistics()); |
121 |
} |
122 |
|
123 |
private void dataTestB1(Statistics stats){ |
124 |
assertEquals(new Double(stats.getMaxByteUnsigned()[0]), new Double(249.0)); |
125 |
assertEquals(new Double(stats.getMinByteUnsigned()[0]), new Double(82.0)); |
126 |
assertEquals(new Double(stats.getSecondMaxByteUnsigned()[0]), new Double(211.0)); |
127 |
assertEquals(new Double(stats.getSecondMinByteUnsigned()[0]), new Double(83.0)); |
128 |
assertEquals((int)stats.getMean()[0], 119); |
129 |
assertEquals((int)stats.getVariance()[0], 584); |
130 |
} |
131 |
|
132 |
private void dataTestB2(Statistics stats){ |
133 |
assertEquals(new Double(stats.getMaxByteUnsigned()[1]), new Double(234.0)); |
134 |
assertEquals(new Double(stats.getMinByteUnsigned()[1]), new Double(49.0)); |
135 |
assertEquals(new Double(stats.getSecondMaxByteUnsigned()[1]), new Double(216.0)); |
136 |
assertEquals(new Double(stats.getSecondMinByteUnsigned()[1]), new Double(50.0)); |
137 |
assertEquals((int)stats.getMean()[1], 102); |
138 |
assertEquals((int)stats.getVariance()[1], 1107); |
139 |
} |
140 |
|
141 |
private void dataTestB3(Statistics stats){ |
142 |
assertEquals(new Double(stats.getMaxByteUnsigned()[2]), new Double(255.0)); |
143 |
assertEquals(new Double(stats.getMinByteUnsigned()[2]), new Double(28.0)); |
144 |
assertEquals(new Double(stats.getSecondMaxByteUnsigned()[2]), new Double(250.0)); |
145 |
assertEquals(new Double(stats.getSecondMinByteUnsigned()[2]), new Double(34.0)); |
146 |
assertEquals((int)stats.getMean()[2], 115); |
147 |
assertEquals((int)stats.getVariance()[2], 2833); |
148 |
} |
149 |
|
150 |
public void print(RasterDataStore grmf) { |
151 |
for (int iBand = 0; iBand < grmf.getStatistics().getBandCount(); iBand++) { |
152 |
System.out.println("Band " + iBand); |
153 |
System.out.println("...Max: " + grmf.getStatistics().getMax()[iBand]); |
154 |
System.out.println("...Min: " + grmf.getStatistics().getMin()[iBand]); |
155 |
System.out.println("...SecondMax: " + grmf.getStatistics().getSecondMax()[iBand]); |
156 |
System.out.println("...SecondMin: " + grmf.getStatistics().getSecondMin()[iBand]); |
157 |
System.out.println("...Mean: " + grmf.getStatistics().getMean()[iBand]); |
158 |
System.out.println("...Variance: " + grmf.getStatistics().getVariance()[iBand]); |
159 |
} |
160 |
} |
161 |
} |