root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridTools / changeDataType / ChangeDataTypeAlgorithm.java @ 59
History | View | Annotate | Download (2.96 KB)
1 |
package es.unex.sextante.gridTools.changeDataType; |
---|---|
2 |
|
3 |
import es.unex.sextante.core.GeoAlgorithm; |
4 |
import es.unex.sextante.core.Sextante; |
5 |
import es.unex.sextante.dataObjects.IRasterLayer; |
6 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
7 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
8 |
|
9 |
public class ChangeDataTypeAlgorithm |
10 |
extends
|
11 |
GeoAlgorithm { |
12 |
|
13 |
public static final String INPUT = "INPUT"; |
14 |
public static final String TYPE = "TYPE"; |
15 |
public static final String RESULT = "RESULT"; |
16 |
|
17 |
public static final int BYTE = 0; |
18 |
public static final int SHORT = 0; |
19 |
public static final int INT = 0; |
20 |
public static final int FLOAT = 0; |
21 |
public static final int DOUBLE = 0; |
22 |
|
23 |
|
24 |
@Override
|
25 |
public void defineCharacteristics() { |
26 |
|
27 |
final String sTypes[] = { "Byte", "Short", "Int", "Float", "Double" }; |
28 |
setName(Sextante.getText("Change_data_type"));
|
29 |
setGroup(Sextante.getText("Basic_tools_for_raster_layers"));
|
30 |
setUserCanDefineAnalysisExtent(true);
|
31 |
|
32 |
try {
|
33 |
m_Parameters.addInputRasterLayer(INPUT, Sextante.getText("Layer"), true); |
34 |
m_Parameters.addSelection(TYPE, Sextante.getText("Data_type"), sTypes);
|
35 |
addOutputRasterLayer(RESULT, Sextante.getText("Result"));
|
36 |
} |
37 |
catch (final RepeatedParameterNameException e) { |
38 |
Sextante.addErrorToLog(e); |
39 |
} |
40 |
|
41 |
} |
42 |
|
43 |
|
44 |
@Override
|
45 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
46 |
|
47 |
int x, y;
|
48 |
int iNX, iNY;
|
49 |
int iType, iRasterType;
|
50 |
double dValue;
|
51 |
IRasterLayer input; |
52 |
|
53 |
input = m_Parameters.getParameterValueAsRasterLayer(INPUT); |
54 |
iType = m_Parameters.getParameterValueAsInt(TYPE); |
55 |
|
56 |
switch (iType) {
|
57 |
case 0: |
58 |
iRasterType = IRasterLayer.RASTER_DATA_TYPE_BYTE; |
59 |
break;
|
60 |
case 1: |
61 |
iRasterType = IRasterLayer.RASTER_DATA_TYPE_SHORT; |
62 |
break;
|
63 |
case 2: |
64 |
iRasterType = IRasterLayer.RASTER_DATA_TYPE_INT; |
65 |
break;
|
66 |
case 3: |
67 |
iRasterType = IRasterLayer.RASTER_DATA_TYPE_FLOAT; |
68 |
break;
|
69 |
case 4: |
70 |
default:
|
71 |
iRasterType = IRasterLayer.RASTER_DATA_TYPE_DOUBLE; |
72 |
break;
|
73 |
} |
74 |
final IRasterLayer result = getNewRasterLayer(RESULT, Sextante.getText("Result"), iRasterType); |
75 |
|
76 |
input.setWindowExtent(m_AnalysisExtent); |
77 |
|
78 |
iNX = result.getWindowGridExtent().getNX(); |
79 |
iNY = result.getWindowGridExtent().getNY(); |
80 |
|
81 |
for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
82 |
for (x = 0; x < iNX; x++) { |
83 |
dValue = input.getCellValueAsDouble(x, y); |
84 |
if (!input.isNoDataValue(dValue)) {
|
85 |
result.setCellValue(x, y, dValue); |
86 |
} |
87 |
else {
|
88 |
result.setNoData(x, y); |
89 |
} |
90 |
} |
91 |
} |
92 |
|
93 |
return !m_Task.isCanceled();
|
94 |
|
95 |
} |
96 |
|
97 |
|
98 |
} |