root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / gridCategorical / fragstatsArea / PatchInfo.java @ 59
History | View | Annotate | Download (2.27 KB)
1 |
package es.unex.sextante.gridCategorical.fragstatsArea; |
---|---|
2 |
|
3 |
import es.unex.sextante.dataObjects.IRasterLayer; |
4 |
|
5 |
public class PatchInfo { |
6 |
|
7 |
private final int m_iOffsetX[] = { -1, 0, 0, 1 }; |
8 |
private final int m_iOffsetY[] = { 0, -1, 1, 0 }; |
9 |
|
10 |
private final int m_iClass; |
11 |
private int m_iCells; |
12 |
private int m_iPerimeter; |
13 |
private int m_iSumX, m_iSumY; |
14 |
private double m_dCentroidX; |
15 |
private double m_dCentroidY; |
16 |
private double m_dRadiusOfGyration; |
17 |
|
18 |
private final IRasterLayer m_Window; |
19 |
|
20 |
|
21 |
public PatchInfo(final int iClass, |
22 |
final IRasterLayer window) {
|
23 |
|
24 |
m_Window = window; |
25 |
|
26 |
m_iCells = 0;
|
27 |
m_iPerimeter = 0;
|
28 |
m_iSumX = 0;
|
29 |
m_iSumY = 0;
|
30 |
m_iClass = iClass; |
31 |
|
32 |
} |
33 |
|
34 |
|
35 |
public void add(final int x, |
36 |
final int y) { |
37 |
|
38 |
int n;
|
39 |
int x2, y2;
|
40 |
int iClass;
|
41 |
|
42 |
m_iCells++; |
43 |
m_iSumX += x; |
44 |
m_iSumY += y; |
45 |
for (n = 0; n < 4; n++) { |
46 |
x2 = x + m_iOffsetX[n]; |
47 |
y2 = y + m_iOffsetY[n]; |
48 |
iClass = m_Window.getCellValueAsInt(x2, y2); |
49 |
if (m_Window.isNoDataValue(iClass) || (iClass != m_iClass)) {
|
50 |
m_iPerimeter++; |
51 |
} |
52 |
} |
53 |
} |
54 |
|
55 |
|
56 |
public void addForRadiusOfGyration(final int x, |
57 |
final int y) { |
58 |
|
59 |
m_dRadiusOfGyration += Math.sqrt(Math.pow(x - m_dCentroidX, 2.0) + Math.pow(y - m_dCentroidY, 2.0)); |
60 |
|
61 |
} |
62 |
|
63 |
|
64 |
public double getPerimeter() { |
65 |
|
66 |
return m_Window.getWindowCellSize() * m_iPerimeter;
|
67 |
|
68 |
} |
69 |
|
70 |
|
71 |
public void calculateCentroid() { |
72 |
|
73 |
m_dCentroidX = m_iSumX / (double) m_iCells;
|
74 |
m_dCentroidY = m_iSumY / (double) m_iCells;
|
75 |
|
76 |
} |
77 |
|
78 |
|
79 |
public double getArea() { |
80 |
|
81 |
return m_Window.getWindowCellSize() * m_Window.getWindowCellSize() * m_iCells;
|
82 |
|
83 |
} |
84 |
|
85 |
|
86 |
public double getRadiusOfGyration() { |
87 |
|
88 |
return m_dRadiusOfGyration / m_iCells * m_Window.getWindowCellSize();
|
89 |
|
90 |
} |
91 |
|
92 |
|
93 |
public int getClassID() { |
94 |
|
95 |
return m_iClass;
|
96 |
|
97 |
} |
98 |
|
99 |
|
100 |
public int getAreaInCells() { |
101 |
|
102 |
return m_iCells;
|
103 |
|
104 |
} |
105 |
|
106 |
|
107 |
public int getPerimeterInCells() { |
108 |
|
109 |
return m_iPerimeter;
|
110 |
|
111 |
} |
112 |
|
113 |
} |