root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridCategorical / reclassifyEqualAmplitude / ReclassifyEqualAmplitudeAlgorithm.java @ 59
History | View | Annotate | Download (2.75 KB)
1 |
package es.unex.sextante.gridCategorical.reclassifyEqualAmplitude; |
---|---|
2 |
|
3 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
4 |
import es.unex.sextante.core.GeoAlgorithm; |
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.RepeatedParameterNameException; |
9 |
|
10 |
public class ReclassifyEqualAmplitudeAlgorithm |
11 |
extends
|
12 |
GeoAlgorithm { |
13 |
|
14 |
public static final String CLASSCOUNT = "CLASSCOUNT"; |
15 |
public static final String RECLASS = "RECLASS"; |
16 |
public static final String INPUT = "INPUT"; |
17 |
|
18 |
|
19 |
@Override
|
20 |
public void defineCharacteristics() { |
21 |
|
22 |
setName(Sextante.getText("Divide_into_n_classes_of_equal_amplitude"));
|
23 |
setGroup(Sextante.getText("Reclassify_raster_layers"));
|
24 |
setUserCanDefineAnalysisExtent(true);
|
25 |
|
26 |
try {
|
27 |
m_Parameters.addInputRasterLayer(INPUT, Sextante.getText("Layer"), true); |
28 |
m_Parameters.addNumericalValue(CLASSCOUNT, Sextante.getText("Number_of_classes"),
|
29 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER, 10, 2, Integer.MAX_VALUE); |
30 |
addOutputRasterLayer(RECLASS, Sextante.getText("Reclassify"));
|
31 |
} |
32 |
catch (final RepeatedParameterNameException e) { |
33 |
Sextante.addErrorToLog(e); |
34 |
} |
35 |
|
36 |
} |
37 |
|
38 |
|
39 |
@Override
|
40 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
41 |
|
42 |
int x, y;
|
43 |
int iNX, iNY;
|
44 |
int iClass;
|
45 |
double dValue;
|
46 |
double dClassAmplitude;
|
47 |
|
48 |
final IRasterLayer grid = m_Parameters.getParameterValueAsRasterLayer(INPUT);
|
49 |
final int iClasses = m_Parameters.getParameterValueAsInt(CLASSCOUNT); |
50 |
|
51 |
final IRasterLayer result = getNewRasterLayer(RECLASS, grid.getName() + Sextante.getText("[reclassified]"), |
52 |
IRasterLayer.RASTER_DATA_TYPE_INT); |
53 |
|
54 |
grid.setWindowExtent(result.getWindowGridExtent()); |
55 |
|
56 |
final double dMax = grid.getMaxValue(); |
57 |
final double dMin = grid.getMinValue(); |
58 |
|
59 |
if (dMax != dMin) {
|
60 |
dClassAmplitude = (dMax - dMin) / iClasses; |
61 |
|
62 |
iNX = grid.getNX(); |
63 |
iNY = grid.getNY(); |
64 |
|
65 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
66 |
for (x = 0; x < iNX; x++) { |
67 |
dValue = grid.getCellValueAsDouble(x, y); |
68 |
if (!grid.isNoDataValue(dValue)) {
|
69 |
iClass = (int) Math.floor(Math.min((dValue - dMin) / dClassAmplitude, iClasses - 1)); |
70 |
result.setCellValue(x, y, iClass + 1);
|
71 |
} |
72 |
else {
|
73 |
result.setNoData(x, y); |
74 |
} |
75 |
} |
76 |
} |
77 |
} |
78 |
|
79 |
return !m_Task.isCanceled();
|
80 |
|
81 |
} |
82 |
|
83 |
|
84 |
} |