root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridTools / invertNoData / InvertNoDataAlgorithm.java @ 59
History | View | Annotate | Download (1.99 KB)
1 | 59 | nbrodin | package es.unex.sextante.gridTools.invertNoData; |
---|---|---|---|
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 InvertNoDataAlgorithm |
||
10 | extends
|
||
11 | GeoAlgorithm { |
||
12 | |||
13 | public static final String RESULT = "RESULT"; |
||
14 | public static final String INPUT = "INPUT"; |
||
15 | |||
16 | |||
17 | @Override
|
||
18 | public void defineCharacteristics() { |
||
19 | |||
20 | setName(Sextante.getText("Invert_mask"));
|
||
21 | setGroup(Sextante.getText("Basic_tools_for_raster_layers"));
|
||
22 | setUserCanDefineAnalysisExtent(true);
|
||
23 | |||
24 | try {
|
||
25 | m_Parameters.addInputRasterLayer(INPUT, Sextante.getText("Layer"), true); |
||
26 | addOutputRasterLayer(RESULT, Sextante.getText("Inverted_mask"));
|
||
27 | } |
||
28 | catch (final RepeatedParameterNameException e) { |
||
29 | Sextante.addErrorToLog(e); |
||
30 | } |
||
31 | |||
32 | } |
||
33 | |||
34 | |||
35 | @Override
|
||
36 | public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
||
37 | |||
38 | int x, y;
|
||
39 | int iNX, iNY;
|
||
40 | double dValue;
|
||
41 | IRasterLayer input; |
||
42 | |||
43 | input = m_Parameters.getParameterValueAsRasterLayer(INPUT); |
||
44 | |||
45 | final IRasterLayer result = getNewRasterLayer(RESULT, Sextante.getText("Inverted_mask"), IRasterLayer.RASTER_DATA_TYPE_BYTE); |
||
46 | |||
47 | |||
48 | result.setNoDataValue(0.0);
|
||
49 | |||
50 | input.setWindowExtent(result.getWindowGridExtent()); |
||
51 | |||
52 | iNX = result.getWindowGridExtent().getNX(); |
||
53 | iNY = result.getWindowGridExtent().getNY(); |
||
54 | |||
55 | for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
||
56 | for (x = 0; x < iNX; x++) { |
||
57 | dValue = input.getCellValueAsDouble(x, y); |
||
58 | if (input.isNoDataValue(dValue)) {
|
||
59 | result.setCellValue(x, y, 1.0);
|
||
60 | } |
||
61 | else {
|
||
62 | result.setNoData(x, y); |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | |||
67 | return !m_Task.isCanceled();
|
||
68 | |||
69 | } |
||
70 | |||
71 | |||
72 | } |