root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridCalculus / generateRandomUniform / GenerateRandomUniformAlgorithm.java @ 59
History | View | Annotate | Download (2.14 KB)
1 |
package es.unex.sextante.gridCalculus.generateRandomUniform; |
---|---|
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 GenerateRandomUniformAlgorithm |
11 |
extends
|
12 |
GeoAlgorithm { |
13 |
|
14 |
public static final String PROB = "PROB"; |
15 |
public static final String MAX = "MAX"; |
16 |
public static final String MIN = "MIN"; |
17 |
|
18 |
private IRasterLayer m_Result;
|
19 |
|
20 |
|
21 |
@Override
|
22 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
23 |
|
24 |
int x, y;
|
25 |
int iNX, iNY;
|
26 |
double dValue;
|
27 |
|
28 |
final double dMin = m_Parameters.getParameterValueAsDouble(MIN); |
29 |
final double dMax = m_Parameters.getParameterValueAsDouble(MAX); |
30 |
|
31 |
m_Result = getNewRasterLayer(PROB, Sextante.getText("New_layer"), IRasterLayer.RASTER_DATA_TYPE_FLOAT);
|
32 |
|
33 |
iNX = m_Result.getWindowGridExtent().getNX(); |
34 |
iNY = m_Result.getWindowGridExtent().getNY(); |
35 |
|
36 |
for (y = 0; y < iNY; y++) { |
37 |
for (x = 0; x < iNX; x++) { |
38 |
dValue = Math.random() * (dMax - dMin) + dMin;
|
39 |
m_Result.setCellValue(x, y, dValue); |
40 |
} |
41 |
} |
42 |
|
43 |
return !m_Task.isCanceled();
|
44 |
} |
45 |
|
46 |
|
47 |
@Override
|
48 |
public void defineCharacteristics() { |
49 |
|
50 |
setName(Sextante.getText("Random_grid__uniform"));
|
51 |
setGroup(Sextante.getText("Raster_creation_tools"));
|
52 |
setUserCanDefineAnalysisExtent(true);
|
53 |
|
54 |
try {
|
55 |
m_Parameters.addNumericalValue(MIN, Sextante.getText("Min_value"), 0, |
56 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
57 |
m_Parameters.addNumericalValue(MAX, Sextante.getText("Max_value"), 1, |
58 |
AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE); |
59 |
addOutputRasterLayer(PROB, Sextante.getText("Probability"));
|
60 |
} |
61 |
catch (final RepeatedParameterNameException e) { |
62 |
Sextante.addErrorToLog(e); |
63 |
} |
64 |
|
65 |
} |
66 |
|
67 |
} |