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-2016 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  myLayer(0), // layer is non-zero only in conflict areas
126  myCurrentIsRoad(false) {}
127 
129  const long long int id;
131  std::string streetName;
137  double myMaxSpeed;
139  std::string myHighWayType;
141  std::string myIsOneWay;
147  int myLayer;
149  std::vector<long long int> myCurrentNodes;
152 
153  private:
155  Edge& operator=(const Edge& s);
156 
157  };
158 
159 
161 
163 
164  void load(const OptionsCont& oc, NBNetBuilder& nb);
165 
166 private:
170  class CompareNodes {
171  public:
172  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
173  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
174  }
175  };
176 
177 
179  static const std::string compoundTypeSeparator;
180 
182 
186  std::map<long long int, NIOSMNode*> myOSMNodes;
187 
189  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
190 
191 
193  std::map<long long int, Edge*> myEdges;
194 
196  std::set<std::string> myUnusableTypes;
197 
199  std::map<std::string, std::string> myKnownCompoundTypes;
200 
215  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
216 
217 
230  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
231  const std::vector<long long int>& passed, NBNetBuilder& nb);
232 
234  void reconstructLayerElevation(SUMOReal layerElevation, NBNetBuilder& nb);
235 
237  std::map<NBNode*, SUMOReal> getNeighboringNodes(NBNode* node, SUMOReal maxDist);
238 
239 protected:
241  static const long long int INVALID_ID;
242 
247  friend class NodesHandler;
248  class NodesHandler : public SUMOSAXHandler {
249  public:
255  NodesHandler(std::map<long long int, NIOSMNode*>& toFill,
256  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
257  bool importElevation);
258 
259 
261  ~NodesHandler();
262 
263 
264  protected:
266 
267 
275  void myStartElement(int element, const SUMOSAXAttributes& attrs);
276 
277 
284  void myEndElement(int element);
286 
287 
288  private:
289 
291  std::map<long long int, NIOSMNode*>& myToFill;
292 
294  long long int myLastNodeID;
295 
298 
301 
303  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
304 
306  const bool myImportElevation;
307 
308 
309  private:
311  NodesHandler(const NodesHandler& s);
312 
315 
316  };
317 
318 
319 
324  class EdgesHandler : public SUMOSAXHandler {
325  public:
331  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
332  std::map<long long int, Edge*>& toFill);
333 
334 
336  ~EdgesHandler();
337 
338 
339  protected:
341 
342 
350  void myStartElement(int element, const SUMOSAXAttributes& attrs);
351 
352 
359  void myEndElement(int element);
361 
362 
363  private:
365  const std::map<long long int, NIOSMNode*>& myOSMNodes;
366 
368  std::map<long long int, Edge*>& myEdgeMap;
369 
372 
374  std::vector<int> myParentElements;
375 
377  std::map<std::string, SUMOReal> mySpeedMap;
378 
379  private:
381  EdgesHandler(const EdgesHandler& s);
382 
385 
386  };
387 
394  public:
400  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
401  const std::map<long long int, Edge*>& osmEdges);
402 
403 
405  ~RelationHandler();
406 
407 
408  protected:
410 
411 
419  void myStartElement(int element, const SUMOSAXAttributes& attrs);
420 
421 
428  void myEndElement(int element);
430 
431 
432  private:
434  const std::map<long long int, NIOSMNode*>& myOSMNodes;
435 
437  const std::map<long long int, Edge*>& myOSMEdges;
438 
440  long long int myCurrentRelation;
441 
443  std::vector<int> myParentElements;
444 
447 
449  long long int myFromWay;
450 
452  long long int myToWay;
453 
455  long long int myViaNode;
456  long long int myViaWay;
457 
458 
468  RESTRICTION_UNKNOWN
469  };
471 
473  void resetValues();
474 
476  bool checkEdgeRef(long long int ref) const;
477 
479  bool applyRestriction() const;
480 
482  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
483 
484  private:
487 
490 
491  };
492 
493 };
494 
495 
496 #endif
497 
498 /****************************************************************************/
499 
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
const SUMOReal lat
The latitude the node is located at.
void reconstructLayerElevation(SUMOReal layerElevation, NBNetBuilder &nb)
reconstruct elevation from layer info
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
std::map< NBNode *, SUMOReal > getNeighboringNodes(NBNode *node, SUMOReal maxDist)
collect neighboring nodes with their road distance
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
int myLayer
Information about the relative z-ordering of ways.
Instance responsible for building networks.
Definition: NBNetBuilder.h:112
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:99
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:213
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:63
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