SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NIImporter_OpenStreetMap.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // Importer for networks stored in OpenStreetMap format
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef NIImporter_OpenStreetMap_h
24 #define NIImporter_OpenStreetMap_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <map>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class NBEdge;
46 class NBEdgeCont;
47 class NBNetBuilder;
48 class NBNode;
49 class NBNodeCont;
51 class NBTypeCont;
52 class OptionsCont;
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
64 public:
76  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
77 
78 
79 protected:
82  struct NIOSMNode {
83  NIOSMNode(SUMOLong _id, double _lon, double _lat) :
84  id(_id), lon(_lon), lat(_lat), tlsControlled(false), node(0) {}
85 
89  double lon;
91  double lat;
96  };
97 
98 
101  struct Edge {
102 
103  Edge(SUMOLong _id) :
105  myCurrentIsRoad(false) {}
106 
110  std::string streetName;
116  double myMaxSpeed;
118  std::string myHighWayType;
120  std::string myIsOneWay;
122  std::vector<SUMOLong> myCurrentNodes;
125  };
126 
127 
129 
131 
132  void load(const OptionsCont& oc, NBNetBuilder& nb);
133 
134 private:
138  class CompareNodes {
139  public:
140  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
141  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
142  }
143  };
144 
145 
147  static const std::string compoundTypeSeparator;
148 
150 
154  std::map<SUMOLong, NIOSMNode*> myOSMNodes;
155 
157  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
158 
159 
161  std::map<SUMOLong, Edge*> myEdges;
162 
164  std::set<std::string> myUnusableTypes;
165 
167  std::map<std::string, std::string> myKnownCompoundTypes;
168 
184 
185 
198  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
199  const std::vector<SUMOLong>& passed, NBNetBuilder& nb);
200 
201 
202 protected:
204  static const SUMOLong INVALID_ID;
205 
210  friend class NodesHandler;
211  class NodesHandler : public SUMOSAXHandler {
212  public:
218  NodesHandler(std::map<SUMOLong, NIOSMNode*>& toFill,
219  std::set<NIOSMNode*, CompareNodes>& uniqueNodes);
220 
221 
223  ~NodesHandler();
224 
225 
226  protected:
228 
229 
237  void myStartElement(int element, const SUMOSAXAttributes& attrs);
238 
239 
246  void myEndElement(int element);
248 
249 
250  private:
251 
253  std::map<SUMOLong, NIOSMNode*>& myToFill;
254 
257 
260 
263 
265  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
266 
267 
268  private:
270  NodesHandler(const NodesHandler& s);
271 
274 
275  };
276 
277 
278 
283  class EdgesHandler : public SUMOSAXHandler {
284  public:
290  EdgesHandler(const std::map<SUMOLong, NIOSMNode*>& osmNodes,
291  std::map<SUMOLong, Edge*>& toFill);
292 
293 
295  ~EdgesHandler();
296 
297 
298  protected:
300 
301 
309  void myStartElement(int element, const SUMOSAXAttributes& attrs);
310 
311 
318  void myEndElement(int element);
320 
321 
322  private:
324  const std::map<SUMOLong, NIOSMNode*>& myOSMNodes;
325 
327  std::map<SUMOLong, Edge*>& myEdgeMap;
328 
331 
333  std::vector<int> myParentElements;
334 
336  std::map<std::string, SUMOReal> mySpeedMap;
337 
338  private:
340  EdgesHandler(const EdgesHandler& s);
341 
344 
345  };
346 
353  public:
359  RelationHandler(const std::map<SUMOLong, NIOSMNode*>& osmNodes,
360  const std::map<SUMOLong, Edge*>& osmEdges);
361 
362 
365 
366 
367  protected:
369 
370 
378  void myStartElement(int element, const SUMOSAXAttributes& attrs);
379 
380 
387  void myEndElement(int element);
389 
390 
391  private:
393  const std::map<SUMOLong, NIOSMNode*>& myOSMNodes;
394 
396  const std::map<SUMOLong, Edge*>& myOSMEdges;
397 
400 
402  std::vector<int> myParentElements;
403 
406 
409 
412 
416 
417 
428  };
430 
432  void resetValues();
433 
435  bool checkEdgeRef(SUMOLong ref) const;
436 
438  bool applyRestriction() const;
439 
441  NBEdge* findEdgeRef(SUMOLong wayRef, const std::vector<NBEdge*>& candidates) const;
442 
443  private:
446 
449 
450  };
451 
452 };
453 
454 
455 #endif
456 
457 /****************************************************************************/
458