root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / topology / extractNodes / Node.java @ 59
History | View | Annotate | Download (1.93 KB)
1 |
package es.unex.sextante.topology.extractNodes; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import com.vividsolutions.jts.geom.Geometry; |
6 |
|
7 |
import es.unex.sextante.dataObjects.IFeature; |
8 |
|
9 |
public class Node { |
10 |
|
11 |
private int ID = 0; |
12 |
private final Geometry geom; |
13 |
IFeature lineFeature; |
14 |
private int degree; |
15 |
//FIDs connectedLines
|
16 |
private final ArrayList lines; |
17 |
private final ArrayList linesIdx; |
18 |
//IDs near endpoints
|
19 |
private final ArrayList closeNodes; |
20 |
|
21 |
|
22 |
public Node(final int iD, |
23 |
final Geometry geom,
|
24 |
final IFeature lineFeature) {
|
25 |
ID = iD; |
26 |
this.geom = geom;
|
27 |
this.degree = 1; |
28 |
this.lineFeature = lineFeature;
|
29 |
lines = new ArrayList(); |
30 |
linesIdx = new ArrayList(); |
31 |
closeNodes = new ArrayList(); |
32 |
} |
33 |
|
34 |
|
35 |
public void incrementDegree() { |
36 |
degree++; |
37 |
} |
38 |
|
39 |
|
40 |
public int getDegree() { |
41 |
return degree;
|
42 |
} |
43 |
|
44 |
|
45 |
public Geometry getGeometry() {
|
46 |
return geom;
|
47 |
} |
48 |
|
49 |
|
50 |
public void addConnectedLine(final IFeature feat, |
51 |
final int idx) { |
52 |
if (!lines.contains(feat)) {
|
53 |
lines.add(feat); |
54 |
} |
55 |
if (!linesIdx.contains(idx)) {
|
56 |
linesIdx.add(idx); |
57 |
} |
58 |
} |
59 |
|
60 |
|
61 |
public void processIfClose(final Node n, |
62 |
final double tolerance) { |
63 |
|
64 |
if (closeNodes.contains(n) || n.getGeometry().equals(getGeometry())) {
|
65 |
//System.out.println(n + " " + this + " equals?" + (n.getGeometry().equals(getGeometry())));
|
66 |
return;
|
67 |
} |
68 |
final Geometry g = n.getGeometry();
|
69 |
final double dist = geom.distance(g); |
70 |
if (dist < tolerance) {
|
71 |
System.out.println("Added a node a " + dist); |
72 |
closeNodes.add(n); |
73 |
} |
74 |
|
75 |
} |
76 |
|
77 |
|
78 |
public ArrayList getCloseNodes() { |
79 |
return closeNodes;
|
80 |
} |
81 |
|
82 |
|
83 |
public ArrayList getConnectedLines() { |
84 |
return lines;
|
85 |
} |
86 |
|
87 |
|
88 |
public ArrayList getConnectedLinesIdx() { |
89 |
return linesIdx;
|
90 |
} |
91 |
|
92 |
} |