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-2014 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), ele(0), tlsControlled(false), node(0) {}
85 
87  const SUMOLong id;
89  const SUMOReal lon;
91  const SUMOReal lat;
98  };
99 
100 
103  struct Edge {
104 
105  Edge(SUMOLong _id) :
107  myCurrentIsRoad(false) {}
108 
112  std::string streetName;
118  double myMaxSpeed;
120  std::string myHighWayType;
122  std::string myIsOneWay;
124  std::vector<SUMOLong> myCurrentNodes;
127  };
128 
129 
131 
133 
134  void load(const OptionsCont& oc, NBNetBuilder& nb);
135 
136 private:
140  class CompareNodes {
141  public:
142  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
143  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
144  }
145  };
146 
147 
149  static const std::string compoundTypeSeparator;
150 
152 
156  std::map<SUMOLong, NIOSMNode*> myOSMNodes;
157 
159  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
160 
161 
163  std::map<SUMOLong, Edge*> myEdges;
164 
166  std::set<std::string> myUnusableTypes;
167 
169  std::map<std::string, std::string> myKnownCompoundTypes;
170 
186 
187 
200  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
201  const std::vector<SUMOLong>& passed, NBNetBuilder& nb);
202 
203 
204 protected:
206  static const SUMOLong INVALID_ID;
207 
212  friend class NodesHandler;
213  class NodesHandler : public SUMOSAXHandler {
214  public:
220  NodesHandler(std::map<SUMOLong, NIOSMNode*>& toFill,
221  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
222  bool importElevation);
223 
224 
226  ~NodesHandler();
227 
228 
229  protected:
231 
232 
240  void myStartElement(int element, const SUMOSAXAttributes& attrs);
241 
242 
249  void myEndElement(int element);
251 
252 
253  private:
254 
256  std::map<SUMOLong, NIOSMNode*>& myToFill;
257 
260 
263 
266 
268  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
269 
271  const bool myImportElevation;
272 
273 
274  private:
276  NodesHandler(const NodesHandler& s);
277 
280 
281  };
282 
283 
284 
289  class EdgesHandler : public SUMOSAXHandler {
290  public:
296  EdgesHandler(const std::map<SUMOLong, NIOSMNode*>& osmNodes,
297  std::map<SUMOLong, Edge*>& toFill);
298 
299 
301  ~EdgesHandler();
302 
303 
304  protected:
306 
307 
315  void myStartElement(int element, const SUMOSAXAttributes& attrs);
316 
317 
324  void myEndElement(int element);
326 
327 
328  private:
330  const std::map<SUMOLong, NIOSMNode*>& myOSMNodes;
331 
333  std::map<SUMOLong, Edge*>& myEdgeMap;
334 
337 
339  std::vector<int> myParentElements;
340 
342  std::map<std::string, SUMOReal> mySpeedMap;
343 
344  private:
346  EdgesHandler(const EdgesHandler& s);
347 
350 
351  };
352 
359  public:
365  RelationHandler(const std::map<SUMOLong, NIOSMNode*>& osmNodes,
366  const std::map<SUMOLong, Edge*>& osmEdges);
367 
368 
371 
372 
373  protected:
375 
376 
384  void myStartElement(int element, const SUMOSAXAttributes& attrs);
385 
386 
393  void myEndElement(int element);
395 
396 
397  private:
399  const std::map<SUMOLong, NIOSMNode*>& myOSMNodes;
400 
402  const std::map<SUMOLong, Edge*>& myOSMEdges;
403 
406 
408  std::vector<int> myParentElements;
409 
412 
415 
418 
422 
423 
434  };
436 
438  void resetValues();
439 
441  bool checkEdgeRef(SUMOLong ref) const;
442 
444  bool applyRestriction() const;
445 
447  NBEdge* findEdgeRef(SUMOLong wayRef, const std::vector<NBEdge*>& candidates) const;
448 
449  private:
452 
455 
456  };
457 
458 };
459 
460 
461 #endif
462 
463 /****************************************************************************/
464