root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridStatistics / base / MultiGridStatsExtendedBaseAlgorithm.java @ 59
History | View | Annotate | Download (4.42 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.gridStatistics.base; |
4 |
|
5 |
import java.awt.image.DataBuffer; |
6 |
import java.util.ArrayList; |
7 |
|
8 |
import es.unex.sextante.additionalInfo.AdditionalInfoMultipleInput; |
9 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
10 |
import es.unex.sextante.core.GeoAlgorithm; |
11 |
import es.unex.sextante.core.Sextante; |
12 |
import es.unex.sextante.dataObjects.IRasterLayer; |
13 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
14 |
import es.unex.sextante.exceptions.NullParameterValueException; |
15 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
16 |
import es.unex.sextante.exceptions.WrongParameterIDException; |
17 |
import es.unex.sextante.exceptions.WrongParameterTypeException; |
18 |
|
19 |
|
20 |
public abstract class MultiGridStatsExtendedBaseAlgorithm |
21 |
extends
|
22 |
GeoAlgorithm { |
23 |
|
24 |
public static final String INPUT = "INPUT"; |
25 |
public static final String VALUE = "VALUE"; |
26 |
public static final String FORCE_NODATA = "NODATA"; |
27 |
public static final String RESULT = "RESULT"; |
28 |
|
29 |
protected double NO_DATA; |
30 |
protected double m_dValue; |
31 |
|
32 |
|
33 |
@Override
|
34 |
public void defineCharacteristics() { |
35 |
|
36 |
setUserCanDefineAnalysisExtent(true);
|
37 |
|
38 |
try {
|
39 |
m_Parameters.addMultipleInput(INPUT, Sextante.getText("Layers"), AdditionalInfoMultipleInput.DATA_TYPE_RASTER, true); |
40 |
m_Parameters.addNumericalValue(VALUE, Sextante.getText("Value"), 0, AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
41 |
m_Parameters.addBoolean(FORCE_NODATA, Sextante.getText("Force_no-data_value"), true); |
42 |
addOutputRasterLayer(RESULT, this.getName());
|
43 |
} |
44 |
catch (final RepeatedParameterNameException e) { |
45 |
Sextante.addErrorToLog(e); |
46 |
} |
47 |
|
48 |
} |
49 |
|
50 |
|
51 |
@Override
|
52 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
53 |
|
54 |
int i;
|
55 |
int x, y;
|
56 |
int iNX, iNY;
|
57 |
double dValue;
|
58 |
IRasterLayer[] window;
|
59 |
|
60 |
NO_DATA = m_OutputFactory.getDefaultNoDataValue(); |
61 |
|
62 |
try {
|
63 |
final ArrayList input = m_Parameters.getParameterValueAsArrayList(INPUT); |
64 |
final boolean bForceNoData = m_Parameters.getParameterValueAsBoolean(FORCE_NODATA); |
65 |
m_dValue = m_Parameters.getParameterValueAsDouble(VALUE); |
66 |
|
67 |
if (input.size() == 0) { |
68 |
return false; |
69 |
} |
70 |
|
71 |
final IRasterLayer result = getNewRasterLayer(RESULT, this.getName(), IRasterLayer.RASTER_DATA_TYPE_DOUBLE); |
72 |
|
73 |
result.setNoDataValue(NO_DATA); |
74 |
result.assignNoData(); |
75 |
|
76 |
window = new IRasterLayer[input.size()];
|
77 |
for (i = 0; i < input.size(); i++) { |
78 |
window[i] = (IRasterLayer) input.get(i); |
79 |
window[i].setWindowExtent(result.getWindowGridExtent()); |
80 |
if ((window[i].getDataType() == DataBuffer.TYPE_FLOAT) || (window[i].getDataType() == DataBuffer.TYPE_DOUBLE)) { |
81 |
window[i].setInterpolationMethod(IRasterLayer.INTERPOLATION_BSpline); |
82 |
} |
83 |
else {
|
84 |
window[i].setInterpolationMethod(IRasterLayer.INTERPOLATION_NearestNeighbour); |
85 |
} |
86 |
} |
87 |
|
88 |
iNX = window[0].getNX();
|
89 |
iNY = window[0].getNY();
|
90 |
|
91 |
final double dValues[] = new double[input.size()]; |
92 |
|
93 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
94 |
for (x = 0; x < iNX; x++) { |
95 |
for (i = 0; i < window.length; i++) { |
96 |
dValue = window[i].getCellValueAsDouble(x, y); |
97 |
if (!window[i].isNoDataValue(dValue)) {
|
98 |
dValues[i] = dValue; |
99 |
} |
100 |
else {
|
101 |
if (bForceNoData) {
|
102 |
result.setNoData(x, y); |
103 |
break;
|
104 |
} |
105 |
else {
|
106 |
dValues[i] = NO_DATA; |
107 |
} |
108 |
} |
109 |
} |
110 |
result.setCellValue(x, y, processValues(dValues)); |
111 |
} |
112 |
|
113 |
} |
114 |
|
115 |
return !m_Task.isCanceled();
|
116 |
|
117 |
} |
118 |
catch (final WrongParameterTypeException e) { |
119 |
Sextante.addErrorToLog(e); |
120 |
} |
121 |
catch (final WrongParameterIDException e) { |
122 |
Sextante.addErrorToLog(e); |
123 |
} |
124 |
catch (final NullParameterValueException e) { |
125 |
Sextante.addErrorToLog(e); |
126 |
} |
127 |
|
128 |
return false; |
129 |
|
130 |
} |
131 |
|
132 |
|
133 |
protected abstract double processValues(double[] dValues); |
134 |
|
135 |
|
136 |
} |