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