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-2017 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>
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class NBEdge;
47 class NBEdgeCont;
48 class NBNetBuilder;
49 class NBNode;
50 class NBNodeCont;
52 class NBTypeCont;
53 class OptionsCont;
54 
55 
56 // ===========================================================================
57 // class definitions
58 // ===========================================================================
65 public:
77  static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);
78 
79 
80 protected:
83  struct NIOSMNode {
84  NIOSMNode(long long int _id, double _lon, double _lat) :
85  id(_id), lon(_lon), lat(_lat), ele(0), tlsControlled(false), railwayCrossing(false), node(0) {}
86 
88  const long long int id;
90  const SUMOReal lon;
92  const SUMOReal lat;
101 
102  private:
104  NIOSMNode& operator=(const NIOSMNode& s);
105 
106  };
107 
111  enum WayType {
112  WAY_NONE = 0,
117  };
118 
119 
122  struct Edge : public Parameterised {
123 
124  Edge(long long int _id) :
125  id(_id), myNoLanes(-1), myNoLanesForward(0), myMaxSpeed(MAXSPEED_UNGIVEN),
126  myCyclewayType(WAY_UNKNOWN), // building of extra lane depends on bikelaneWidth of loaded typemap
127  myBuswayType(WAY_NONE), // buslanes are always built when declared
128  myLayer(0), // layer is non-zero only in conflict areas
129  myCurrentIsRoad(false) {}
130 
132  const long long int id;
134  std::string streetName;
140  double myMaxSpeed;
142  std::string myHighWayType;
144  std::string myIsOneWay;
150  int myLayer;
152  std::vector<long long int> myCurrentNodes;
155 
156  private:
158  Edge& operator=(const Edge& s);
159 
160  };
161 
162 
164 
166 
167  void load(const OptionsCont& oc, NBNetBuilder& nb);
168 
169 private:
173  class CompareNodes {
174  public:
175  bool operator()(const NIOSMNode* n1, const NIOSMNode* n2) const {
176  return (n1->lat > n2->lat) || (n1->lat == n2->lat && n1->lon > n2->lon);
177  }
178  };
179 
180 
182  static const std::string compoundTypeSeparator;
183 
185 
189  std::map<long long int, NIOSMNode*> myOSMNodes;
190 
192  std::set<NIOSMNode*, CompareNodes> myUniqueNodes;
193 
194 
196  std::map<long long int, Edge*> myEdges;
197 
199  std::set<std::string> myUnusableTypes;
200 
202  std::map<std::string, std::string> myKnownCompoundTypes;
203 
218  NBNode* insertNodeChecking(long long int id, NBNodeCont& nc, NBTrafficLightLogicCont& tlsc);
219 
220 
233  int insertEdge(Edge* e, int index, NBNode* from, NBNode* to,
234  const std::vector<long long int>& passed, NBNetBuilder& nb);
235 
237  void reconstructLayerElevation(SUMOReal layerElevation, NBNetBuilder& nb);
238 
240  std::map<NBNode*, std::pair<SUMOReal, SUMOReal> > getNeighboringNodes(NBNode* node, SUMOReal maxDist, const std::set<NBNode*>& knownElevation);
241 
242 protected:
244  static const long long int INVALID_ID;
245 
250  friend class NodesHandler;
251  class NodesHandler : public SUMOSAXHandler {
252  public:
258  NodesHandler(std::map<long long int, NIOSMNode*>& toFill,
259  std::set<NIOSMNode*, CompareNodes>& uniqueNodes,
260  bool importElevation);
261 
262 
264  ~NodesHandler();
265 
266 
267  protected:
269 
270 
278  void myStartElement(int element, const SUMOSAXAttributes& attrs);
279 
280 
287  void myEndElement(int element);
289 
290 
291  private:
292 
294  std::map<long long int, NIOSMNode*>& myToFill;
295 
297  long long int myLastNodeID;
298 
301 
304 
306  std::set<NIOSMNode*, CompareNodes>& myUniqueNodes;
307 
309  const bool myImportElevation;
310 
311 
312  private:
314  NodesHandler(const NodesHandler& s);
315 
318 
319  };
320 
321 
322 
327  class EdgesHandler : public SUMOSAXHandler {
328  public:
334  EdgesHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
335  std::map<long long int, Edge*>& toFill);
336 
337 
339  ~EdgesHandler();
340 
341 
342  protected:
344 
345 
353  void myStartElement(int element, const SUMOSAXAttributes& attrs);
354 
355 
362  void myEndElement(int element);
364 
365 
366  private:
368  const std::map<long long int, NIOSMNode*>& myOSMNodes;
369 
371  std::map<long long int, Edge*>& myEdgeMap;
372 
375 
377  std::vector<int> myParentElements;
378 
380  std::map<std::string, SUMOReal> mySpeedMap;
381 
382  private:
384  EdgesHandler(const EdgesHandler& s);
385 
388 
389  };
390 
397  public:
403  RelationHandler(const std::map<long long int, NIOSMNode*>& osmNodes,
404  const std::map<long long int, Edge*>& osmEdges);
405 
406 
408  ~RelationHandler();
409 
410 
411  protected:
413 
414 
422  void myStartElement(int element, const SUMOSAXAttributes& attrs);
423 
424 
431  void myEndElement(int element);
433 
434 
435  private:
437  const std::map<long long int, NIOSMNode*>& myOSMNodes;
438 
440  const std::map<long long int, Edge*>& myOSMEdges;
441 
443  long long int myCurrentRelation;
444 
446  std::vector<int> myParentElements;
447 
450 
452  long long int myFromWay;
453 
455  long long int myToWay;
456 
458  long long int myViaNode;
459  long long int myViaWay;
460 
461 
471  RESTRICTION_UNKNOWN
472  };
474 
476  void resetValues();
477 
479  bool checkEdgeRef(long long int ref) const;
480 
482  bool applyRestriction() const;
483 
485  NBEdge* findEdgeRef(long long int wayRef, const std::vector<NBEdge*>& candidates) const;
486 
487  private:
490 
493 
494  };
495 
496 };
497 
498 
499 #endif
500 
501 /****************************************************************************/
502 
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:71
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
An upper class for objects with additional parameters.
Definition: Parameterised.h:51
bool railwayCrossing
Whether this is a railway crossing.
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:75
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:208
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
std::map< NBNode *, std::pair< SUMOReal, SUMOReal > > getNeighboringNodes(NBNode *node, SUMOReal maxDist, const std::set< NBNode * > &knownElevation)
collect neighboring nodes with their road distance and maximum between-speed. Search does not continu...
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