root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridCalculus / binaryOperators / BinaryOperatorAlgorithm.java @ 59
History | View | Annotate | Download (2.62 KB)
1 |
|
---|---|
2 |
|
3 |
package es.unex.sextante.gridCalculus.binaryOperators; |
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.exceptions.GeoAlgorithmExecutionException; |
9 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
10 |
|
11 |
|
12 |
public abstract class BinaryOperatorAlgorithm |
13 |
extends
|
14 |
GeoAlgorithm { |
15 |
|
16 |
public static final String LAYER = "LAYER"; |
17 |
public static final String LAYER2 = "LAYER2"; |
18 |
public static final String RESULT = "RESULT"; |
19 |
|
20 |
//protected final double NO_DATA = -99999.0;
|
21 |
|
22 |
private IRasterLayer m_window;
|
23 |
private IRasterLayer m_window2;
|
24 |
|
25 |
protected double m_dValue; |
26 |
protected double m_dValue2; |
27 |
|
28 |
|
29 |
@Override
|
30 |
public void defineCharacteristics() { |
31 |
|
32 |
setGroup(Sextante.getText("Calculus_tools_for_raster_layer"));
|
33 |
setUserCanDefineAnalysisExtent(true);
|
34 |
|
35 |
try {
|
36 |
m_Parameters.addInputRasterLayer(LAYER, Sextante.getText("Layer"), true); |
37 |
m_Parameters.addInputRasterLayer(LAYER2, Sextante.getText("Layer") + " 2", true); |
38 |
|
39 |
addOutputRasterLayer(RESULT, Sextante.getText("Result"), 1); |
40 |
} |
41 |
catch (final RepeatedParameterNameException e) { |
42 |
Sextante.addErrorToLog(e); |
43 |
} |
44 |
|
45 |
} |
46 |
|
47 |
|
48 |
@Override
|
49 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
50 |
|
51 |
int x, y;
|
52 |
int iNX, iNY;
|
53 |
|
54 |
m_window = m_Parameters.getParameterValueAsRasterLayer(LAYER); |
55 |
m_window2 = m_Parameters.getParameterValueAsRasterLayer(LAYER2); |
56 |
|
57 |
m_window.setWindowExtent(m_AnalysisExtent); |
58 |
m_window2.setWindowExtent(m_AnalysisExtent); |
59 |
|
60 |
final IRasterLayer result = getNewRasterLayer(RESULT, this.getName(), IRasterLayer.RASTER_DATA_TYPE_DOUBLE, |
61 |
m_window.getWindowGridExtent()); |
62 |
|
63 |
result.setNoDataValue(m_OutputFactory.getDefaultNoDataValue()); |
64 |
result.assignNoData(); |
65 |
|
66 |
iNX = m_window.getNX(); |
67 |
iNY = m_window.getNY(); |
68 |
|
69 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
70 |
for (x = 0; x < iNX; x++) { |
71 |
m_dValue = m_window.getCellValueAsDouble(x, y); |
72 |
m_dValue2 = m_window2.getCellValueAsDouble(x, y); |
73 |
if (!m_window.isNoDataValue(m_dValue) && !m_window2.isNoDataValue(m_dValue2)) {
|
74 |
result.setCellValue(x, y, getProcessedValue()); |
75 |
} |
76 |
else {
|
77 |
result.setNoData(x, y); |
78 |
} |
79 |
} |
80 |
} |
81 |
|
82 |
return !m_Task.isCanceled();
|
83 |
|
84 |
} |
85 |
|
86 |
|
87 |
protected abstract double getProcessedValue(); |
88 |
|
89 |
} |