View Javadoc
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   * OpenStreetmap Node.
11   * <p>
12   * Copyright (c) 2013-2018 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 OTSNode 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     public final String toString()
143     {
144         return String.format("Node %d %.6f %.6f", getId(), getLongitude(), getLatitude());
145     }
146 
147     /**
148      * @return trafficSignal.
149      */
150     public final boolean isTrafficSignal()
151     {
152         return this.trafficSignal;
153     }
154 
155     /**
156      * @param trafficSignal set trafficSignal.
157      */
158     public final void setTrafficSignal(final boolean trafficSignal)
159     {
160         this.trafficSignal = trafficSignal;
161     }
162 
163     /**
164      * @return stopSign.
165      */
166     public final boolean isStopSign()
167     {
168         return this.stopSign;
169     }
170 
171     /**
172      * @param stopSign set stopSign.
173      */
174     public final void setStopSign(final boolean stopSign)
175     {
176         this.stopSign = stopSign;
177     }
178 
179     /**
180      * @return yieldSign.
181      */
182     public final boolean isYieldSign()
183     {
184         return this.yieldSign;
185     }
186 
187     /**
188      * @param yieldSign set yieldSign.
189      */
190     public final void setYieldSign(final boolean yieldSign)
191     {
192         this.yieldSign = yieldSign;
193     }
194 
195     /**
196      * @return crossing.
197      */
198     public final boolean isCrossing()
199     {
200         return this.crossing;
201     }
202 
203     /**
204      * @param crossing set crossing.
205      */
206     public final void setCrossing(final boolean crossing)
207     {
208         this.crossing = crossing;
209     }
210 
211     /**
212      * @param n OTSNode&lt;String&gt;
213      */
214     public final void setOtsNode(final OTSNode n)
215     {
216         if (this.otsNode != null)
217         {
218             throw new Error("OTS Node already set, can only be set once.");
219         }
220         this.otsNode = n;
221     }
222 
223     /**
224      * @return OTSNodeOTSNode&lt;String&gt; - The associated OTS Node.
225      */
226     public final OTSNode getOtsNode()
227     {
228         return this.otsNode;
229     }
230 
231     /**
232      * @return boolean; true if this OSMNode has no tags; false otherwise
233      */
234     public final boolean hasNoTags()
235     {
236         return this.tags.isEmpty();
237     }
238 }