SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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.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(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  private:
101  NIOSMNode& operator=(const NIOSMNode& s);
102 
103  };
104 
105 
108  struct Edge {
109 
110  Edge(SUMOLong _id) :
112  myCurrentIsRoad(false) {}
113 
115  const SUMOLong id;
117  std::string streetName;
123  double myMaxSpeed;
125  std::string myHighWayType;
127  std::string myIsOneWay;
129  std::vector<SUMOLong> myCurrentNodes;
132 
133  private:
135  Edge& operator=(const Edge& s);
136 
137  };
138 
139 
141 
143 
144  void load(const OptionsCont& oc, NBNetBuilder& nb);
145 
146 private:
150  class CompareNodes {
151  public:
152  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
153  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
154  }
155  };
156 
157 
159  static const std::string compoundTypeSeparator;
160 
162 
166  std::map<SUMOLong, NIOSMNode*> myOSMNodes;
167 
169  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
170 
171 
173  std::map<SUMOLong, Edge*> myEdges;
174 
176  std::set<std::string> myUnusableTypes;
177 
179  std::map<std::string, std::string> myKnownCompoundTypes;
180 
196 
197 
210  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
211  const std::vector<SUMOLong>& passed, NBNetBuilder& nb);
212 
213 
214 protected:
216  static const SUMOLong INVALID_ID;
217 
222  friend class NodesHandler;
223  class NodesHandler : public SUMOSAXHandler {
224  public:
230  NodesHandler(std::map<SUMOLong, NIOSMNode*>& toFill,
231  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
232  bool importElevation);
233 
234 
236  ~NodesHandler();
237 
238 
239  protected:
241 
242 
250  void myStartElement(int element, const SUMOSAXAttributes& attrs);
251 
252 
259  void myEndElement(int element);
261 
262 
263  private:
264 
266  std::map<SUMOLong, NIOSMNode*>& myToFill;
267 
270 
273 
276 
278  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
279 
281  const bool myImportElevation;
282 
283 
284  private:
286  NodesHandler(const NodesHandler& s);
287 
290 
291  };
292 
293 
294 
299  class EdgesHandler : public SUMOSAXHandler {
300  public:
306  EdgesHandler(const std::map<SUMOLong, NIOSMNode*>& osmNodes,
307  std::map<SUMOLong, Edge*>& toFill);
308 
309 
311  ~EdgesHandler();
312 
313 
314  protected:
316 
317 
325  void myStartElement(int element, const SUMOSAXAttributes& attrs);
326 
327 
334  void myEndElement(int element);
336 
337 
338  private:
340  const std::map<SUMOLong, NIOSMNode*>& myOSMNodes;
341 
343  std::map<SUMOLong, Edge*>& myEdgeMap;
344 
347 
349  std::vector<int> myParentElements;
350 
352  std::map<std::string, SUMOReal> mySpeedMap;
353 
354  private:
356  EdgesHandler(const EdgesHandler& s);
357 
360 
361  };
362 
369  public:
375  RelationHandler(const std::map<SUMOLong, NIOSMNode*>& osmNodes,
376  const std::map<SUMOLong, Edge*>& osmEdges);
377 
378 
381 
382 
383  protected:
385 
386 
394  void myStartElement(int element, const SUMOSAXAttributes& attrs);
395 
396 
403  void myEndElement(int element);
405 
406 
407  private:
409  const std::map<SUMOLong, NIOSMNode*>& myOSMNodes;
410 
412  const std::map<SUMOLong, Edge*>& myOSMEdges;
413 
416 
418  std::vector<int> myParentElements;
419 
422 
425 
428 
432 
433 
444  };
446 
448  void resetValues();
449 
451  bool checkEdgeRef(SUMOLong ref) const;
452 
454  bool applyRestriction() const;
455 
457  NBEdge* findEdgeRef(SUMOLong wayRef, const std::vector<NBEdge*>& candidates) const;
458 
459  private:
462 
465 
466  };
467 
468 };
469 
470 
471 #endif
472 
473 /****************************************************************************/
474 
NodesHandler(std::map< SUMOLong, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, bool importElevation)
Contructor.
const SUMOReal lat
The latitude the node is located at.
An internal definition of a loaded edge.
Edge & operator=(const Edge &s)
invalidated assignment operator
const bool myImportElevation
whether elevation data should be imported
const std::map< SUMOLong, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
An internal representation of an OSM-node.
std::string streetName
The edge's street name.
std::map< SUMOLong, Edge * > myEdges
the map from OSM way ids to edge objects
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
std::map< SUMOLong, Edge * > & myEdgeMap
A map of built edges.
A container for traffic light definitions and built programs.
bool applyRestriction() const
try to apply the parsed restriction and return whether successful
void myEndElement(int element)
Called when a closing tag occurs.
The representation of a single edge during network building.
Definition: NBEdge.h:71
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
const SUMOLong id
The edge's id.
NodesHandler & operator=(const NodesHandler &s)
invalidated assignment operator
SUMOLong myCurrentRelation
The currently parsed relation.
EdgesHandler & operator=(const EdgesHandler &s)
invalidated assignment operator
void myEndElement(int element)
Called when a closing tag occurs.
NBNode * insertNodeChecking(SUMOLong id, NBNodeCont &nc, NBTrafficLightLogicCont &tlsc)
Builds an NBNode.
NIOSMNode & operator=(const NIOSMNode &s)
invalidated assignment operator
SAX-handler base for SUMO-files.
SUMOLong myViaNode
the via node/way for the current restriction
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
NIOSMNode(SUMOLong _id, double _lon, double _lat)
const std::map< SUMOLong, Edge * > & myOSMEdges
The previously parsed edges.
static const SUMOReal MAXSPEED_UNGIVEN
std::vector< SUMOLong > myCurrentNodes
The list of nodes this edge is made of.
SUMOLong myToWay
the destination way for the current restriction
static void loadNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Loads content of the optionally given OSM file.
Functor which compares two Edges.
RelationHandler & operator=(const RelationHandler &s)
invalidated assignment operator
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.
std::vector< int > myParentElements
The element stack.
Encapsulated SAX-Attributes.
SUMOLong myFromWay
the origination way for the current restriction
void myEndElement(int element)
Called when a closing tag occurs.
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
#define SUMOLong
Definition: config.h:215
bool operator()(const NIOSMNode *n1, const NIOSMNode *n2) const
bool myIsRestriction
whether the currently parsed relation is a restriction
std::map< SUMOLong, NIOSMNode * > & myToFill
The nodes container to fill.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
NBEdge * findEdgeRef(SUMOLong wayRef, const std::vector< NBEdge * > &candidates) const
try to find the way segment among candidates
bool myIsInValidNodeTag
Hierarchy helper for parsing a node's tags.
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.
const SUMOReal lon
The longitude the node is located at.
EdgesHandler(const std::map< SUMOLong, NIOSMNode * > &osmNodes, std::map< SUMOLong, Edge * > &toFill)
Constructor.
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.
RelationHandler(const std::map< SUMOLong, NIOSMNode * > &osmNodes, const std::map< SUMOLong, Edge * > &osmEdges)
Constructor.
A storage for options typed value containers)
Definition: OptionsCont.h:108
const std::map< SUMOLong, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
A class which extracts OSM-nodes from a parsed OSM-file.
Represents a single node (junction) during network building.
Definition: NBNode.h:75
void resetValues()
reset members to their defaults for parsing a new relation
bool checkEdgeRef(SUMOLong ref) const
check whether a referenced way has a corresponding edge
int myHierarchyLevel
The current hierarchy level.
std::string myHighWayType
The type, stored in "highway" key.
Importer for networks stored in OpenStreetMap format.
#define SUMOReal
Definition: config.h:218
int insertEdge(Edge *e, int index, NBNode *from, NBNode *to, const std::vector< SUMOLong > &passed, NBNetBuilder &nb)
Builds an NBEdge.
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::vector< int > myParentElements
The element stack.
std::map< SUMOLong, NIOSMNode * > myOSMNodes
the map from OSM node ids to actual nodes
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
static const SUMOLong INVALID_ID
A class which extracts relevant relation information from a parsed OSM-file.
std::string myIsOneWay
Information whether this is an one-way road.
SUMOLong myLastNodeID
ID of the currently parsed node, for reporting mainly.
A storage for available types of edges.
Definition: NBTypeCont.h:56