root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vegetationIndices / base / SlopeBasedAlgorithm.java @ 59
History | View | Annotate | Download (3.8 KB)
1 |
package es.unex.sextante.vegetationIndices.base; |
---|---|
2 |
|
3 |
import es.unex.sextante.core.GeoAlgorithm; |
4 |
import es.unex.sextante.core.AnalysisExtent; |
5 |
import es.unex.sextante.core.Sextante; |
6 |
import es.unex.sextante.dataObjects.IRasterLayer; |
7 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
8 |
import es.unex.sextante.exceptions.OptionalParentParameterException; |
9 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
10 |
import es.unex.sextante.exceptions.UndefinedParentParameterNameException; |
11 |
|
12 |
public abstract class SlopeBasedAlgorithm |
13 |
extends
|
14 |
GeoAlgorithm { |
15 |
|
16 |
public static final String LAYERRED = "LAYERRED"; |
17 |
public static final String BANDRED = "BANDRED"; |
18 |
public static final String BANDNIR = "BANDNIR"; |
19 |
public static final String LAYERNIR = "LAYERNIR"; |
20 |
public static final String RESULT = "RESULT"; |
21 |
|
22 |
private IRasterLayer m_LayerRed, m_LayerNIR;
|
23 |
protected double m_dNoData; |
24 |
|
25 |
|
26 |
@Override
|
27 |
public void defineCharacteristics() { |
28 |
|
29 |
setUserCanDefineAnalysisExtent(true);
|
30 |
setGroup(Sextante.getText("Vegetation_indices"));
|
31 |
this.setGroup(Sextante.getText("Vegetation_indices")); |
32 |
try {
|
33 |
m_Parameters.addInputRasterLayer(LAYERRED, Sextante.getText("Red_layer"), true); |
34 |
m_Parameters.addBand(BANDRED, Sextante.getText("Red_band"), LAYERRED);
|
35 |
m_Parameters.addInputRasterLayer(LAYERNIR, Sextante.getText("Near_infrared_layer"), true); |
36 |
m_Parameters.addBand(BANDNIR, Sextante.getText("Near_infrared_band"), LAYERNIR);
|
37 |
addOutputRasterLayer(RESULT, Sextante.getText("Result"));
|
38 |
} |
39 |
catch (final RepeatedParameterNameException e) { |
40 |
Sextante.addErrorToLog(e); |
41 |
} |
42 |
catch (final UndefinedParentParameterNameException e) { |
43 |
Sextante.addErrorToLog(e); |
44 |
} |
45 |
catch (final OptionalParentParameterException e) { |
46 |
Sextante.addErrorToLog(e); |
47 |
} |
48 |
|
49 |
} |
50 |
|
51 |
|
52 |
@Override
|
53 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
54 |
|
55 |
int x, y;
|
56 |
int iNX, iNY;
|
57 |
double dRed;
|
58 |
double dNIR;
|
59 |
double dIndex;
|
60 |
AnalysisExtent extent; |
61 |
|
62 |
m_LayerRed = m_Parameters.getParameterValueAsRasterLayer(LAYERRED); |
63 |
final int iBandRed = m_Parameters.getParameterValueAsInt(BANDRED); |
64 |
m_LayerNIR = m_Parameters.getParameterValueAsRasterLayer(LAYERNIR); |
65 |
final int iBandNIR = m_Parameters.getParameterValueAsInt(BANDNIR); |
66 |
|
67 |
final IRasterLayer result = getNewRasterLayer(RESULT, getName(), IRasterLayer.RASTER_DATA_TYPE_DOUBLE);
|
68 |
|
69 |
extent = result.getWindowGridExtent(); |
70 |
|
71 |
m_LayerRed.setWindowExtent(extent); |
72 |
m_LayerNIR.setWindowExtent(extent); |
73 |
m_LayerRed.setInterpolationMethod(IRasterLayer.INTERPOLATION_NearestNeighbour); |
74 |
m_LayerNIR.setInterpolationMethod(IRasterLayer.INTERPOLATION_NearestNeighbour); |
75 |
|
76 |
iNX = m_LayerRed.getNX(); |
77 |
iNY = m_LayerRed.getNY(); |
78 |
|
79 |
m_dNoData = result.getNoDataValue(); |
80 |
|
81 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
82 |
for (x = 0; x < iNX; x++) { |
83 |
dRed = m_LayerRed.getCellValueAsDouble(x, y, iBandRed); |
84 |
dNIR = m_LayerNIR.getCellValueAsDouble(x, y, iBandNIR); |
85 |
if (!m_LayerRed.isNoDataValue(dRed) && !m_LayerNIR.isNoDataValue(dNIR)) {
|
86 |
dIndex = getIndex(dRed, dNIR); |
87 |
result.setCellValue(x, y, dIndex); |
88 |
} |
89 |
else {
|
90 |
result.setNoData(x, y); |
91 |
} |
92 |
} |
93 |
} |
94 |
|
95 |
return !m_Task.isCanceled();
|
96 |
|
97 |
} |
98 |
|
99 |
|
100 |
protected double getNDVI(final double dRed, |
101 |
final double dNIR) { |
102 |
|
103 |
return (dNIR - dRed) / (dNIR + dRed);
|
104 |
|
105 |
} |
106 |
|
107 |
|
108 |
protected abstract double getIndex(double dRed, |
109 |
double dNIR);
|
110 |
|
111 |
} |