Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / rasterize / linearDecrease / LinearDecreaseAlgorithm.java @ 59

History | View | Annotate | Download (2.43 KB)

1
package es.unex.sextante.rasterize.linearDecrease;
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 LinearDecreaseAlgorithm
11
         extends
12
            BaseInterpolationAlgorithm {
13

    
14
   public static final String CROSSVALIDATION = "CROSSVALIDATION";
15
   public static final String POWER           = "POWER";
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("Linear_decrease"));
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
      Point3D pt;
55
      double d;
56
      double dDistSum = 0, dZSum = 0;
57
      int iPts = 0;
58
      if (m_NearestPoints.length != 0) {
59
         final int iSize = m_NearestPoints.length;
60
         for (i = 0; i < iSize; i++) {
61
            if (m_NearestPoints[i] != null) {
62
               iPts++;
63
               pt = m_NearestPoints[i].getPt();
64
               d = m_NearestPoints[i].getDist();
65

    
66
               if (d <= 0.0) {
67
                  return pt.getZ();
68
               }
69

    
70
               d = 1 - Math.pow(d / m_dDistance, m_dPower);
71

    
72
               dZSum += d * pt.getZ();
73
               dDistSum += d;
74
            }
75
         }
76
         if (iPts > 0) {
77
            return dZSum / dDistSum;
78
         }
79
         else {
80
            return NO_DATA;
81
         }
82
      }
83
      else {
84
         return NO_DATA;
85
      }
86

    
87
   }
88

    
89
}