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