root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridTools / gridBasicStats / GridBasicStatsAlgorithm.java @ 59
History | View | Annotate | Download (5.13 KB)
1 |
package es.unex.sextante.gridTools.gridBasicStats; |
---|---|
2 |
|
3 |
import java.text.DecimalFormat; |
4 |
|
5 |
import es.unex.sextante.core.GeoAlgorithm; |
6 |
import es.unex.sextante.core.Sextante; |
7 |
import es.unex.sextante.dataObjects.IRasterLayer; |
8 |
import es.unex.sextante.docEngines.html.HTMLDoc; |
9 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
10 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
11 |
import es.unex.sextante.math.simpleStats.SimpleStats; |
12 |
|
13 |
public class GridBasicStatsAlgorithm |
14 |
extends
|
15 |
GeoAlgorithm { |
16 |
|
17 |
public static final String INPUT = "INPUT"; |
18 |
public static final String STATS = "STATS"; |
19 |
public static final String MEAN = "MEAN"; |
20 |
public static final String MEAN_SQUARED = "MEAN_SQUARED"; |
21 |
public static final String MIN = "MIN"; |
22 |
public static final String MAX = "MAX"; |
23 |
public static final String VARIANCE = "VARIANCE"; |
24 |
public static final String SUM = "SUM"; |
25 |
public static final String COEF_OF_VARIATION = "COEF_OF_VARIATION"; |
26 |
public static final String VALID_CELLS = "VALID_CELLS"; |
27 |
public static final String NO_DATA_CELLS = "NO_DATA_CELLS"; |
28 |
|
29 |
|
30 |
@Override
|
31 |
public void defineCharacteristics() { |
32 |
|
33 |
setName(Sextante.getText("Basic_statistics"));
|
34 |
setGroup(Sextante.getText("Basic_tools_for_raster_layers"));
|
35 |
setUserCanDefineAnalysisExtent(false);
|
36 |
|
37 |
try {
|
38 |
m_Parameters.addInputRasterLayer(INPUT, Sextante.getText("Layer"), true); |
39 |
addOutputText(STATS, Sextante.getText("Statistics"));
|
40 |
addOutputNumericalValue(MEAN, Sextante.getText("Mean_value"));
|
41 |
addOutputNumericalValue(MEAN_SQUARED, Sextante.getText("Mean_squared_value"));
|
42 |
addOutputNumericalValue(MIN, Sextante.getText("Minimum_value"));
|
43 |
addOutputNumericalValue(MAX, Sextante.getText("Maximum_value"));
|
44 |
addOutputNumericalValue(VARIANCE, Sextante.getText("Variance"));
|
45 |
addOutputNumericalValue(SUM, Sextante.getText("Total_sum"));
|
46 |
addOutputNumericalValue(COEF_OF_VARIATION, Sextante.getText("Coefficient_of_variation"));
|
47 |
addOutputNumericalValue(VALID_CELLS, Sextante.getText("Valid_data_cells"));
|
48 |
addOutputNumericalValue(NO_DATA_CELLS, Sextante.getText("No_data_cells"));
|
49 |
|
50 |
} |
51 |
catch (final RepeatedParameterNameException e) { |
52 |
Sextante.addErrorToLog(e); |
53 |
} |
54 |
|
55 |
} |
56 |
|
57 |
|
58 |
@Override
|
59 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
60 |
|
61 |
int x, y;
|
62 |
int iNX, iNY;
|
63 |
int iNoDataCells = 0; |
64 |
double dValue;
|
65 |
IRasterLayer input; |
66 |
final SimpleStats stats = new SimpleStats(); |
67 |
|
68 |
input = m_Parameters.getParameterValueAsRasterLayer(INPUT); |
69 |
input.setFullExtent(); |
70 |
iNX = input.getNX(); |
71 |
iNY = input.getNY(); |
72 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
73 |
for (x = 0; x < iNX; x++) { |
74 |
dValue = input.getCellValueAsDouble(x, y); |
75 |
if (!input.isNoDataValue(dValue)) {
|
76 |
stats.addValue(dValue); |
77 |
} |
78 |
else {
|
79 |
iNoDataCells++; |
80 |
} |
81 |
} |
82 |
|
83 |
} |
84 |
if (m_Task.isCanceled()) {
|
85 |
return false; |
86 |
} |
87 |
|
88 |
final DecimalFormat df = new DecimalFormat("##.###"); |
89 |
final HTMLDoc doc = new HTMLDoc(); |
90 |
doc.open(Sextante.getText("Statistics"));
|
91 |
doc.addHeader(Sextante.getText("Basic_statistics"), 2); |
92 |
doc.startUnorderedList(); |
93 |
doc.addListElement(Sextante.getText("Mean_value") + ": " + df.format(stats.getMean())); |
94 |
doc.addListElement(Sextante.getText("Mean_squared_value") + ": " + df.format(stats.getRMS())); |
95 |
doc.addListElement(Sextante.getText("Minimum_value") + ": " + df.format(stats.getMin())); |
96 |
doc.addListElement(Sextante.getText("Maximum_value") + ": " + df.format(stats.getMax())); |
97 |
doc.addListElement(Sextante.getText("Variance") + ": " + df.format(stats.getVariance())); |
98 |
doc.addListElement(Sextante.getText("Total_sum") + ": " + df.format(stats.getSum())); |
99 |
doc.addListElement(Sextante.getText("Coefficient_of_variation") + ": " + df.format(stats.getCoeffOfVar())); |
100 |
doc.addListElement(Sextante.getText("Valid_data_cells") + ": " + Integer.toString(stats.getCount())); |
101 |
doc.addListElement(Sextante.getText("No_data_cells") + ": " + Integer.toString((iNX * iNY) - stats.getCount())); |
102 |
doc.closeUnorderedList(); |
103 |
doc.close(); |
104 |
|
105 |
addOutputText(STATS, Sextante.getText("Statistics") + "[" + input.getName() + "]", doc.getHTMLCode()); |
106 |
|
107 |
addOutputNumericalValue(MEAN, stats.getMean()); |
108 |
addOutputNumericalValue(MEAN_SQUARED, stats.getRMS()); |
109 |
addOutputNumericalValue(MIN, stats.getMin()); |
110 |
addOutputNumericalValue(MAX, stats.getMax()); |
111 |
addOutputNumericalValue(VARIANCE, stats.getVariance()); |
112 |
addOutputNumericalValue(SUM, stats.getSum()); |
113 |
addOutputNumericalValue(COEF_OF_VARIATION, stats.getCoeffOfVar()); |
114 |
addOutputNumericalValue(VALID_CELLS, stats.getCount()); |
115 |
addOutputNumericalValue(NO_DATA_CELLS, (iNX * iNY) - stats.getCount()); |
116 |
|
117 |
return true; |
118 |
|
119 |
} |
120 |
|
121 |
} |