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.sourceforge.net/
13 // Copyright (C) 2001-2012 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 {
86  double lon;
88  double lat;
91  };
92 
93 
96  struct Edge {
98  std::string id;
100  std::string streetName;
104  double myMaxSpeed;
106  std::string myHighWayType;
108  std::string myIsOneWay;
110  std::vector<SUMOLong> myCurrentNodes;
113  };
114 
115 
117 
119 
120  void load(const OptionsCont& oc, NBNetBuilder& nb);
121 
122 private:
126  class CompareNodes {
127  public:
128  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
129  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
130  }
131  };
132 
133 
135  static const std::string compoundTypeSeparator;
136 
138 
142  std::map<SUMOLong, NIOSMNode*> myOSMNodes;
143 
145  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
146 
147 
148  std::map<std::string, Edge*> myEdges;
149 
165 
166 
179  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
180  const std::vector<SUMOLong>& passed, NBNetBuilder& nb);
181 
182 
183 protected:
185 
190  friend class NodesHandler;
191  class NodesHandler : public SUMOSAXHandler {
192  public:
198  NodesHandler(std::map<SUMOLong, NIOSMNode*>& toFill,
199  std::set<NIOSMNode*, CompareNodes>& uniqueNodes);
200 
201 
203  ~NodesHandler();
204 
205 
206  protected:
208 
209 
217  void myStartElement(int element, const SUMOSAXAttributes& attrs);
218 
219 
226  void myEndElement(int element);
228 
229 
230  private:
231 
233  std::map<SUMOLong, NIOSMNode*>& myToFill;
234 
237 
240 
243 
245  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
246 
247 
248  private:
250  NodesHandler(const NodesHandler& s);
251 
254 
255  };
256 
257 
258 
263  class EdgesHandler : public SUMOSAXHandler {
264  public:
270  EdgesHandler(const std::map<SUMOLong, NIOSMNode*>& osmNodes,
271  std::map<std::string, Edge*>& toFill);
272 
273 
275  ~EdgesHandler();
276 
277 
278  protected:
280 
281 
289  void myStartElement(int element, const SUMOSAXAttributes& attrs);
290 
291 
298  void myEndElement(int element);
300 
301 
302  private:
304  const std::map<SUMOLong, NIOSMNode*>& myOSMNodes;
305 
307  std::map<std::string, Edge*>& myEdgeMap;
308 
311 
313  std::vector<int> myParentElements;
314 
316  std::map<std::string, SUMOReal> mySpeedMap;
317 
318 
319  private:
321  EdgesHandler(const EdgesHandler& s);
322 
325 
326  };
327 
328 
329 };
330 
331 
332 #endif
333 
334 /****************************************************************************/
335