root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridStatistics / base / MultiGridStatsBaseAlgorithm.java @ 59
History | View | Annotate | Download (3.47 KB)
1 | 59 | nbrodin | |
---|---|---|---|
2 | |||
3 | package es.unex.sextante.gridStatistics.base; |
||
4 | |||
5 | import java.awt.image.DataBuffer; |
||
6 | import java.util.ArrayList; |
||
7 | |||
8 | import es.unex.sextante.additionalInfo.AdditionalInfoMultipleInput; |
||
9 | import es.unex.sextante.core.GeoAlgorithm; |
||
10 | import es.unex.sextante.core.Sextante; |
||
11 | import es.unex.sextante.dataObjects.IRasterLayer; |
||
12 | import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
||
13 | import es.unex.sextante.exceptions.RepeatedParameterNameException; |
||
14 | |||
15 | |||
16 | public abstract class MultiGridStatsBaseAlgorithm |
||
17 | extends
|
||
18 | GeoAlgorithm { |
||
19 | |||
20 | public static final String INPUT = "INPUT"; |
||
21 | public static final String FORCE_NODATA = "NODATA"; |
||
22 | public static final String RESULT = "RESULT"; |
||
23 | |||
24 | |||
25 | protected double NO_DATA; |
||
26 | |||
27 | |||
28 | @Override
|
||
29 | public void defineCharacteristics() { |
||
30 | |||
31 | setUserCanDefineAnalysisExtent(true);
|
||
32 | |||
33 | try {
|
||
34 | m_Parameters.addMultipleInput(INPUT, Sextante.getText("Layers"), AdditionalInfoMultipleInput.DATA_TYPE_RASTER, true); |
||
35 | m_Parameters.addBoolean(FORCE_NODATA, Sextante.getText("Force_no-data_value"), true); |
||
36 | addOutputRasterLayer(RESULT, this.getName());
|
||
37 | } |
||
38 | catch (final RepeatedParameterNameException e) { |
||
39 | Sextante.addErrorToLog(e); |
||
40 | } |
||
41 | |||
42 | } |
||
43 | |||
44 | |||
45 | @Override
|
||
46 | public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
||
47 | |||
48 | int i;
|
||
49 | int x, y;
|
||
50 | int iNX, iNY;
|
||
51 | double dValue;
|
||
52 | IRasterLayer[] window;
|
||
53 | |||
54 | NO_DATA = m_OutputFactory.getDefaultNoDataValue(); |
||
55 | |||
56 | final ArrayList input = m_Parameters.getParameterValueAsArrayList("INPUT"); |
||
57 | final boolean bForceNoData = m_Parameters.getParameterValueAsBoolean("NODATA"); |
||
58 | |||
59 | if (input.size() == 0) { |
||
60 | return false; |
||
61 | } |
||
62 | |||
63 | final IRasterLayer result = getNewRasterLayer(RESULT, this.getName(), IRasterLayer.RASTER_DATA_TYPE_DOUBLE); |
||
64 | |||
65 | result.setNoDataValue(m_OutputFactory.getDefaultNoDataValue()); |
||
66 | result.assignNoData(); |
||
67 | |||
68 | window = new IRasterLayer[input.size()];
|
||
69 | for (i = 0; i < input.size(); i++) { |
||
70 | window[i] = (IRasterLayer) input.get(i); |
||
71 | window[i].setWindowExtent(result.getWindowGridExtent()); |
||
72 | if ((window[i].getDataType() == DataBuffer.TYPE_FLOAT) || (window[i].getDataType() == DataBuffer.TYPE_DOUBLE)) { |
||
73 | window[i].setInterpolationMethod(IRasterLayer.INTERPOLATION_BSpline); |
||
74 | } |
||
75 | else {
|
||
76 | window[i].setInterpolationMethod(IRasterLayer.INTERPOLATION_NearestNeighbour); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | iNX = window[0].getNX();
|
||
81 | iNY = window[0].getNY();
|
||
82 | |||
83 | final double dValues[] = new double[input.size()]; |
||
84 | |||
85 | for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
||
86 | for (x = 0; x < iNX; x++) { |
||
87 | for (i = 0; i < window.length; i++) { |
||
88 | dValue = window[i].getCellValueAsDouble(x, y); |
||
89 | if (!window[i].isNoDataValue(dValue)) {
|
||
90 | dValues[i] = dValue; |
||
91 | } |
||
92 | else {
|
||
93 | if (bForceNoData) {
|
||
94 | result.setNoData(x, y); |
||
95 | break;
|
||
96 | } |
||
97 | else {
|
||
98 | dValues[i] = m_OutputFactory.getDefaultNoDataValue(); |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | result.setCellValue(x, y, processValues(dValues)); |
||
103 | } |
||
104 | |||
105 | } |
||
106 | |||
107 | return !m_Task.isCanceled();
|
||
108 | |||
109 | |||
110 | } |
||
111 | |||
112 | |||
113 | protected abstract double processValues(double[] dValues); |
||
114 | |||
115 | |||
116 | } |