SUMO - Simulation of Urban MObility
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.dlr.de/
13 // Copyright (C) 2001-2015 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(long long int _id, double _lon, double _lat) :
84  id(_id), lon(_lon), lat(_lat), ele(0), tlsControlled(false), node(0) {}
85 
87  const long long int id;
89  const SUMOReal lon;
91  const SUMOReal lat;
98 
99  private:
101  NIOSMNode& operator=(const NIOSMNode& s);
102 
103  };
104 
108  enum WayType {
109  WAY_NONE = 0,
114  };
115 
116 
119  struct Edge {
120 
121  Edge(long long int _id) :
122  id(_id), myNoLanes(-1), myNoLanesForward(0), myMaxSpeed(MAXSPEED_UNGIVEN),
123  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
124  myBuswayType(WAY_NONE), // buslanes are always built when declared
125  myCurrentIsRoad(false) {}
126 
128  const long long int id;
130  std::string streetName;
136  double myMaxSpeed;
138  std::string myHighWayType;
140  std::string myIsOneWay;
146  std::vector<long long int> myCurrentNodes;
149 
150  private:
152  Edge& operator=(const Edge& s);
153 
154  };
155 
156 
158 
160 
161  void load(const OptionsCont& oc, NBNetBuilder& nb);
162 
163 private:
167  class CompareNodes {
168  public:
169  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
170  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
171  }
172  };
173 
174 
176  static const std::string compoundTypeSeparator;
177 
179 
183  std::map<long long int, NIOSMNode*> myOSMNodes;
184 
186  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
187 
188 
190  std::map<long long int, Edge*> myEdges;
191 
193  std::set<std::string> myUnusableTypes;
194 
196  std::map<std::string, std::string> myKnownCompoundTypes;
197 
212  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
213 
214 
227  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
228  const std::vector<long long int>& passed, NBNetBuilder& nb);
229 
230 
231 protected:
233  static const long long int INVALID_ID;
234 
239  friend class NodesHandler;
240  class NodesHandler : public SUMOSAXHandler {
241  public:
247  NodesHandler(std::map<long long int, NIOSMNode*>& toFill,
248  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
249  bool importElevation);
250 
251 
253  ~NodesHandler();
254 
255 
256  protected:
258 
259 
267  void myStartElement(int element, const SUMOSAXAttributes& attrs);
268 
269 
276  void myEndElement(int element);
278 
279 
280  private:
281 
283  std::map<long long int, NIOSMNode*>& myToFill;
284 
286  long long int myLastNodeID;
287 
290 
293 
295  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
296 
298  const bool myImportElevation;
299 
300 
301  private:
303  NodesHandler(const NodesHandler& s);
304 
307 
308  };
309 
310 
311 
316  class EdgesHandler : public SUMOSAXHandler {
317  public:
323  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
324  std::map<long long int, Edge*>& toFill);
325 
326 
328  ~EdgesHandler();
329 
330 
331  protected:
333 
334 
342  void myStartElement(int element, const SUMOSAXAttributes& attrs);
343 
344 
351  void myEndElement(int element);
353 
354 
355  private:
357  const std::map<long long int, NIOSMNode*>& myOSMNodes;
358 
360  std::map<long long int, Edge*>& myEdgeMap;
361 
364 
366  std::vector<int> myParentElements;
367 
369  std::map<std::string, SUMOReal> mySpeedMap;
370 
371  private:
373  EdgesHandler(const EdgesHandler& s);
374 
377 
378  };
379 
386  public:
392  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
393  const std::map<long long int, Edge*>& osmEdges);
394 
395 
397  ~RelationHandler();
398 
399 
400  protected:
402 
403 
411  void myStartElement(int element, const SUMOSAXAttributes& attrs);
412 
413 
420  void myEndElement(int element);
422 
423 
424  private:
426  const std::map<long long int, NIOSMNode*>& myOSMNodes;
427 
429  const std::map<long long int, Edge*>& myOSMEdges;
430 
432  long long int myCurrentRelation;
433 
435  std::vector<int> myParentElements;
436 
439 
441  long long int myFromWay;
442 
444  long long int myToWay;
445 
447  long long int myViaNode;
448  long long int myViaWay;
449 
450 
460  RESTRICTION_UNKNOWN
461  };
463 
465  void resetValues();
466 
468  bool checkEdgeRef(long long int ref) const;
469 
471  bool applyRestriction() const;
472 
474  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
475 
476  private:
479 
482 
483  };
484 
485 };
486 
487 
488 #endif
489 
490 /****************************************************************************/
491 
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const SUMOReal lat
The latitude the node is located at.
An internal definition of a loaded edge.
const bool myImportElevation
whether elevation data should be imported
const std::map< long long int, Edge * > & myOSMEdges
The previously parsed edges.
An internal representation of an OSM-node.
const long long int id
The edge&#39;s id.
std::string streetName
The edge&#39;s street name.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const long long int id
The node&#39;s id.
WayType myBuswayType
Information about the kind of busway along this road.
long long int myFromWay
the origination way for the current restriction
A container for traffic light definitions and built programs.
The representation of a single edge during network building.
Definition: NBEdge.h:70
long long int myCurrentRelation
The currently parsed relation.
NIOSMNode(long long int _id, double _lon, double _lat)
NIOSMNode & operator=(const NIOSMNode &s)
invalidated assignment operator
SAX-handler base for SUMO-files.
std::vector< long long int > myCurrentNodes
The list of nodes this edge is made of.
RestrictionType
whether the only allowed or the only forbidden connection is defined
SUMOReal ele
The elevation of this node.
std::set< NIOSMNode *, CompareNodes > & myUniqueNodes
the set of unique nodes (used for duplicate detection/substitution)
NBNode * node
the NBNode that was instantiated
static const SUMOReal MAXSPEED_UNGIVEN
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
Functor which compares two Edges.
WayType myCyclewayType
Information about the kind of cycleway along this road.
int myNoLanesForward
number of lanes in forward direction or 0 if unknown, negative if backwards lanes are meant ...
void load(const OptionsCont &oc, NBNetBuilder &nb)
A class which extracts OSM-edges from a parsed OSM-file.
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< long long int > &passed, NBNetBuilder &nb)
Builds an NBEdge.
std::vector< int > myParentElements
The element stack.
Encapsulated SAX-Attributes.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
bool operator()(const NIOSMNode *n1, const NIOSMNode *n2) const
long long int myLastNodeID
ID of the currently parsed node, for reporting mainly.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
bool myIsRestriction
whether the currently parsed relation is a restriction
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
bool myIsInValidNodeTag
Hierarchy helper for parsing a node&#39;s tags.
std::map< long long int, Edge * > myEdges
the map from OSM way ids to edge objects
int myNoLanes
number of lanes, or -1 if unknown
bool tlsControlled
Whether this is a tls controlled junction.
std::map< std::string, std::string > myKnownCompoundTypes
The compound types that have already been mapped to other known types.
std::map< long long int, Edge * > & myEdgeMap
A map of built edges.
const SUMOReal lon
The longitude the node is located at.
long long int myToWay
the destination way for the current restriction
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
static const std::string compoundTypeSeparator
The separator within newly created compound type names.
std::map< std::string, SUMOReal > mySpeedMap
A map of non-numeric speed descriptions to their numeric values.
A storage for options typed value containers)
Definition: OptionsCont.h:108
long long int myViaNode
the via node/way for the current restriction
A class which extracts OSM-nodes from a parsed OSM-file.
Represents a single node (junction) during network building.
Definition: NBNode.h:74
NBNode * insertNodeChecking(long long int id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
int myHierarchyLevel
The current hierarchy level.
std::string myHighWayType
The type, stored in "highway" key.
Importer for networks stored in OpenStreetMap format.
static const long long int INVALID_ID
#define SUMOReal
Definition: config.h:214
bool myCurrentIsRoad
Information whether this is a road.
Edge * myCurrentEdge
The currently built edge.
std::set< std::string > myUnusableTypes
The compounds types that do not contain known types.
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
std::map< long long int, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
std::vector< int > myParentElements
The element stack.
Functor which compares two NIOSMNodes according to their coordinates.
std::set< NIOSMNode *, CompareNodes > myUniqueNodes
the set of unique nodes used in NodesHandler, used when freeing memory
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
A storage for available types of edges.
Definition: NBTypeCont.h:62