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-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), railwayCrossing(false), node(0) {}
85 
87  const long long int id;
89  const SUMOReal lon;
91  const SUMOReal lat;
100 
101  private:
103  NIOSMNode& operator=(const NIOSMNode& s);
104 
105  };
106 
110  enum WayType {
111  WAY_NONE = 0,
116  };
117 
118 
121  struct Edge {
122 
123  Edge(long long int _id) :
125  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
126  myBuswayType(WAY_NONE), // buslanes are always built when declared
127  myLayer(0), // layer is non-zero only in conflict areas
128  myCurrentIsRoad(false) {}
129 
131  const long long int id;
133  std::string streetName;
139  double myMaxSpeed;
141  std::string myHighWayType;
143  std::string myIsOneWay;
149  int myLayer;
151  std::vector<long long int> myCurrentNodes;
154 
155  private:
157  Edge& operator=(const Edge& s);
158 
159  };
160 
161 
163 
165 
166  void load(const OptionsCont& oc, NBNetBuilder& nb);
167 
168 private:
172  class CompareNodes {
173  public:
174  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
175  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
176  }
177  };
178 
179 
181  static const std::string compoundTypeSeparator;
182 
184 
188  std::map<long long int, NIOSMNode*> myOSMNodes;
189 
191  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
192 
193 
195  std::map<long long int, Edge*> myEdges;
196 
198  std::set<std::string> myUnusableTypes;
199 
201  std::map<std::string, std::string> myKnownCompoundTypes;
202 
217  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
218 
219 
232  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
233  const std::vector<long long int>& passed, NBNetBuilder& nb);
234 
236  void reconstructLayerElevation(SUMOReal layerElevation, NBNetBuilder& nb);
237 
239  std::map<NBNode*, SUMOReal> getNeighboringNodes(NBNode* node, SUMOReal maxDist);
240 
241 protected:
243  static const long long int INVALID_ID;
244 
249  friend class NodesHandler;
250  class NodesHandler : public SUMOSAXHandler {
251  public:
257  NodesHandler(std::map<long long int, NIOSMNode*>& toFill,
258  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
259  bool importElevation);
260 
261 
263  ~NodesHandler();
264 
265 
266  protected:
268 
269 
277  void myStartElement(int element, const SUMOSAXAttributes& attrs);
278 
279 
286  void myEndElement(int element);
288 
289 
290  private:
291 
293  std::map<long long int, NIOSMNode*>& myToFill;
294 
296  long long int myLastNodeID;
297 
300 
303 
305  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
306 
308  const bool myImportElevation;
309 
310 
311  private:
313  NodesHandler(const NodesHandler& s);
314 
317 
318  };
319 
320 
321 
326  class EdgesHandler : public SUMOSAXHandler {
327  public:
333  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
334  std::map<long long int, Edge*>& toFill);
335 
336 
338  ~EdgesHandler();
339 
340 
341  protected:
343 
344 
352  void myStartElement(int element, const SUMOSAXAttributes& attrs);
353 
354 
361  void myEndElement(int element);
363 
364 
365  private:
367  const std::map<long long int, NIOSMNode*>& myOSMNodes;
368 
370  std::map<long long int, Edge*>& myEdgeMap;
371 
374 
376  std::vector<int> myParentElements;
377 
379  std::map<std::string, SUMOReal> mySpeedMap;
380 
381  private:
383  EdgesHandler(const EdgesHandler& s);
384 
387 
388  };
389 
396  public:
402  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
403  const std::map<long long int, Edge*>& osmEdges);
404 
405 
408 
409 
410  protected:
412 
413 
421  void myStartElement(int element, const SUMOSAXAttributes& attrs);
422 
423 
430  void myEndElement(int element);
432 
433 
434  private:
436  const std::map<long long int, NIOSMNode*>& myOSMNodes;
437 
439  const std::map<long long int, Edge*>& myOSMEdges;
440 
442  long long int myCurrentRelation;
443 
445  std::vector<int> myParentElements;
446 
449 
451  long long int myFromWay;
452 
454  long long int myToWay;
455 
457  long long int myViaNode;
458  long long int myViaWay;
459 
460 
471  };
473 
475  void resetValues();
476 
478  bool checkEdgeRef(long long int ref) const;
479 
481  bool applyRestriction() const;
482 
484  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
485 
486  private:
489 
492 
493  };
494 
495 };
496 
497 
498 #endif
499 
500 /****************************************************************************/
501 
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.
Edge & operator=(const Edge &s)
invalidated assignment operator
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's id.
std::string streetName
The edge's street name.
const std::map< long long int, NIOSMNode * > & myOSMNodes
The previously parsed nodes.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
const long long int id
The node'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.
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;.
long long int myCurrentRelation
The currently parsed relation.
NodesHandler & operator=(const NodesHandler &s)
invalidated assignment operator
NIOSMNode(long long int _id, double _lon, double _lat)
EdgesHandler & operator=(const EdgesHandler &s)
invalidated assignment operator
void myEndElement(int element)
Called when a closing tag occurs.
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.
RelationHandler & operator=(const RelationHandler &s)
invalidated assignment operator
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 ...
RelationHandler(const std::map< long long int, NIOSMNode * > &osmNodes, const std::map< long long int, Edge * > &osmEdges)
Constructor.
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.
void myEndElement(int element)
Called when a closing tag occurs.
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.
NodesHandler(std::map< long long int, NIOSMNode * > &toFill, std::set< NIOSMNode *, CompareNodes > &uniqueNodes, bool importElevation)
Contructor.
std::map< long long int, NIOSMNode * > & myToFill
The nodes container to fill.
bool myIsRestriction
whether the currently parsed relation is a restriction
bool railwayCrossing
Whether this is a railway crossing.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
double myMaxSpeed
maximum speed in km/h, or MAXSPEED_UNGIVEN
bool checkEdgeRef(long long int ref) const
check whether a referenced way has a corresponding edge
bool myIsInValidNodeTag
Hierarchy helper for parsing a node'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.
EdgesHandler(const std::map< long long int, NIOSMNode * > &osmNodes, std::map< long long int, Edge * > &toFill)
Constructor.
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
NBEdge * findEdgeRef(long long int wayRef, const std::vector< NBEdge * > &candidates) const
try to find the way segment among candidates
A class which extracts OSM-nodes from a parsed OSM-file.
Represents a single node (junction) during network building.
Definition: NBNode.h:74
void resetValues()
reset members to their defaults for parsing a new relation
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: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