Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridStatistics / neighborhoodVariance / NeighborhoodVarianceAlgorithm.java @ 59

History | View | Annotate | Download (1.11 KB)

1
package es.unex.sextante.gridStatistics.neighborhoodVariance;
2

    
3
import es.unex.sextante.core.Sextante;
4
import es.unex.sextante.gridStatistics.base.NeighborhoodStatsBaseAlgorithm;
5

    
6
public class NeighborhoodVarianceAlgorithm
7
         extends
8
            NeighborhoodStatsBaseAlgorithm {
9

    
10
   @Override
11
   public void defineCharacteristics() {
12

    
13
      setName(Sextante.getText("Variance__neighbourhood"));
14
      setGroup(Sextante.getText("Focal_statistics"));
15
      super.defineCharacteristics();
16

    
17
   }
18

    
19

    
20
   @Override
21
   protected double processValues() {
22

    
23
      int i;
24
      int iValidCells = 0;
25
      double dValue;
26

    
27
      double dSum = 0;
28
      double dVar = 0;
29

    
30
      for (i = 0; i < m_dValues.length; i++) {
31
         dValue = m_dValues[i];
32
         if (dValue != NO_DATA) {
33
            dSum += dValue;
34
            dVar += (dValue * dValue);
35
            iValidCells++;
36
         }
37
      }
38

    
39
      if (iValidCells > 0) {
40
         final double dMean = dSum / iValidCells;
41
         return (dVar / iValidCells - dMean * dMean);
42
      }
43
      else {
44
         return NO_DATA;
45
      }
46

    
47
   }
48

    
49
}