1 package org.opentrafficsim.road.network.factory.osm;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.opentrafficsim.core.network.OTSNode;
7
8
9
10
11
12
13
14
15
16
17
18 public class OSMNode
19 {
20
21 private final long id;
22
23
24 private final double longitude;
25
26
27 private final double latitude;
28
29
30 private List<OSMTag> tags;
31
32
33 private boolean trafficSignal = false;
34
35
36 private boolean stopSign = false;
37
38
39 private boolean yieldSign = false;
40
41
42 private boolean crossing = false;
43
44
45 public int linksOriginating = 0;
46
47
48 public int linksTerminating = 0;
49
50
51 private OTSNode otsNode = null;
52
53
54
55
56 public final long getId()
57 {
58 return this.id;
59 }
60
61
62
63
64 public final double getLongitude()
65 {
66 return this.longitude;
67 }
68
69
70
71
72 public final double getLatitude()
73 {
74 return this.latitude;
75 }
76
77
78
79
80
81
82
83 public OSMNode(final long id, final double longitude, final double latitude)
84 {
85 this.id = id;
86 this.longitude = longitude;
87 this.latitude = latitude;
88 this.tags = new ArrayList<OSMTag>();
89 }
90
91
92
93
94
95
96 public final OSMTag getTag(final String key)
97 {
98 for (OSMTag tag : this.tags)
99 {
100 if (tag.getKey().equals(key))
101 {
102 return tag;
103 }
104 }
105 return null;
106 }
107
108
109
110
111
112 public final void addTag(final OSMTag tag)
113 {
114 this.tags.add(tag);
115 if (tag.getKey().equals("highway"))
116 {
117 switch (tag.getValue())
118 {
119 case "crossing":
120 this.setCrossing(true);
121 break;
122 case "give_way":
123 this.setYieldSign(true);
124 break;
125 case "stop":
126 this.setStopSign(true);
127 break;
128 case "traffic_signals":
129 this.setTrafficSignal(true);
130 break;
131 default:
132 break;
133 }
134 }
135 }
136
137
138 public final String toString()
139 {
140 return String.format("Node %d %.6f %.6f", getId(), getLongitude(), getLatitude());
141 }
142
143
144
145
146 public final boolean isTrafficSignal()
147 {
148 return this.trafficSignal;
149 }
150
151
152
153
154 public final void setTrafficSignal(final boolean trafficSignal)
155 {
156 this.trafficSignal = trafficSignal;
157 }
158
159
160
161
162 public final boolean isStopSign()
163 {
164 return this.stopSign;
165 }
166
167
168
169
170 public final void setStopSign(final boolean stopSign)
171 {
172 this.stopSign = stopSign;
173 }
174
175
176
177
178 public final boolean isYieldSign()
179 {
180 return this.yieldSign;
181 }
182
183
184
185
186 public final void setYieldSign(final boolean yieldSign)
187 {
188 this.yieldSign = yieldSign;
189 }
190
191
192
193
194 public final boolean isCrossing()
195 {
196 return this.crossing;
197 }
198
199
200
201
202 public final void setCrossing(final boolean crossing)
203 {
204 this.crossing = crossing;
205 }
206
207
208
209
210 public final void setOtsNode(final OTSNode n)
211 {
212 if (this.otsNode != null)
213 {
214 throw new Error("OTS Node already set, can only be set once.");
215 }
216 this.otsNode = n;
217 }
218
219
220
221
222 public final OTSNode getOtsNode()
223 {
224 return this.otsNode;
225 }
226
227
228
229
230 public final boolean hasNoTags()
231 {
232 return this.tags.isEmpty();
233 }
234 }