root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / rasterize / idw / IDWAlgorithm.java @ 59
History | View | Annotate | Download (2.58 KB)
1 |
package es.unex.sextante.rasterize.idw; |
---|---|
2 |
|
3 |
import es.unex.sextante.additionalInfo.AdditionalInfoNumericalValue; |
4 |
import es.unex.sextante.closestpts.Point3D; |
5 |
import es.unex.sextante.core.Sextante; |
6 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
7 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
8 |
import es.unex.sextante.rasterize.interpolationBase.BaseInterpolationAlgorithm; |
9 |
|
10 |
public class IDWAlgorithm |
11 |
extends
|
12 |
BaseInterpolationAlgorithm { |
13 |
|
14 |
public static final String POWER = "POWER"; |
15 |
public static final String CROSSVALIDATION = "CROSSVALIDATION"; |
16 |
|
17 |
private double m_dPower; |
18 |
|
19 |
|
20 |
@Override
|
21 |
public void defineCharacteristics() { |
22 |
|
23 |
super.defineCharacteristics();
|
24 |
setGroup(Sextante.getText("Rasterization_and_interpolation"));
|
25 |
setName(Sextante.getText("Inverse_Distance_Weighting__IDW"));
|
26 |
|
27 |
try {
|
28 |
m_Parameters.addNumericalValue(POWER, Sextante.getText("Exponent"), AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE,
|
29 |
2, 0, Double.MAX_VALUE); |
30 |
addOutputTable(CROSSVALIDATION, Sextante.getText("Cross_validation"));
|
31 |
} |
32 |
catch (final RepeatedParameterNameException e) { |
33 |
Sextante.addErrorToLog(e); |
34 |
} |
35 |
|
36 |
} |
37 |
|
38 |
|
39 |
@Override
|
40 |
protected void setValues() throws GeoAlgorithmExecutionException { |
41 |
|
42 |
super.setValues();
|
43 |
|
44 |
m_dPower = m_Parameters.getParameterValueAsDouble(POWER); |
45 |
|
46 |
} |
47 |
|
48 |
|
49 |
@Override
|
50 |
protected double interpolate(final double x, |
51 |
final double y) { |
52 |
|
53 |
int i;
|
54 |
int iPts = 0; |
55 |
Point3D pt; |
56 |
double d;
|
57 |
double dDistSum = 0, dZSum = 0; |
58 |
|
59 |
try {
|
60 |
if (m_NearestPoints.length != 0) { |
61 |
final int iSize = m_NearestPoints.length; |
62 |
for (i = 0; i < iSize; i++) { |
63 |
if (m_NearestPoints[i] != null) { |
64 |
iPts++; |
65 |
pt = m_NearestPoints[i].getPt(); |
66 |
d = m_NearestPoints[i].getDist(); |
67 |
|
68 |
if (d <= 0.0) { |
69 |
return pt.getZ();
|
70 |
} |
71 |
|
72 |
d = Math.pow(d, -m_dPower);
|
73 |
|
74 |
dZSum += d * pt.getZ(); |
75 |
dDistSum += d; |
76 |
} |
77 |
} |
78 |
|
79 |
if (iPts > 0) { |
80 |
return dZSum / dDistSum;
|
81 |
} |
82 |
else {
|
83 |
return NO_DATA;
|
84 |
} |
85 |
} |
86 |
else {
|
87 |
return NO_DATA;
|
88 |
} |
89 |
} |
90 |
catch (final Exception e) { |
91 |
return NO_DATA;
|
92 |
} |
93 |
|
94 |
} |
95 |
|
96 |
} |