root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / hydrology / cFactorFromNDVI / CFactorFromNDVIAlgorithm.java @ 59
History | View | Annotate | Download (2.49 KB)
1 | 59 | nbrodin | package es.unex.sextante.hydrology.cFactorFromNDVI; |
---|---|---|---|
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 CFactorFromNDVIAlgorithm |
||
11 | extends
|
||
12 | GeoAlgorithm { |
||
13 | |||
14 | public static final String ALPHA = "ALPHA"; |
||
15 | public static final String BETA = "BETA"; |
||
16 | public static final String NDVI = "NDVI"; |
||
17 | public static final String CFACTOR = "CFACTOR"; |
||
18 | |||
19 | private IRasterLayer m_NDVI = null; |
||
20 | private IRasterLayer m_CFactor;
|
||
21 | |||
22 | |||
23 | @Override
|
||
24 | public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
||
25 | |||
26 | int x, y;
|
||
27 | int iNX, iNY;
|
||
28 | double dNDVI;
|
||
29 | double dAlpha, dBeta;
|
||
30 | |||
31 | m_NDVI = m_Parameters.getParameterValueAsRasterLayer(NDVI); |
||
32 | m_CFactor = getNewRasterLayer(CFACTOR, "C", IRasterLayer.RASTER_DATA_TYPE_FLOAT);
|
||
33 | dAlpha = m_Parameters.getParameterValueAsDouble(ALPHA); |
||
34 | dBeta = m_Parameters.getParameterValueAsDouble(BETA); |
||
35 | |||
36 | m_NDVI.setWindowExtent(m_AnalysisExtent); |
||
37 | |||
38 | iNX = m_NDVI.getNX(); |
||
39 | iNY = m_NDVI.getNY(); |
||
40 | |||
41 | for (y = 0; (y < iNY) && setProgress(y, iNY); y++) { |
||
42 | for (x = 0; x < iNX; x++) { |
||
43 | dNDVI = m_NDVI.getCellValueAsDouble(x, y); |
||
44 | if (m_NDVI.isNoDataValue(dNDVI)) {
|
||
45 | m_CFactor.setNoData(x, y); |
||
46 | } |
||
47 | else {
|
||
48 | m_CFactor.setCellValue(x, y, Math.exp(-dAlpha * dNDVI / (dBeta - dNDVI)));
|
||
49 | } |
||
50 | } |
||
51 | } |
||
52 | |||
53 | |||
54 | return !m_Task.isCanceled();
|
||
55 | } |
||
56 | |||
57 | |||
58 | @Override
|
||
59 | public void defineCharacteristics() { |
||
60 | |||
61 | setName(Sextante.getText("C_factor_from_NDVI"));
|
||
62 | setGroup(Sextante.getText("Indices_and_other_hydrological_parameters"));
|
||
63 | setUserCanDefineAnalysisExtent(true);
|
||
64 | |||
65 | try {
|
||
66 | m_Parameters.addInputRasterLayer(NDVI, "NDVI", true); |
||
67 | m_Parameters.addNumericalValue(ALPHA, "Alpha", 1., AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
||
68 | m_Parameters.addNumericalValue(BETA, "Beta", 2., AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
||
69 | addOutputRasterLayer(CFACTOR, Sextante.getText("C"));
|
||
70 | } |
||
71 | catch (final RepeatedParameterNameException e) { |
||
72 | Sextante.addErrorToLog(e); |
||
73 | } |
||
74 | |||
75 | } |
||
76 | |||
77 | } |