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.road.network.lane.OTSRoadNode;
8
9 /**
10 * OpenStreetmap Node.
11 * <p>
12 * Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14 * <p>
15 * $LastChangedDate: 2015-08-23 00:48:01 +0200 (Sun, 23 Aug 2015) $, @version $Revision: 1291 $, by $Author: averbraeck $,
16 * initial version 31 dec. 2014 <br>
17 * @author <a>Moritz Bergmann</a>
18 */
19 public class OSMNode implements Serializable
20 {
21 /** */
22 private static final long serialVersionUID = 20141231L;
23
24 /** The id of this OSMNode. */
25 private final long id;
26
27 /** The longitude of this OSMNode. */
28 private final double longitude;
29
30 /** The latitude of this OSMNode. */
31 private final double latitude;
32
33 /** The tags of this OSMNode. */
34 private List<OSMTag> tags;
35
36 /** Does this OSMNode have a traffic signal? */
37 private boolean trafficSignal = false;
38
39 /** Does this OSMNode have a stop sign? */
40 private boolean stopSign = false;
41
42 /** Does this OSMNode have a yield sign? */
43 private boolean yieldSign = false;
44
45 /** Is this OSMNode a crossing? */
46 private boolean crossing = false;
47
48 /** The number of OSMLinks originating at this OSMNode; i.e. having this node as start. */
49 public int linksOriginating = 0;
50
51 /** The number of OSMLinks ending at this OSMNode; i.e. having this node as end. */
52 public int linksTerminating = 0;
53
54 /** The OTS Node that corresponds to this OSMNode. */
55 private OTSRoadNode otsNode = null;
56
57 /**
58 * @return Id
59 */
60 public final long getId()
61 {
62 return this.id;
63 }
64
65 /**
66 * @return longitude
67 */
68 public final double getLongitude()
69 {
70 return this.longitude;
71 }
72
73 /**
74 * @return latitude
75 */
76 public final double getLatitude()
77 {
78 return this.latitude;
79 }
80
81 /**
82 * Construct a new OSMNode.
83 * @param id long; id of the new OSMNode
84 * @param longitude double; longitude of the new OSMNode
85 * @param latitude double; latitude of the new OSMNode
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 * Retrieve a tag of this OSMNode.
97 * @param key String; the key of the tag to retrieve
98 * @return OSMTag, or null if this OSMNode has no tag with the specified key
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 * Add a tag to this OSMNode.
114 * @param tag OSMTag; the tag to add to this OSMNode
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 /** {@inheritDoc} */
142 @Override
143 public final String toString()
144 {
145 return String.format("Node %d %.6f %.6f", getId(), getLongitude(), getLatitude());
146 }
147
148 /**
149 * @return trafficSignal.
150 */
151 public final boolean isTrafficSignal()
152 {
153 return this.trafficSignal;
154 }
155
156 /**
157 * @param trafficSignal boolean; set trafficSignal.
158 */
159 public final void setTrafficSignal(final boolean trafficSignal)
160 {
161 this.trafficSignal = trafficSignal;
162 }
163
164 /**
165 * @return stopSign.
166 */
167 public final boolean isStopSign()
168 {
169 return this.stopSign;
170 }
171
172 /**
173 * @param stopSign boolean; set stopSign.
174 */
175 public final void setStopSign(final boolean stopSign)
176 {
177 this.stopSign = stopSign;
178 }
179
180 /**
181 * @return yieldSign.
182 */
183 public final boolean isYieldSign()
184 {
185 return this.yieldSign;
186 }
187
188 /**
189 * @param yieldSign boolean; set yieldSign.
190 */
191 public final void setYieldSign(final boolean yieldSign)
192 {
193 this.yieldSign = yieldSign;
194 }
195
196 /**
197 * @return crossing.
198 */
199 public final boolean isCrossing()
200 {
201 return this.crossing;
202 }
203
204 /**
205 * @param crossing boolean; set crossing.
206 */
207 public final void setCrossing(final boolean crossing)
208 {
209 this.crossing = crossing;
210 }
211
212 /**
213 * @param n OTSRoadNode; OTSRoadNode<String>
214 */
215 public final void setOtsNode(final OTSRoadNode 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 * @return OTSNodeOTSNode<String> - The associated OTS Node.
226 */
227 public final OTSRoadNode getOtsNode()
228 {
229 return this.otsNode;
230 }
231
232 /**
233 * @return boolean; true if this OSMNode has no tags; false otherwise
234 */
235 public final boolean hasNoTags()
236 {
237 return this.tags.isEmpty();
238 }
239 }